Since v5.4, CollectD implements the StatsD network protocol.
You might not need to run two separate processes anymore.
About StatsD in CollectD
StatsD and CollectD are complementary monitoring solution.
- Stats is an event counter/aggregation service. Simply send events to this external service to monitor your own code. Periodically the aggregated events are sent to a database.
- CollectD is a statistics collection daemon. It periodically polls various sources such as your OS CPU, RAM, network but also from many database and software.
StatsD is also “embedded” into CollectD since v5.4 with the StatsD plugin. CollectD can now act as a StatsD process.
Install StatsD plugin for CollectD
Edit CollectD configuration file; usually located at /opt/collectd/etc/collectd.conf
Uncomment or add StatsD plugin and configuration:
Don’t forget to restart CollectD:
$ service collectd restart
- Host “0.0.0.0”; listen to any IP. Change to “127.0.0.1” to only allow localhost to send metrics.
- port 8125; where StatsD metrics will be received.
- DeleteSets true; the values of type sets metrics will not be sent if they didn’t change since the last interval.
Read more about StatsD plugin configuration
Calling CollectD StatsD
Many StatsD client libraries exist in various programming language. Pick your favorite and call StatsD on port 8125.
It’s also possible to call the Plugin from the command line:
$ echo "my.own.metric:1|c" | nc -w 1 -u 127.0.0.1 8125
$ echo "my.own.metric:4|c" | nc -w 1 -u 127.0.0.1 8125
If like me, your CollectD sends it metrics to InfluxDB you should see the values in your database.
Calling both commands:
- within the interval will result in an aggregate value of 5
- out of the interval will result in two values 4 and 1
StatsD is a very clever idea but not a complex software. It behaviour was replicated in 730 lines of C.
This Plugin is stable and was able to achieve 50k events per second on commodity hardware. If you already run CollectD and don’t need to run StatsD at scale it is highly recommend using this plugin. Save yourself the pain of running both services.