Created
April 10, 2013 21:54
-
-
Save mchestr/5358806 to your computer and use it in GitHub Desktop.
tcollector sensor instantaneous rate of bytes leaving squid.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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