Skip to content

Instantly share code, notes, and snippets.

@alq666
Last active March 4, 2016 23:55
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 alq666/a2f79293df9bf8b028bf to your computer and use it in GitHub Desktop.
Save alq666/a2f79293df9bf8b028bf to your computer and use it in GitHub Desktop.
Datadog from gawk
/app/ {
split($7, arr, "/");
host = arr[2];
if (host == "<NOSRV>") {
host = "nosrv";
}
split($8, arr, "/");
tq = arr[1];
tw = arr[2];
tc = arr[3];
tr = arr[4];
tt = arr[5];
split($18, arr, "?");
stem = arr[1];
# send to dogstatsd
d = "app.connection.error:1|c|#server:" host ",stem:" stem;
print d > "/inet4/udp/0/localhost/8125";
close("/inet4/udp/0/localhost/8125");
# send other metrics
d = "haproxy.request.tq:" tq "|ms|#server:" host ",stem:" stem;
print d > "/inet4/udp/0/localhost/8125";
close("/inet4/udp/0/localhost/8125");
d = "haproxy.request.tw:" tw "|ms|#server:" host ",stem:" stem;
print d > "/inet4/udp/0/localhost/8125";
close("/inet4/udp/0/localhost/8125");
d = "haproxy.request.tc:" tc "|ms|#server:" host ",stem:" stem;
print d > "/inet4/udp/0/localhost/8125";
close("/inet4/udp/0/localhost/8125");
d = "haproxy.request.tr:" tr "|ms|#server:" host ",stem:" stem;
print d > "/inet4/udp/0/localhost/8125";
close("/inet4/udp/0/localhost/8125");
d = "haproxy.request.tt:" tt "|ms|#server:" host ",stem:" stem;
print d > "/inet4/udp/0/localhost/8125";
close("/inet4/udp/0/localhost/8125");
}
# in this case, mpstat 1 | gawk -f metric.awk
# change the metric name at will
/all/ {
d = "system.cpu.mpstat.idle:" $NF "|g";
print d > "/inet4/udp/0/localhost/8125";
close("/inet4/udp/0/localhost/8125");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment