This guide provides an Ansible playbook to install StatsD from source/npm for Debian 10+, Ubuntu LTS, and RHEL 9+ compatible systems.
StatsD is not available in standard distribution repositories. This playbook installs StatsD from npm.
- name: Install StatsD
hosts: statsd
become: true
vars:
statsd_graphite_host: "graphite"
statsd_graphite_port: 2003
statsd_port: 8125
statsd_install_dir: /opt/statsd
tasks:
- name: Install Node.js and npm (Debian/Ubuntu)
apt:
name:
- nodejs
- npm
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install Node.js and npm (RHEL)
dnf:
name:
- nodejs
- npm
state: present
when: ansible_os_family == "RedHat"
- name: Create StatsD installation directory
file:
path: "{{ statsd_install_dir }}"
state: directory
mode: "0755"
- name: Install StatsD from npm
npm:
name: statsd
global: true
state: present
- name: Create StatsD configuration
copy:
dest: "{{ statsd_install_dir }}/config.js"
content: |
{
"graphiteHost": "{{ statsd_graphite_host }}",
"graphitePort": {{ statsd_graphite_port }},
"port": {{ statsd_port }},
"flushInterval": 10000
}
mode: "0644"
notify: restart statsd
- name: Create systemd service for StatsD
copy:
dest: /etc/systemd/system/statsd.service
content: |
[Unit]
Description=StatsD daemon
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/statsd {{ statsd_install_dir }}/config.js
Restart=on-failure
User=nobody
WorkingDirectory={{ statsd_install_dir }}
[Install]
WantedBy=multi-user.target
mode: "0644"
notify:
- reload systemd
- restart statsd
handlers:
- name: reload systemd
systemd:
daemon_reload: true
- name: restart statsd
service:
name: statsd
state: restarted
/opt/statsd/config.js8125/udp - StatsD UDP listener (primary)8126/tcp - Admin interface (optional)Any questions?
Feel free to contact us. Find all contact information on our contact page.