Skip to content

Instantly share code, notes, and snippets.

@kimthostrup
Forked from sobanvuex/nio.py
Created December 1, 2015 21:29
Show Gist options
  • Save kimthostrup/ca4c7b4626ccdf2b76f1 to your computer and use it in GitHub Desktop.
Save kimthostrup/ca4c7b4626ccdf2b76f1 to your computer and use it in GitHub Desktop.
#!/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