Don't log every string metric that prometheus doesnt support

This commit is contained in:
Cameron Sparr 2016-03-23 08:57:05 -06:00
parent a95710ed0c
commit 474d6db42f
1 changed files with 14 additions and 4 deletions

View File

@ -96,6 +96,15 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error {
} }
for n, val := range point.Fields() { for n, val := range point.Fields() {
// Ignore string and bool fields.
switch val.(type) {
case string:
continue
case bool:
continue
}
// sanitize the measurement name
n = sanitizedChars.Replace(n) n = sanitizedChars.Replace(n)
var mname string var mname string
if n == "value" { if n == "value" {
@ -104,15 +113,17 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error {
mname = fmt.Sprintf("%s_%s", key, n) mname = fmt.Sprintf("%s_%s", key, n)
} }
// verify that it is a valid measurement name
if !metricName.MatchString(mname) { if !metricName.MatchString(mname) {
continue continue
} }
// Create a new metric if it hasn't been created yet.
if _, ok := p.metrics[mname]; !ok { if _, ok := p.metrics[mname]; !ok {
p.metrics[mname] = prometheus.NewUntypedVec( p.metrics[mname] = prometheus.NewUntypedVec(
prometheus.UntypedOpts{ prometheus.UntypedOpts{
Name: mname, Name: mname,
Help: fmt.Sprintf("Telegraf collected point '%s'", mname), Help: "Telegraf collected metric",
}, },
labels, labels,
) )
@ -123,9 +134,6 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error {
} }
switch val := val.(type) { switch val := val.(type) {
default:
log.Printf("Prometheus output, unsupported type. key: %s, type: %T\n",
mname, val)
case int64: case int64:
m, err := p.metrics[mname].GetMetricWith(l) m, err := p.metrics[mname].GetMetricWith(l)
if err != nil { if err != nil {
@ -144,6 +152,8 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error {
continue continue
} }
m.Set(val) m.Set(val)
default:
continue
} }
} }
} }