-
-
Save alexdias/d51ef12d02d9e8f56721c48d52517f5c to your computer and use it in GitHub Desktop.
Outlyer host network metrics plugin replacement
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
def check_netio(): | |
sys_path = '/rootfs/sys' # change this to the directory your host sys is mounted to | |
net_class_path = os.path.join(sys_path, 'class', 'net') | |
metric_keys = { | |
'bytes_sent': 'tx_bytes', | |
'bytes_recv': 'rx_bytes', | |
'packets_sent': 'tx_packets', | |
'packets_recv': 'rx_packets', | |
'errin': 'rx_errors', | |
'errout': 'tx_errors', | |
'dropin': 'rx_dropped', | |
'dropout': 'tx_dropped', | |
} | |
net_excludes = ['teredo', 'isatap', 'loopback'] | |
net_map = {} | |
for our_key, sys_key in metric_keys.iteritems(): | |
current_sum = 0 | |
for interface in os.listdir(net_class_path): | |
if interface in net_excludes: | |
continue | |
stats_folder = os.path.join(net_class_path, interface, 'statistics') | |
metric_file = os.path.join(stats_folder, sys_key) | |
try: | |
with open(metric_file, 'r') as stat_file: | |
stat = stat_file.read() | |
stat_value = int(stat) | |
net_map['network.' + interface.replace(' ', '_').lower() + '.' + our_key] = stat_value | |
current_sum += stat_value | |
except Exception: | |
continue | |
net_map['network.' + our_key] = current_sum | |
return net_map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment