Slug: statsd Date: 2011-02-16 Title: Statsd and Python layout: post

Short version: pystatsd is fire-and-forget site metrics from python, using Etsy’s StatsD and Graphite.

The brilliant devops folks at Etsy released (and posted about) an awesome little node.js-based stats server called statsd.

Statsd sits in front of the Graphite metrics server, providing a simple API for applications to send stats over UDP. UDP is “old tech” but is fire-and-forget – clients don’t have to wait for a response to keep processing.

I took a few hours last night (after reviewing my python socket programming) and ported Etsy’s PHP example to Python. Until (and if) it gets pulled into the main repo, yo can find the python sample client in my Github fork of statsd.

>>> from python_example import Statsd
>>> Statsd.timing('some.time','500|ms')
>>> Statsd.increment('some.int')
>>> Statsd.decrement('some.int')

Stand-alone Client

I reworked this code into a standalone client you can now find on Github:

>>> from pystatsd import Statsd
>>> statsd_client = Statsd(host, port)
>>> statsd_client.timing('some.time','500|ms')
>>> statsd_client.increment('some.int')
>>> statsd_client.decrement('some.int')

Enjoy!