Add use_int_samples option for backwards compatibility (#5563)

This commit is contained in:
Pontus Rydin 2019-03-11 14:16:32 -04:00 committed by Daniel Nelson
parent 1752619e35
commit 19988a94de
2 changed files with 23 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"log" "log"
"math"
"math/rand" "math/rand"
"net/url" "net/url"
"regexp" "regexp"
@ -948,7 +949,7 @@ func (e *Endpoint) collectChunk(ctx context.Context, pqs []types.PerfQuerySpec,
e.populateTags(&objectRef, resourceType, res, t, &v) e.populateTags(&objectRef, resourceType, res, t, &v)
nValues := 0 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 { for idx, sample := range alignedInfo {
// According to the docs, SampleInfo and Value should have the same length, but we've seen corrupted // 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" { if info.UnitInfo.GetElementDescription().Key == "percent" {
bucket.fields[fn] = float64(v) / 100.0 bucket.fields[fn] = float64(v) / 100.0
} else { } else {
bucket.fields[fn] = v if e.Parent.UseIntSamples {
bucket.fields[fn] = int64(round(v))
} else {
bucket.fields[fn] = v
}
} }
count++ count++
@ -1082,3 +1087,11 @@ func cleanDiskTag(disk string) string {
// Remove enclosing "<>" // Remove enclosing "<>"
return strings.TrimSuffix(strings.TrimPrefix(disk, "<"), ">") 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
}

View File

@ -40,6 +40,7 @@ type VSphere struct {
DatastoreMetricExclude []string DatastoreMetricExclude []string
DatastoreInclude []string DatastoreInclude []string
Separator string Separator string
UseIntSamples bool
MaxQueryObjects int MaxQueryObjects int
MaxQueryMetrics int MaxQueryMetrics int
@ -199,6 +200,12 @@ var sampleConfig = `
## timeout applies to any of the api request made to vcenter ## timeout applies to any of the api request made to vcenter
# timeout = "60s" # 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 ## Optional SSL Config
# ssl_ca = "/path/to/cafile" # ssl_ca = "/path/to/cafile"
# ssl_cert = "/path/to/certfile" # ssl_cert = "/path/to/certfile"
@ -312,6 +319,7 @@ func init() {
DatastoreMetricExclude: nil, DatastoreMetricExclude: nil,
DatastoreInclude: []string{"/*/datastore/**"}, DatastoreInclude: []string{"/*/datastore/**"},
Separator: "_", Separator: "_",
UseIntSamples: true,
MaxQueryObjects: 256, MaxQueryObjects: 256,
MaxQueryMetrics: 256, MaxQueryMetrics: 256,