Omit keys when creating measurement names for GNMI telemetry (#5986)
This commit is contained in:
parent
4b6e791908
commit
4cfd70b6c0
|
@ -101,12 +101,16 @@ func (c *CiscoTelemetryGNMI) Start(acc telegraf.Accumulator) error {
|
||||||
// Invert explicit alias list and prefill subscription names
|
// Invert explicit alias list and prefill subscription names
|
||||||
c.aliases = make(map[string]string, len(c.Subscriptions)+len(c.Aliases))
|
c.aliases = make(map[string]string, len(c.Subscriptions)+len(c.Aliases))
|
||||||
for _, subscription := range c.Subscriptions {
|
for _, subscription := range c.Subscriptions {
|
||||||
path := subscription.Path
|
// Build the subscription path without keys
|
||||||
if len(subscription.Origin) > 0 {
|
gnmiPath, err := parsePath(subscription.Origin, subscription.Path, "")
|
||||||
path = subscription.Origin + ":" + path
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
path, _ := c.handlePath(gnmiPath, nil, "")
|
||||||
name := subscription.Name
|
name := subscription.Name
|
||||||
|
|
||||||
|
// If the user didn't provide a measurement name, use last path element
|
||||||
if len(name) == 0 {
|
if len(name) == 0 {
|
||||||
name = path[strings.LastIndexByte(path, '/')+1:]
|
name = path[strings.LastIndexByte(path, '/')+1:]
|
||||||
}
|
}
|
||||||
|
@ -269,7 +273,10 @@ func (c *CiscoTelemetryGNMI) handleSubscribeResponse(address string, reply *gnmi
|
||||||
|
|
||||||
// Group metrics
|
// Group metrics
|
||||||
for key, val := range fields {
|
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
|
lastAliasPath = aliasPath
|
||||||
|
@ -347,6 +354,7 @@ func (c *CiscoTelemetryGNMI) handlePath(path *gnmi.Path, tags map[string]string,
|
||||||
aliasPath = name
|
aliasPath = name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tags != nil {
|
||||||
for key, val := range elem.Key {
|
for key, val := range elem.Key {
|
||||||
key = strings.Replace(key, "-", "_", -1)
|
key = strings.Replace(key, "-", "_", -1)
|
||||||
|
|
||||||
|
@ -356,6 +364,8 @@ func (c *CiscoTelemetryGNMI) handlePath(path *gnmi.Path, tags map[string]string,
|
||||||
} else {
|
} else {
|
||||||
tags[key] = val
|
tags[key] = val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue