This page covers configuration for StatsD deployments.
| File | Purpose |
|---|---|
config.js |
Main configuration file |
Create config.js in your StatsD directory:
{
// Graphite backend
"graphiteHost": "graphite.example.com",
"graphitePort": 2003,
// StatsD listener
"port": 8125,
// Flush interval (milliseconds)
"flushInterval": 10000,
// Enable debug logging
"debug": false,
// Log all metrics
"dumpMessages": false
}
{
"graphiteHost": "graphite1.example.com",
"graphitePort": 2003,
"port": 8125,
"flushInterval": 10000,
// Additional backends
"backends": [
"./backends/graphite",
"./backends/repeater"
],
// Repeat to secondary backend
"repeater": [
{
"host": "graphite2.example.com",
"port": 2003
}
]
}
{
"port": 8125,
"flushInterval": 10000,
// Allow sampling in metric names
"sampledInternal": true,
// Default sample rate
"defaultSampleRate": 1.0
}
For timer metrics:
{
"port": 8125,
"flushInterval": 10000,
// Calculate percentiles
"percentiles": [90, 95, 99],
// Calculate mean
"calculateSummaries": true
}
Control metric naming:
{
"graphiteHost": "graphite.example.com",
"graphitePort": 2003,
"port": 8125,
// Add prefix to all metrics
"prefix": "stats.",
// Add suffix to timer metrics
"timerSuffix": ".timer",
// Global prefix
"globalPrefix": "prod.",
// Global suffix
"globalSuffix": ".statsd"
}
{
"port": 8125,
// Maximum metrics per flush
"maxStats": 1000,
// Delete counters after flush
"deleteCounters": true,
// Delete timers after flush
"deleteTimers": true,
// Delete gauges after flush
"deleteGauges": false
}
{
"port": 8125,
// Enable logging
"debug": false,
"dumpMessages": false,
// Log to file
"log": {
"logfile": "/var/log/statsd/statsd.log",
"loglevel": "info"
}
}
StatsD can read some configuration from environment variables:
export GRAPHITE_HOST=graphite.example.com
export GRAPHITE_PORT=2003
export STATSD_PORT=8125
export STATSD_FLUSH_INTERVAL=10000
# With config file
node stats.js config.js
# In background
nohup node stats.js config.js &
# With systemd (create service file)
sudo systemctl start statsd
# Send test metric
echo "test.metric:1|c" | nc -u -w0 localhost 8125
# Send timer metric
echo "test.timer:320|ms" | nc -u -w0 localhost 8125
# Send gauge
echo "test.gauge:42|g" | nc -u -w0 localhost 8125
# Check logs
tail -f /var/log/statsd/statsd.log
| Type | Format | Description |
|---|---|---|
| Counter | name:value\|c |
Increment/decrement |
| Timer | name:value\|ms |
Duration in milliseconds |
| Gauge | name:value\|g |
Absolute value |
| Set | name:value\|s |
Unique values |
If you see too many unique metric names:
If metrics are being dropped:
maxStatsflushInterval