forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
37 lines (31 loc) · 761 Bytes
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package prometheus
import (
"github.com/influxdata/telegraf"
dto "github.com/prometheus/client_model/go"
)
func mapValueType(mt dto.MetricType) telegraf.ValueType {
switch mt {
case dto.MetricType_COUNTER:
return telegraf.Counter
case dto.MetricType_GAUGE:
return telegraf.Gauge
case dto.MetricType_SUMMARY:
return telegraf.Summary
case dto.MetricType_HISTOGRAM:
return telegraf.Histogram
default:
return telegraf.Untyped
}
}
func getTagsFromLabels(m *dto.Metric, defaultTags map[string]string) map[string]string {
result := map[string]string{}
for key, value := range defaultTags {
result[key] = value
}
for _, label := range m.Label {
if v := label.GetValue(); v != "" {
result[label.GetName()] = v
}
}
return result
}