This commit is contained in:
Villivateur Von 2022-03-21 08:59:17 +08:00
commit eea55f928d
2 changed files with 59 additions and 0 deletions

46
main.py Normal file
View File

@ -0,0 +1,46 @@
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)

13
topuino_slave.service Normal file
View File

@ -0,0 +1,13 @@
[Unit]
Description=Topuino Server Slave
After=network.target
[Service]
Type=simple
User=sampleuser
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/python3 /path/to/main.py
[Install]
WantedBy=multi-user.target