47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
|
import requests
|
||
|
import psutil
|
||
|
|
||
|
##############################################
|
||
|
####### User Defined Area 用户自定义区 ########
|
||
|
|
||
|
uuid = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
|
||
|
mount_point0 = '/'
|
||
|
mount_point1 = '/'
|
||
|
|
||
|
#################### End #####################
|
||
|
##############################################
|
||
|
|
||
|
|
||
|
url = "http://iot.vvzero.com/topuino/putdata"
|
||
|
|
||
|
while True:
|
||
|
try:
|
||
|
mem_percent = int(psutil.virtual_memory().percent)
|
||
|
disk_percent = int(psutil.disk_usage(mount_point0).percent)
|
||
|
disk1_percent = int(psutil.disk_usage(mount_point1).percent)
|
||
|
disk_read_before = psutil.disk_io_counters().read_bytes
|
||
|
disk_write_before = psutil.disk_io_counters().write_bytes
|
||
|
net_sent_before = psutil.net_io_counters().bytes_sent
|
||
|
net_recv_before = psutil.net_io_counters().bytes_recv
|
||
|
cpu_percent = int(psutil.cpu_percent(interval=1)) # For delay
|
||
|
disk_read_after = psutil.disk_io_counters().read_bytes
|
||
|
disk_write_after = psutil.disk_io_counters().write_bytes
|
||
|
net_sent_after = psutil.net_io_counters().bytes_sent
|
||
|
net_recv_after = psutil.net_io_counters().bytes_recv
|
||
|
|
||
|
data = {
|
||
|
'UUID': uuid,
|
||
|
'CPU_PERCENT': cpu_percent,
|
||
|
'MEM_PERCENT': mem_percent,
|
||
|
'DISK_PERCENT': disk_percent,
|
||
|
'DISK1_PERCENT': disk1_percent,
|
||
|
'DISK_READ_RATE': disk_read_after - disk_read_before,
|
||
|
'DISK_WRITE_RATE': disk_write_after - disk_write_before,
|
||
|
'NET_SENT_RATE': net_sent_after - net_sent_before,
|
||
|
'NET_RECV_RATE': net_recv_after - net_recv_before,
|
||
|
}
|
||
|
|
||
|
requests.post(url, data)
|
||
|
except Exception as e:
|
||
|
print(e)
|