Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdhaworth/b71cda594f7a10f2e3c1 to your computer and use it in GitHub Desktop.
Save gdhaworth/b71cda594f7a10f2e3c1 to your computer and use it in GitHub Desktop.
Grabs all of the CloudWatch metric names and dimensions and prints them in Splunk's inputs.conf format for easy use with the Splunk AWS add-on. Requires awscli and jq.
#!/bin/bash -ex
exec aws cloudwatch list-metrics \
| jq -r '
.Metrics
| reduce .[] as $item ({}; .[$item.Namespace] |= {
names: (.names + [$item.MetricName] | unique),
dimensions: (.dimensions + [$item.Dimensions[].Name?] | unique)
})
| to_entries
| .[]
| .value.dimensions |= map({
(.): [".*"]
})
| "[aws_cloudwatch://\(.key | gsub("/"; ".") | ascii_downcase)]\n"
+ "metric_namespace = \(.key)\n"
+ "metric_names = \(.value.names | tojson)\n"
+ "metric_dimensions = \(.value.dimensions | tojson)\n"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment