parent
6afe9ceef1
commit
b4a6d9c647
|
@ -5,7 +5,6 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
|
@ -14,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
sanitizedChars = strings.NewReplacer("/", "_", "@", "_", " ", "_", "-", "_", ".", "_")
|
invalidNameCharRE = regexp.MustCompile(`[^a-zA-Z0-9_]`)
|
||||||
|
|
||||||
// Prometheus metric names must match this regex
|
// Prometheus metric names must match this regex
|
||||||
// see https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels
|
// see https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels
|
||||||
|
@ -111,12 +110,12 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error {
|
||||||
|
|
||||||
for _, point := range metrics {
|
for _, point := range metrics {
|
||||||
key := point.Name()
|
key := point.Name()
|
||||||
key = sanitizedChars.Replace(key)
|
key = invalidNameCharRE.ReplaceAllString(key, "_")
|
||||||
|
|
||||||
var labels []string
|
var labels []string
|
||||||
l := prometheus.Labels{}
|
l := prometheus.Labels{}
|
||||||
for k, v := range point.Tags() {
|
for k, v := range point.Tags() {
|
||||||
k = sanitizedChars.Replace(k)
|
k = invalidNameCharRE.ReplaceAllString(k, "_")
|
||||||
if len(k) == 0 {
|
if len(k) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -137,7 +136,7 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// sanitize the measurement name
|
// sanitize the measurement name
|
||||||
n = sanitizedChars.Replace(n)
|
n = invalidNameCharRE.ReplaceAllString(n, "_")
|
||||||
var mname string
|
var mname string
|
||||||
if n == "value" {
|
if n == "value" {
|
||||||
mname = key
|
mname = key
|
||||||
|
|
Loading…
Reference in New Issue