Skip to content

Instantly share code, notes, and snippets.

@mchestr
Created April 10, 2013 21:54
Show Gist options
  • Save mchestr/5358806 to your computer and use it in GitHub Desktop.
Save mchestr/5358806 to your computer and use it in GitHub Desktop.
tcollector sensor instantaneous rate of bytes leaving squid.
#!/usr/bin/env python
import time
while True:
rx = open('/sys/class/net/eth0/statistics/rx_bytes')
tx = open('/sys/class/net/eth0/statistics/tx_bytes')
rx1 = int(rx.read())
tx1 = int(tx.read())
rx.close()
tx.close()
time.sleep(1)
rx = open('/sys/class/net/eth0/statistics/rx_bytes')
tx = open('/sys/class/net/eth0/statistics/tx_bytes')
rx2 = int(rx.read())
tx2 = int(tx.read())
rx.close()
tx.close()
rx_rate = (rx2 - rx1) / 1024
tx_rate = (tx2 - tx1) / 1024
print "%s %s %s" % ('bytes.rate.in', int(time.time()), rx_rate)
print "%s %s %s" % ('bytes.rate.out', int(time.time()), tx_rate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment