Echo-ing StatsD metrics locally
March 22, 2023It's useful to know what StatsD metrics you're sending locally before it hits your production metrics sink. Getting a metric name, namespace, or data type incorrect in production is annoying, and it can mess up metrics for a certain time window after it's fixed.
Assuming this example that sends a metric:
1from time import sleep 2import statsd 3 4c = statsd.StatsClient("localhost", 8125) 5 6while True: 7 sleep(2) 8 c.timing("stats.timed", 1) 9 c.incr("foo")
You can follow what it's sending locally by using netcat
to listen for the
UDP packets:
1$ nc -ulv -p 8125 2Received packet from 127.0.0.1:58916 -> 127.0.0.1:8125 (local) 3stats.timed:1.000000|msfoo:1|c
$ nc -ulv
starts nc
in UDP listening mode:
-u
= UDP-l
= Listen-v
= Verbose Logs-p
= Port of your StatsD emitter