Skip to content

Instantly share code, notes, and snippets.

@davemcphee
Last active August 25, 2022 13:55
Show Gist options
  • Save davemcphee/fb0966abaff5e365019f8226cb841837 to your computer and use it in GitHub Desktop.
Save davemcphee/fb0966abaff5e365019f8226cb841837 to your computer and use it in GitHub Desktop.
prometheus to OpenTSDB metrics formetter
#!/bin/sh
# curls a prometheus metrics endpoint, and awk's it into OpenTSDB format
JMX_URL="http://localhost:7070"
curl -s $JMX_URL | awk '
BEGIN { ts=systime() }
match($0, /{(.*)}/, a) {
tags=a[1];
gsub(/ /, "_", tags);
gsub(/,/, " ", tags);
gsub(/[^[:alnum:]_/= \-\.]/, "", tags);
metric=$NF
};
match($NF, /.*E.*/, result) {
split(result[0], numArr, "E");
metric=(numArr[1] * 10**numArr[2]);
}
/^[^#]/ {
sub(/\{.*/, "", $1);
gsub(/_/, ".", $1);
printf "zookeeper.nre.jmx.%s %d %f %s\n", $1, ts, metric, tags;
tags=""
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment