Skip to content

Instantly share code, notes, and snippets.

@sage-oli-wood
Created November 5, 2015 17:38
Show Gist options
  • Save sage-oli-wood/70e0931f037ea0aac132 to your computer and use it in GitHub Desktop.
Save sage-oli-wood/70e0931f037ea0aac132 to your computer and use it in GitHub Desktop.
F.Ugly way to push TCP network stats into DataDog. Can be run from a crontab entry
#!/bin/bash -eux
// set $DATADOGKEY to your API key
DATE=$(date +%s)
HOSTNAME=`hostname`
cat /proc/net/sockstat | grep TCP | cut -d":" -f2 |sed 's/^ //g' | awk '{print $1, $2"\n"$3, $4"\n"$5,$6"\n"$7,$8"\n"$9,$10}' > /tmp/stats.tmp
while read LINE; do
METRIC=$(echo $LINE | cut -d" " -f1)
VALUE=$(echo $LINE | cut -d" " -f2)
curl -X POST -H "Content-type: application/json" \
-d "{ \"series\" :
[{\"metric\":\"system.net.sock-$METRIC\",
\"points\":[[$DATE, $VALUE]],
\"type\":\"gauge\",
\"host\":\"$HOSTNAME\"}
]
}" \
"https://app.datadoghq.com/api/v1/series?api_key=$DATADOGKEY"
done < /tmp/stats.tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment