Skip to content

Commit

Permalink
apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aarnaud committed Dec 2, 2020
1 parent c3f4062 commit 2be0757
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
38 changes: 38 additions & 0 deletions plugins/serializers/prometheusremotewrite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Prometheus

The `prometheusremotewrite` data format converts metrics into the Prometheus protobuf
exposition format.

**Warning**: When generating histogram and summary types, output may
not be correct if the metric spans multiple batches. This issue can be
somewhat, but not fully, mitigated by using outputs that support writing in
"batch format". When using histogram and summary types, it is recommended to
use only the `prometheus_client` output.

### Configuration

```toml
[[outputs.http]]
url = "https://cortex/api/prom/push"
data_format = "prometheusremotewrite"
tls_ca = "/etc/telegraf/ca.pem"
tls_cert = "/etc/telegraf/cert.pem"
tls_key = "/etc/telegraf/key.pem"
[outputs.http.headers]
Content-Type = "application/x-protobuf"
Content-Encoding = "snappy"
X-Prometheus-Remote-Write-Version = "0.1.0"
```

### Metrics

A Prometheus metric is created for each integer, float, boolean or unsigned
field. Boolean values are converted to *1.0* for true and *0.0* for false.

The Prometheus metric names are produced by joining the measurement name with
the field key. In the special case where the measurement name is `prometheus`
it is not included in the final metric name.

Prometheus labels are produced for each tag.

**Note:** String fields are ignored and do not produce Prometheus metrics.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prometheus_remote_write
package prometheusremotewrite

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prometheus_remote_write
package prometheusremotewrite

import (
"bytes"
Expand Down
14 changes: 7 additions & 7 deletions plugins/serializers/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package serializers

import (
"fmt"
"github.com/influxdata/telegraf/plugins/serializers/prometheus_remote_write"
"github.com/influxdata/telegraf/plugins/serializers/prometheusremotewrite"
"time"

"github.com/influxdata/telegraf"
Expand Down Expand Up @@ -127,7 +127,7 @@ func NewSerializer(config *Config) (Serializer, error) {
serializer, err = NewWavefrontSerializer(config.Prefix, config.WavefrontUseStrict, config.WavefrontSourceOverride)
case "prometheus":
serializer, err = NewPrometheusSerializer(config)
case "prometheus_remote_write":
case "prometheusremotewrite":
serializer, err = NewPrometheusRemoteWriteSerializer(config)
default:
err = fmt.Errorf("Invalid data format: %s", config.DataFormat)
Expand All @@ -136,17 +136,17 @@ func NewSerializer(config *Config) (Serializer, error) {
}

func NewPrometheusRemoteWriteSerializer(config *Config) (Serializer, error) {
sortMetrics := prometheus_remote_write.NoSortMetrics
sortMetrics := prometheusremotewrite.NoSortMetrics
if config.PrometheusExportTimestamp {
sortMetrics = prometheus_remote_write.SortMetrics
sortMetrics = prometheusremotewrite.SortMetrics
}

stringAsLabels := prometheus_remote_write.DiscardStrings
stringAsLabels := prometheusremotewrite.DiscardStrings
if config.PrometheusStringAsLabel {
stringAsLabels = prometheus_remote_write.StringAsLabel
stringAsLabels = prometheusremotewrite.StringAsLabel
}

return prometheus_remote_write.NewSerializer(prometheus_remote_write.FormatConfig{
return prometheusremotewrite.NewSerializer(prometheusremotewrite.FormatConfig{
MetricSortOrder: sortMetrics,
StringHandling: stringAsLabels,
})
Expand Down

0 comments on commit 2be0757

Please sign in to comment.