Last active
December 1, 2015 21:29
-
-
Save sobanvuex/9f5ab56b1a067910ccdb to your computer and use it in GitHub Desktop.
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/python | |
# -*- coding: utf-8 -*- | |
from os import listdir | |
import json | |
net = '/sys/class/net' | |
stat = net + '/{}/statistics/{}x_bytes' | |
interfaces = filter(lambda x: 'eth' in x, listdir(net)) | |
data = {} | |
for interface in interfaces: | |
received = open(stat.format(interface, 'r'), 'r').read().rstrip('\n') | |
send = open(stat.format(interface, 't'), 'r').read().rstrip('\n') | |
data[interface] = { | |
'received': received, | |
'send': send | |
} | |
print json.dumps(data, sort_keys=True, indent=2, separators=(',', ': ')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment