Skip to content

Instantly share code, notes, and snippets.

Created May 11, 2011 16:41
  • Star 63 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Send a metric to StatsD from bash
# Send a metric to statsd from bash
# Useful for:
# deploy scripts (
# init scripts
# sending metrics via crontab one-liners
# sprinkling in existing bash scripts.
# netcat options:
# -w timeout If a connection and stdin are idle for more than timeout seconds, then the connection is silently closed.
# -u Use UDP instead of the default option of TCP.
echo "deploys.test.myservice:1|c" | nc -w 1 -u 8125
Copy link

very useful, thanks :)

Copy link

Another suggestion:

echo "deploys.test.myservice:1|c" | nc -w 1 -cu 8125

Note the -c, from nc --help:

  -c, --close                close connection on EOF from stdin

Copy link

Amazing, very simple and useful! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment