diff --git a/plugins/outputs/stackdriver/README.md b/plugins/outputs/stackdriver/README.md index ead8a0a6e..ce3eb626e 100644 --- a/plugins/outputs/stackdriver/README.md +++ b/plugins/outputs/stackdriver/README.md @@ -17,3 +17,8 @@ Metrics are grouped by the `namespace` variable and metric key - eg: `custom.goo # The namespace for the metric descriptor namespace = "telegraf" ``` + +### Restrictions + +Stackdriver does not support string values in custom metrics, any string +fields will not be written. diff --git a/plugins/outputs/stackdriver/stackdriver.go b/plugins/outputs/stackdriver/stackdriver.go index 0b2403358..a1cafdd98 100644 --- a/plugins/outputs/stackdriver/stackdriver.go +++ b/plugins/outputs/stackdriver/stackdriver.go @@ -6,12 +6,10 @@ import ( "log" "path" + monitoring "cloud.google.com/go/monitoring/apiv3" // Imports the Stackdriver Monitoring client package. + googlepb "github.com/golang/protobuf/ptypes/timestamp" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/outputs" - - // Imports the Stackdriver Monitoring client package. - monitoring "cloud.google.com/go/monitoring/apiv3" - googlepb "github.com/golang/protobuf/ptypes/timestamp" metricpb "google.golang.org/genproto/googleapis/api/metric" monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres" monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3" @@ -86,6 +84,10 @@ func (s *Stackdriver) Write(metrics []telegraf.Metric) error { continue } + if value == nil { + continue + } + metricKind, err := getStackdriverMetricKind(m.Type()) if err != nil { log.Printf("E! [output.stackdriver] get metric failed: %s", err) @@ -222,11 +224,8 @@ func getStackdriverTypedValue(value interface{}) (*monitoringpb.TypedValue, erro }, }, nil case string: - return &monitoringpb.TypedValue{ - Value: &monitoringpb.TypedValue_StringValue{ - StringValue: string(v), - }, - }, nil + // String value types are not available for custom metrics + return nil, nil default: return nil, fmt.Errorf("value type \"%T\" not supported for stackdriver custom metrics", v) }