Skip to content

Commit

Permalink
Merge pull request #388 from kongfei605/cloudwatch_fix
Browse files Browse the repository at this point in the history
cloudwatch add namespace info to metric name
  • Loading branch information
kongfei605 authored Mar 1, 2023
2 parents f5ab92e + 6f9ebc9 commit 118f9cd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions inputs/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ func (ins *Instance) aggregateMetrics(
)

for namespace, results := range metricDataResults {
ns := namespace
namespace = sanitizeMeasurement(namespace)

for _, result := range results {
Expand All @@ -527,14 +528,15 @@ func (ins *Instance) aggregateMetrics(
tags = *dimensions
}
tags["region"] = ins.Region
tags["namespace"] = ns

for i := range result.Values {
grouper.Add(namespace, tags, result.Timestamps[i], *result.Label, result.Values[i])
}
}
}
for _, metric := range grouper.Metrics() {
slist.PushSamples(inputName, metric.Fields(), metric.Tags())
slist.PushSamples(metric.Name(), metric.Fields(), metric.Tags())
}

return nil
Expand All @@ -553,7 +555,7 @@ func init() {
func sanitizeMeasurement(namespace string) string {
namespace = strings.ReplaceAll(namespace, "/", "_")
namespace = snakeCase(namespace)
return "cloudwatch_" + namespace
return inputName + "_" + namespace
}

func snakeCase(s string) string {
Expand Down

0 comments on commit 118f9cd

Please sign in to comment.