Skip to content

Commit

Permalink
Add use_int_samples option for backwards compatibility (influxdata#5563)
Browse files Browse the repository at this point in the history
  • Loading branch information
prydin authored and Jean-Louis Dupond committed Apr 22, 2019
1 parent 90672aa commit 36a959f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
17 changes: 15 additions & 2 deletions plugins/inputs/vsphere/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"log"
"math"
"math/rand"
"net/url"
"regexp"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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++

Expand Down Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions plugins/inputs/vsphere/vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type VSphere struct {
DatastoreMetricExclude []string
DatastoreInclude []string
Separator string
UseIntSamples bool

MaxQueryObjects int
MaxQueryMetrics int
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -312,6 +319,7 @@ func init() {
DatastoreMetricExclude: nil,
DatastoreInclude: []string{"/*/datastore/**"},
Separator: "_",
UseIntSamples: true,

MaxQueryObjects: 256,
MaxQueryMetrics: 256,
Expand Down

0 comments on commit 36a959f

Please sign in to comment.