StatsD is a statistic aggregation tool written in node.js. It is a simple, yet powerful, tool for counting and timing when monitoring. StatsD makes it very easy to monitor your own code.
Why StatsD?
In the DevOps world, it is crucial to record and monitor everything. Network, machine, and third party apps can be monitored using CollectD.
But how do you monitor your own code? That is where StatsD comes in. It helps you monitor your code in an easy and flexible way. When you want to track something in your code, just call StatsD: it will produce metrics for you.
Requirements
Node.js must be installed.
On Debian / Ubuntu:
1 2 | curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash - apt-get install -y nodejs |
On CentOS / Fedora:
1 2 | curl -sL https://rpm.nodesource.com/setup | bash - yum install -y nodejs |
On Mac OS X with brew:
1 | brew install nodejs |
Download node.js install for Windows and MacOSX.
Install StatsD
First download StatsD from GitHub.
Then create a configuration file
1 2 3 4 5 | $ git clone https://github.com/etsy/statsd.git $ cd statsd #create a configuration file $ cp exampleConfig.js config.js |
Edit config.js to look like:
1 2 3 4 5 | { port: 8125, mgmt_port: 8126, backends: [ "./backends/console" ] } |
- StatsD runs on port 8125
- StatsD Admin runs on port 8126
Send Metrics to StatsD
Start StatsD with its configuration file
1 2 3 4 | $ node stats.js config.js 27 Apr 15:31:51 - reading config file: config.js 27 Apr 15:31:51 - server is up [ ... ] |
Open a terminal and start sending metrics:
1 2 3 | $ echo "my.metric:2|c" | nc -u -w 1 127.0.0.1 8125 $ echo "my.metric.time:320|ms" | nc -u -w 1 127.0.0.1 8125 $ |
Note that these commands will not return any direct result.
The StatsD console should display the received metrics:
1 2 3 4 5 6 7 8 | Flushing stats at Mon Apr 27 2015 16:28:36 GMT+0000 (UTC) { counters: { 'statsd.bad_lines_seen': 0, 'statsd.packets_received': 2, 'statsd.metrics_received': 2, 'my.metric': 4 }, timers: {}, [...] |
This shows two metrics received – “statsd.metrics_received”: 2
The value of the counter is “my.metric”: 4
Go Further!
Monitor your own code with StatsD:
- StatsD in Java
- StatsD in Python
- StatsD in PHP
- StatsD with other programming languages
StatsD is usually used with other software or databases:
- Send StatsD metrics to InfluxDB
- Embedded StatsD in CollectD
- Send StatsD metrics to Graphite
Monitor & detect anomalies with Anomaly.io
SIGN UP