Monitoring with SdStatsd

A simple way to get your custom application metrics into Server Density for graphing and alerting is to use our custom statsd implementation. 

Installing the Sdstatsd Service

Install the Sdstatsd service on Debian/Ubuntu:

sudo apt-get install sd-agent-sdstatsd

Install the Sdstatsd service on RHEL/CentOS:

sudo yum install sd-agent-sdstatsd

Configuring the agent to monitor via Sdstatsd

By default the agent Sdstatsd does not require any configuration. It will automatically bind to localhost or on port 8125 on the next agent restart. 

You can configure the following options in your sd-agent config.cfg to customise your sdstatsd deployment: 

# If you don't want to enable the SdStatsd server, set this option to no
# use_sdstatsd: yes

#  Make sure your client is sending to the same port.
# sdstatsd_port: 8125

# you may want all statsd metrics coming from this host to be namespaced
# in some way; if so, configure your namespace here. a metric that looks
# like `` will instead become ``
# statsd_metric_namespace:

# By default, sdstatsd supports only plain ASCII packets. However, most
# (sd)statsd client support UTF8 by encoding packets before sending them
# this option enables UTF8 decoding in case you need it.
# However, it comes with a performance overhead of ~10% in the sdstatsd
# server. This will be taken care of properly in the new gen agent core.
# utf8_decoding: false

# The number of bytes allocated to the statsd socket receive buffer. By default,
# this value is set to the value of `/proc/sys/net/core/rmem_default`. If you
# need to increase the size of this buffer but keep the OS default value the
# same, you can set sdstats's receive buffer size here. The maximum allowed
# value is the value of `/proc/sys/net/core/rmem_max`.
# statsd_so_rcvbuf: 

Posting metrics to Sdstatsd

It's simple to post metrics to Sdstatsd. The python example below will send the metric 'application.metric.example' with a random value between 1-100. The metric is a counter and is tagged with 'example: tag'.

import socket
from random import randint

count = randint(1, 100) HOST = 'localhost' PORT = 8125 MESSAGE = 'application.metric.example:{}|c|#example: tag'.format(count) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.sendto(MESSAGE, (HOST, PORT))

Metric Types and Formatting 

Your metrics should be formatted in the following manner when sending them to sdstatsd|type|@sample_rate|#tag1:value,tag2
  • - A string with no colons, bars, or @ characters. This is the name that your metrics will appear under in your Server Density account
  • value - a float or integer. 
  • type - c for counter, g for gauge, ms for timer, h for histogram, s for set.
  • sample rate (optional) - A float between 0 and 1, inclusive. This is only available for counter, histogram and timer metrics. Defaults to 1, which means sample 100% of the time. 
  • tags (optional) - a comma separated list of tags. You can use colons for key:value tags. The device key is reserved and will be removed automatically. 

Some examples of correctly formatted metrics are below: 

# Increment the app.logins counter

# The cookie jar is half-full, gauge

# Sample the video length histogram half of the time

# Track a unique visitor to the site

# Increment the application logged in users counter, tagging by country of origin

# Track application logged in users, tagging by country of origin and use a 50% sample rate
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Monday  —  Friday.

10am  —  6pm UK.

Dedicated Support.