Skip to content

Commit

Permalink
[feature] set precision acording to poll interval (influxdata/telegra…
Browse files Browse the repository at this point in the history
  • Loading branch information
Tesifonte Belda committed May 20, 2022
1 parent 5745372 commit af45f9d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Telegraf execd vcstat input

vcstat is a VMware vSphere input plugin for [Telegraf](https://github.com/influxdata/telegraf) that gathers status and basic stats from vCenter using govmomi library (in a similar way to [govc *.info](https://github.com/vmware/govmomi/blob/master/govc/USAGE.md) commands). You may use this input in parallel with Telegraf's vsphere input to complement the performance metrics it collects. With vcstat input's data you may be able to detect when a node goes from green to red, an HBA goes from link-up to link-down or to know the number of ports used by a Distributed Virtual Switch.
vcstat is a VMware vSphere input plugin for [Telegraf](https://github.com/influxdata/telegraf) that gathers status and basic [stats](https://github.com/tesibelda/vcstat/blob/master/METRICS.md) from vCenter using govmomi library (in a similar way to [govc *.info](https://github.com/vmware/govmomi/blob/master/govc/USAGE.md) commands). You may use this input in parallel with Telegraf's vsphere input to complement the performance metrics it collects. With vcstat input's data you may be able to detect when a node goes from green to red, an HBA goes from link-up to link-down or to know the number of ports used by a Distributed Virtual Switch.

# Compatibility

Expand Down Expand Up @@ -65,6 +65,7 @@ You can optionally tell vcstat the input's interval by adding -poll_interval the
command = ["/path/to/vcstat_binary", "-config", "/path/to/vcstat.conf", "-poll_interval", "30s"]
signal = "none"
```
Metric timestamp precision will be set according to the polling interval, so it will usually be 1s.

* Restart or reload Telegraf.

Expand Down
15 changes: 15 additions & 0 deletions plugins/inputs/vcstat/vcstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func (vcs *VCstatConfig) Gather(acc telegraf.Accumulator) error {
}
vcs.SessionsCreated.Incr(1)
}
acc.SetPrecision(getPrecision(vcs.pollInterval))
// poll using a context with timeout
ctx1, cancel1 := context.WithTimeout(vcs.ctx, time.Duration(vcs.Timeout))
defer cancel1()
Expand Down Expand Up @@ -324,3 +325,17 @@ func gatherError(acc telegraf.Accumulator, err error) error {
acc.AddError(err)
return nil
}

// Returns the rounding precision for metrics
func getPrecision(interval time.Duration) time.Duration {
switch {
case interval >= time.Second:
return time.Second
case interval >= time.Millisecond:
return time.Millisecond
case interval >= time.Microsecond:
return time.Microsecond
default:
return time.Nanosecond
}
}

0 comments on commit af45f9d

Please sign in to comment.