diff --git a/plugins/inputs/vsphere/endpoint.go b/plugins/inputs/vsphere/endpoint.go index 192a4a487..694efb574 100644 --- a/plugins/inputs/vsphere/endpoint.go +++ b/plugins/inputs/vsphere/endpoint.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "log" + "math" "math/rand" "net/url" "regexp" @@ -948,7 +949,7 @@ func (e *Endpoint) collectChunk(ctx context.Context, pqs []types.PerfQuerySpec, e.populateTags(&objectRef, resourceType, res, t, &v) nValues := 0 - alignedInfo, alignedValues := alignSamples(em.SampleInfo, v.Value, interval) // TODO: Estimate interval + alignedInfo, alignedValues := alignSamples(em.SampleInfo, v.Value, interval) for idx, sample := range alignedInfo { // According to the docs, SampleInfo and Value should have the same length, but we've seen corrupted @@ -981,7 +982,11 @@ func (e *Endpoint) collectChunk(ctx context.Context, pqs []types.PerfQuerySpec, if info.UnitInfo.GetElementDescription().Key == "percent" { bucket.fields[fn] = float64(v) / 100.0 } else { - bucket.fields[fn] = v + if e.Parent.UseIntSamples { + bucket.fields[fn] = int64(round(v)) + } else { + bucket.fields[fn] = v + } } count++ @@ -1082,3 +1087,11 @@ func cleanDiskTag(disk string) string { // Remove enclosing "<>" return strings.TrimSuffix(strings.TrimPrefix(disk, "<"), ">") } + +func round(x float64) float64 { + t := math.Trunc(x) + if math.Abs(x-t) >= 0.5 { + return t + math.Copysign(1, x) + } + return t +} diff --git a/plugins/inputs/vsphere/vsphere.go b/plugins/inputs/vsphere/vsphere.go index 809026e3e..852dd5e25 100644 --- a/plugins/inputs/vsphere/vsphere.go +++ b/plugins/inputs/vsphere/vsphere.go @@ -40,6 +40,7 @@ type VSphere struct { DatastoreMetricExclude []string DatastoreInclude []string Separator string + UseIntSamples bool MaxQueryObjects int MaxQueryMetrics int @@ -199,6 +200,12 @@ var sampleConfig = ` ## timeout applies to any of the api request made to vcenter # timeout = "60s" + ## When set to true, all samples are sent as integers. This makes the output data types backwards compatible + ## with Telegraf 1.9 or lower. Normally all samples from vCenter, with the exception of percentages, are + ## integer values, but under some conditions, some averaging takes place internally in the plugin. Setting this + ## flag to "false" will send values as floats to preserve the full precision when averaging takes place. + # use_int_samples = true + ## Optional SSL Config # ssl_ca = "/path/to/cafile" # ssl_cert = "/path/to/certfile" @@ -312,6 +319,7 @@ func init() { DatastoreMetricExclude: nil, DatastoreInclude: []string{"/*/datastore/**"}, Separator: "_", + UseIntSamples: true, MaxQueryObjects: 256, MaxQueryMetrics: 256,