Skip to content

Commit

Permalink
Add option export_timestamp for enable/disable timestamp export
Browse files Browse the repository at this point in the history
  • Loading branch information
bozaro committed Jan 16, 2019
1 parent 43f55ea commit 9c0a0bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions plugins/outputs/prometheus_client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ This plugin starts a [Prometheus](https://prometheus.io/) Client, it exposes all
## If set, enable TLS with the given certificate.
# tls_cert = "/etc/ssl/telegraf.crt"
# tls_key = "/etc/ssl/telegraf.key"

## Export metric collection time.
# export_timestamp = true
```
10 changes: 9 additions & 1 deletion plugins/outputs/prometheus_client/prometheus_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type PrometheusClient struct {
Path string `toml:"path"`
CollectorsExclude []string `toml:"collectors_exclude"`
StringAsLabel bool `toml:"string_as_label"`
ExportTimestamp bool `toml:"export_timestamp"`

server *http.Server

Expand Down Expand Up @@ -104,6 +105,9 @@ var sampleConfig = `
## If set, enable TLS with the given certificate.
# tls_cert = "/etc/ssl/telegraf.crt"
# tls_key = "/etc/ssl/telegraf.key"
## Export metric collection time.
# export_timestamp = true
`

func (p *PrometheusClient) auth(h http.Handler) http.Handler {
Expand Down Expand Up @@ -283,7 +287,10 @@ func (p *PrometheusClient) Collect(ch chan<- prometheus.Metric) {
name, labels, err.Error())
}

ch <- prometheus.NewMetricWithTimestamp(sample.Timestamp, metric)
if p.ExportTimestamp {
metric = prometheus.NewMetricWithTimestamp(sample.Timestamp, metric)
}
ch <- metric
}
}
}
Expand Down Expand Up @@ -504,6 +511,7 @@ func init() {
return &PrometheusClient{
ExpirationInterval: internal.Duration{Duration: time.Second * 60},
StringAsLabel: true,
ExportTimestamp: true,
fam: make(map[string]*MetricFamily),
now: time.Now,
}
Expand Down

0 comments on commit 9c0a0bf

Please sign in to comment.