Skip to content

Instantly share code, notes, and snippets.

@andreyev
Created June 30, 2021 18:20
Show Gist options
  • Save andreyev/256f25a288a6590215e98804ca8bee60 to your computer and use it in GitHub Desktop.
Save andreyev/256f25a288a6590215e98804ca8bee60 to your computer and use it in GitHub Desktop.
list and post all AWS tagged resources to prometheus pushgateway
cat <<EOF | curl --data-binary @- http://localhost:9091/metrics/job/inventory/cloud/aws
$(aws ec2 describe-regions --region us-east-1 | jq -r '.Regions[].RegionName' | sort | while read REGION; do
aws resourcegroupstaggingapi get-resources --region $REGION | jq --arg Region $REGION -r '.ResourceTagMappingList[].ResourceARN';
done | while read LINE; do echo 'resource_item{partition="'$(echo ${LINE//\//:} | cut -d ':' -f2)'",service="'$(echo ${LINE//\//:} | cut -d ':' -f3)'",region="'$(echo ${LINE//\//:} | cut -d ':' -f4)'",account_id="'$(echo ${LINE//\//:} | cut -d ':' -f5)'",resource_type="'$(echo ${LINE//\//:} | cut -d ':' -f6)'",resource_id="'$(echo ${LINE//\//:} | cut -d ':' -f7)'"} 1'; done| sort -u)
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment