Skip to content

Commit

Permalink
[bufix] reset esxcli response time on every poll in any case
Browse files Browse the repository at this point in the history
  • Loading branch information
tbelda-ems committed Jul 5, 2023
1 parent 075b7c2 commit ec47bfe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
40 changes: 16 additions & 24 deletions internal/vccollector/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,49 +272,41 @@ func (c *VcCollector) GetNumberNotRespondingHosts() int {
// ResetResponseTimes set host states response times to 0
func (c *VcCollector) ResetResponseTimes() {
for i := range c.dcs {
for _, hState := range c.hostStates[i] {
hState.responseTime = 0
for j := range c.hostStates[i] {
c.hostStates[i][j].responseTime = 0
}
}
}

func (c *hostState) setNotConnected(conn bool) {
c.notConnected = conn
func (h *hostState) setNotConnected(conn bool) {
h.notConnected = conn
}

func (c *hostState) setNotResponding(resp bool) {
c.notResponding = resp
func (h *hostState) setNotResponding(resp bool) {
h.notResponding = resp
if resp {
c.lastNoResponse = time.Now()
}
}

func (c *hostState) setMeanResponseTime(dur time.Duration) {
if c.responseTime == 0 {
c.responseTime = dur
} else {
c.responseTime = (c.responseTime + dur) / 2
h.lastNoResponse = time.Now()
}
}

func (c *hostState) sumResponseTime(dur time.Duration) {
c.responseTime += dur
func (h *hostState) sumResponseTime(dur time.Duration) {
h.responseTime += dur
}

func (c *hostState) isHostConnectedAndResponding(skipDuration time.Duration) bool {
func (h *hostState) isHostConnectedAndResponding(skipDuration time.Duration) bool {
var connectedResponding bool

if !c.notConnected {
if !h.notConnected {
// limit notResponding in cache for skipDuration
if !c.lastNoResponse.IsZero() && time.Since(c.lastNoResponse) > skipDuration {
c.setNotResponding(false)
if !h.lastNoResponse.IsZero() && time.Since(h.lastNoResponse) > skipDuration {
h.setNotResponding(false)
}
connectedResponding = !c.notResponding
connectedResponding = !h.notResponding
}

return connectedResponding
}

func (c *hostState) isHostConnected() bool {
return !c.notConnected
func (h *hostState) isHostConnected() bool {
return !h.notConnected
}
2 changes: 1 addition & 1 deletion internal/vccollector/graphics.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *VcCollector) CollectHostGraphics(
continue
}
res, err = x.Run([]string{"graphics", "device", "stats", "list"})
hostSt.setMeanResponseTime(time.Since(startTime))
hostSt.sumResponseTime(time.Since(startTime))
if err != nil {
hostExecutorRunAddError(acc, "graphics device", host.Name(), err)
hostSt.setNotResponding(true)
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/vcstat/vcstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ func (vcs *Config) gatherHost(
return err
}
}
col.ResetResponseTimes()

if vcs.HostHBAInstances {
hasEsxcliCollection = true
col.ResetResponseTimes()
if err = col.CollectHostHBA(ctx, acc); err != nil {
return err
}
Expand Down

0 comments on commit ec47bfe

Please sign in to comment.