Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (48 sloc) 1.98 KB
# This daemon requires django, the python statsd library, and PSUtil:
# The daemon reads system metrics and outputs them to StatsD
# Usage: python &
import os
import time
from django.conf import settings
from import NoArgsCommand
import psutil
import statsd
last_disk_io = psutil.disk_io_counters()
last_net_io = psutil.net_io_counters()
gauge = statsd.Gauge('system')
def io_change(last, current):
return dict([(f, getattr(current, f) - getattr(last, f))
for f in last._fields])
while True:
memory = psutil.phymem_usage()
disk = psutil.disk_usage("/")
disk_io = psutil.disk_io_counters()
disk_io_change = io_change(last_disk_io, disk_io)
net_io = psutil.net_io_counters()
net_io_change = io_change(last_net_io, net_io)
last_disk_io = disk_io
last_net_io = net_io
gauges = {
"memory.used": memory.used,
"memory.percent": memory.percent,
"cpu.percent": psutil.cpu_percent(),
"load": os.getloadavg()[0],
"disk.size.used": disk.used,
"disk.size.percent": disk.percent,
"": disk_io_change["read_bytes"],
"": disk_io_change["read_time"],
"disk.write.bytes": disk_io_change["write_bytes"],
"disk.write.time": disk_io_change["write_time"],
"": net_io_change["bytes_recv"],
"": net_io_change["errin"],
"": net_io_change["dropin"],
"net.out.bytes": net_io_change["bytes_sent"],
"net.out.errors": net_io_change["errout"],
"net.out.dropped": net_io_change["dropout"],
for name, value in gauges.items():
gauge.send(name, value)
You can’t perform that action at this time.