diff options
author | Blaster4385 <venkateshchaturvedi12@gmail.com> | 2023-05-20 18:44:22 +0530 |
---|---|---|
committer | Blaster4385 <venkateshchaturvedi12@gmail.com> | 2023-05-21 11:04:05 +0530 |
commit | 364c5c00578fa2e88466bb0ddcaff3db34ccd4e4 (patch) | |
tree | b5ea0369e2c43ff74d1b9732883534f5cd6d16df /sysmon.py | |
parent | 5fd76b071a7b5b359abd62ab18ab9d42fad0d1a4 (diff) |
Add system information
- Also cleanup code
- Switch to almost realtime data reading
Diffstat (limited to 'sysmon.py')
-rw-r--r-- | sysmon.py | 52 |
1 files changed, 17 insertions, 35 deletions
@@ -5,12 +5,10 @@ from datetime import datetime from datetime import timedelta import psutil import serial -from gettext import c2py from time import sleep import sensors import subprocess import math -import pyowm import os CPU_TEMP_PATH = '/sys/devices/pci0000:00/0000:00:18.3/hwmon/hwmon2/temp1_input' @@ -27,37 +25,36 @@ def send_command(command): sleep(0.1) def set_time(date_time): - request = '\nTime=%s\r\n' % date_time.strftime('%H:%M:%S') - send_command(request) + curr_time=date_time.strftime('%H:%M:%S') + return curr_time def set_max(): ram_max = int(psutil.virtual_memory().total / (1024.*1024.)) - request = 'RamMax=%d\r\n' % ram_max - send_command(request) + # request = 'RamMax=%d\r\n' % ram_max + # send_command(request) + return ram_max def set_free(): ram_free = int(psutil.virtual_memory().free / (1024.*1024.)) - request = 'RamFree=%d\r\n' % ram_free - send_command(request) + # request = 'RamFree=%d\r\n' % ram_free + # send_command(request) + return ram_free -def set_system_info(): +def set_OS(): with open('/etc/os-release', 'r') as f: for line in f: if line.startswith('NAME='): OSName = line.split('"')[1] break - request = 'OS=%s\r\n' % OSName - send_command(request) - sleep(1) + return OSName +def set_kernel_version(): with open('/proc/version', 'r') as f: for line in f: Kernel = line.split(' ')[2].split('-')[0] break - request = 'Kernel=%s\r\n' % Kernel - send_command(request) - sleep(1) + return Kernel def set_uptime(): uptime_seconds = psutil.boot_time() @@ -65,35 +62,20 @@ def set_uptime(): uptime_hours = int(uptime.total_seconds() // 3600) uptime_minutes = int((uptime.total_seconds() % 3600) // 60) uptime = f"{uptime_hours:02d}:{uptime_minutes:02d}" - request = 'Uptime=%s\r\n' % uptime - send_command(request) + return uptime -def start(tty_serial): - - set_system_info() +def start(): while 1: - set_uptime() - sleep(1) cpu_temp = int(subprocess.check_output(['cat', CPU_TEMP_PATH]))/1000 - requests = "\nCpuTemp="+str(math.trunc(cpu_temp)) - send_command(requests) - sleep(1) cpu_pct = psutil.cpu_percent(interval=None, percpu=False) cpu_global = int(cpu_pct) - request = "\nCpuUsage=" + str(math.trunc(cpu_global)) + request = "\nCpuTemp="+str(math.trunc(cpu_temp))+",CpuUsage="+str(math.trunc(cpu_global))+",RamMax="+str(set_max())+",RamFree="+str(set_free())+",Time="+str(set_time(datetime.now()))+",OS="+str(set_OS())+",Kernel="+str(set_kernel_version())+",Uptime="+str(set_uptime()) send_command(request) - sleep(1) - set_time(datetime.now()) - sleep(1) - set_max() - sleep(1) - set_free() - sleep(1) + sleep(2) def main(): - start('/dev/ttyUSB0') - + start() if __name__ == "__main__": main() |