Omit keys when creating measurement names for GNMI telemetry (#5986)

This commit is contained in:
Steven Barth 2019-06-14 20:29:06 +02:00 committed by Daniel Nelson
parent 4b6e791908
commit 4cfd70b6c0
1 changed files with 21 additions and 11 deletions

View File

@ -101,12 +101,16 @@ func (c *CiscoTelemetryGNMI) Start(acc telegraf.Accumulator) error {
// Invert explicit alias list and prefill subscription names
c.aliases = make(map[string]string, len(c.Subscriptions)+len(c.Aliases))
for _, subscription := range c.Subscriptions {
path := subscription.Path
if len(subscription.Origin) > 0 {
path = subscription.Origin + ":" + path
// Build the subscription path without keys
gnmiPath, err := parsePath(subscription.Origin, subscription.Path, "")
if err != nil {
return err
}
path, _ := c.handlePath(gnmiPath, nil, "")
name := subscription.Name
// If the user didn't provide a measurement name, use last path element
if len(name) == 0 {
name = path[strings.LastIndexByte(path, '/')+1:]
}
@ -269,7 +273,10 @@ func (c *CiscoTelemetryGNMI) handleSubscribeResponse(address string, reply *gnmi
// Group metrics
for key, val := range fields {
grouper.Add(name, tags, timestamp, key[len(aliasPath)+1:], val)
if len(aliasPath) > 0 {
key = key[len(aliasPath)+1:]
}
grouper.Add(name, tags, timestamp, key, val)
}
lastAliasPath = aliasPath
@ -347,14 +354,17 @@ func (c *CiscoTelemetryGNMI) handlePath(path *gnmi.Path, tags map[string]string,
aliasPath = name
}
for key, val := range elem.Key {
key = strings.Replace(key, "-", "_", -1)
if tags != nil {
for key, val := range elem.Key {
key = strings.Replace(key, "-", "_", -1)
// Use short-form of key if possible
if _, exists := tags[key]; exists {
tags[name+"/"+key] = val
} else {
tags[key] = val
}
// Use short-form of key if possible
if _, exists := tags[key]; exists {
tags[name+"/"+key] = val
} else {
tags[key] = val
}
}
}