2016-09-08 14:22:10 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/influxdata/telegraf"
|
|
|
|
)
|
|
|
|
|
2018-09-28 21:48:20 +00:00
|
|
|
// Makemetric applies new metric plugin and agent measurement and tag
|
|
|
|
// settings.
|
2016-09-08 14:22:10 +00:00
|
|
|
func makemetric(
|
2018-09-28 21:48:20 +00:00
|
|
|
metric telegraf.Metric,
|
2016-09-08 14:22:10 +00:00
|
|
|
nameOverride string,
|
|
|
|
namePrefix string,
|
|
|
|
nameSuffix string,
|
2018-09-28 21:48:20 +00:00
|
|
|
tags map[string]string,
|
|
|
|
globalTags map[string]string,
|
2016-09-08 14:22:10 +00:00
|
|
|
) telegraf.Metric {
|
|
|
|
if len(nameOverride) != 0 {
|
2018-09-28 21:48:20 +00:00
|
|
|
metric.SetName(nameOverride)
|
2016-09-08 14:22:10 +00:00
|
|
|
}
|
2018-09-28 21:48:20 +00:00
|
|
|
|
2016-09-08 14:22:10 +00:00
|
|
|
if len(namePrefix) != 0 {
|
2018-09-28 21:48:20 +00:00
|
|
|
metric.AddPrefix(namePrefix)
|
2016-09-08 14:22:10 +00:00
|
|
|
}
|
|
|
|
if len(nameSuffix) != 0 {
|
2018-09-28 21:48:20 +00:00
|
|
|
metric.AddSuffix(nameSuffix)
|
2016-09-08 14:22:10 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 21:48:20 +00:00
|
|
|
// Apply plugin-wide tags
|
|
|
|
for k, v := range tags {
|
|
|
|
if _, ok := metric.GetTag(k); !ok {
|
|
|
|
metric.AddTag(k, v)
|
2016-09-08 14:22:10 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-28 21:48:20 +00:00
|
|
|
// Apply global tags
|
|
|
|
for k, v := range globalTags {
|
|
|
|
if _, ok := metric.GetTag(k); !ok {
|
|
|
|
metric.AddTag(k, v)
|
2016-09-08 14:22:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 21:48:20 +00:00
|
|
|
return metric
|
2016-09-08 14:22:10 +00:00
|
|
|
}
|