Skip to content

Commit

Permalink
[feature] CHANGING set response_time_ns as the sum of time spent in e…
Browse files Browse the repository at this point in the history
…sxcli cmds per poll instead of the running mean
  • Loading branch information
tbelda-ems committed Jun 26, 2023
1 parent f4233e2 commit 30cd32c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
13 changes: 13 additions & 0 deletions internal/vccollector/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,15 @@ func (c *VcCollector) GetNumberNotRespondingHosts() int {
return numnotresponding
}

// 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
}
}
}

func (c *hostState) setNotConnected(conn bool) {
c.notConnected = conn
}
Expand All @@ -288,6 +297,10 @@ func (c *hostState) setMeanResponseTime(dur time.Duration) {
}
}

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

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

Expand Down
6 changes: 3 additions & 3 deletions internal/vccollector/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (c *VcCollector) CollectHostHBA(
continue
}
res, err = x.Run([]string{"storage", "core", "adapter", "list"})
hostSt.setMeanResponseTime(time.Since(startTime))
hostSt.sumResponseTime(time.Since(startTime))
if err != nil {
hostExecutorRunAddError(acc, "storage core", host.Name(), err)
hostSt.setNotResponding(true)
Expand Down Expand Up @@ -236,7 +236,7 @@ func (c *VcCollector) CollectHostNIC(
continue
}
res, err = x.Run([]string{"network", "nic", "list"})
hostSt.setMeanResponseTime(time.Since(startTime))
hostSt.sumResponseTime(time.Since(startTime))
if err != nil {
hostExecutorRunAddError(acc, "network nic", host.Name(), err)
hostSt.setNotResponding(true)
Expand Down Expand Up @@ -316,7 +316,7 @@ func (c *VcCollector) CollectHostFw(
continue
}
res, err = x.Run([]string{"network", "firewall", "get"})
hostSt.setMeanResponseTime(time.Since(startTime))
hostSt.sumResponseTime(time.Since(startTime))
if err != nil {
hostExecutorRunAddError(acc, "network firewall", host.Name(), err)
hostSt.setNotResponding(true)
Expand Down
28 changes: 19 additions & 9 deletions plugins/inputs/vcstat/vcstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package vcstat

import (
"context"
"errors"
"fmt"
"net/url"
"time"
Expand Down Expand Up @@ -121,6 +122,8 @@ var sampleConfig = `
# vm_instances = false
`

var ErrorNoCollector = errors.New("collector not yet created")

func init() {
inputs.Add("vcstat", func() telegraf.Input {
return &Config{
Expand Down Expand Up @@ -343,7 +346,9 @@ func (vcs *Config) gatherHighLevelEntities(
err error
)

col = vcs.vcc
if col = vcs.vcc; col == nil {
return ErrorNoCollector
}

//--- Get vCenter basic stats
if err = col.CollectVcenterInfo(ctx, acc); err != nil {
Expand Down Expand Up @@ -378,7 +383,10 @@ func (vcs *Config) gatherHost(
err error
)

col = vcs.vcc
if col = vcs.vcc; col == nil {
return ErrorNoCollector
}

if vcs.HostInstances {
if err = col.CollectHostInfo(ctx, acc); err != nil {
return err
Expand All @@ -387,6 +395,7 @@ func (vcs *Config) gatherHost(

if vcs.HostHBAInstances {
hasEsxcliCollection = true
col.ResetResponseTimes()
if err = col.CollectHostHBA(ctx, acc); err != nil {
return err
}
Expand Down Expand Up @@ -438,7 +447,10 @@ func (vcs *Config) gatherNetwork(
err error
)

col = vcs.vcc
if col = vcs.vcc; col == nil {
return ErrorNoCollector
}

if vcs.NetDVSInstances {
if err = col.CollectNetDVS(ctx, acc); err != nil {
return err
Expand All @@ -462,9 +474,8 @@ func (vcs *Config) gatherStorage(
if vcs.DatastoreInstances {
var col *vccollector.VcCollector
var err error
col = vcs.vcc
if col == nil {
return nil
if col = vcs.vcc; col == nil {
return ErrorNoCollector
}
if err = col.CollectDatastoresInfo(ctx, acc); err != nil {
return tgplus.GatherError(acc, err)
Expand All @@ -482,9 +493,8 @@ func (vcs *Config) gatherVM(
if vcs.VMInstances {
var col *vccollector.VcCollector
var err error
col = vcs.vcc
if col == nil {
return nil
if col = vcs.vcc; col == nil {
return ErrorNoCollector
}
if err = col.CollectVmsInfo(ctx, acc); err != nil {
return tgplus.GatherError(acc, err)
Expand Down

0 comments on commit 30cd32c

Please sign in to comment.