Last active
August 25, 2022 13:55
-
-
Save davemcphee/fb0966abaff5e365019f8226cb841837 to your computer and use it in GitHub Desktop.
prometheus to OpenTSDB metrics formetter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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