Python获取系统监控参数

系统监控


import os, json

# load
load = os.popen('cat /proc/loadavg').read()

# uptime
uptime = os.popen('uptime').read()

# net
net = os.popen('cat /proc/net/dev').read()

# memory
memory = os.popen('free -m').read()

# tcp
tcp = os.popen('ss -ant | wc -l').read()

# disk
disk = os.popen('df -hli').read()

# iostat
iostat = os.popen('iostat').read()

# data
data = {'load':load, 'uptime':uptime, 'net':net, 'memory':memory, 'tcp':tcp, 'disk':disk, 'iostat':iostat}

send = json.dumps(data)