Skip to content

Instantly share code, notes, and snippets.

@masayoshi634
Created May 15, 2019 04:30
Show Gist options
  • Save masayoshi634/47aae0f806cab9f8711557728e5a4896 to your computer and use it in GitHub Desktop.
Save masayoshi634/47aae0f806cab9f8711557728e5a4896 to your computer and use it in GitHub Desktop.
import json
def get_snmp_static():
""" /proc/net/snmp をparseして辞書形式を返す """
with open('/proc/net/snmp', 'r') as fh:
protocols = []
statics = []
lines = fh.readlines()
for line in zip(*[iter(lines)] * 2):
keys = line[0].split()
values = line[1].split()
statics.append(dict(zip(keys[1:], [int(x) for x in values[1:]])))
protocols.append(keys[0][:-1])
return dict(zip(protocols, statics))
if __name__ == "__main__":
print(json.dumps(get_snmp_static()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment