File indexing completed on 2024-11-03 06:41:20
0001 #!/usr/bin/python3 0002 0003 import socket, psutil, subprocess 0004 import sys, errno 0005 0006 #HOST = '192.168.178.26' 0007 HOST = 'localhost' 0008 PORT = 1030 0009 ADDR = (HOST,PORT) 0010 serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 0011 0012 serv.bind(ADDR) 0013 serv.listen(1) 0014 0015 # download pinpoit from https://github.com/osmhpi/pinpoint 0016 # use pinpoint -l to get the list of counters and aliases for them, 0017 # adjust the command below - e.g. use CPU,RAM only if not counter is available for the GPU, etc. 0018 pinpoint_cmd = "pinpoint -e CPU,GPU,RAM -i 200 -c sleep 0.1" 0019 0020 print ('listening ...') 0021 0022 while True: 0023 conn, addr = serv.accept() 0024 print('client connected ... ', addr) 0025 cpu_percent = str(psutil.cpu_percent()) 0026 pinpoint_output = subprocess.check_output(pinpoint_cmd, shell=True).decode("utf-8") 0027 result = str(cpu_percent) + ',' + pinpoint_output 0028 0029 try: 0030 conn.send(result.encode()) 0031 print('written ' + result) 0032 except (BrokenPipeError, IOError): 0033 pass 0034 0035 conn.close() 0036 print('client disconnected')