File: server_cpu_udp_socket.py

package info (click to toggle)
labplot 2.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 70,348 kB
  • sloc: cpp: 145,806; ansic: 4,534; python: 881; yacc: 540; xml: 357; sh: 185; awk: 35; makefile: 7
file content (15 lines) | stat: -rwxr-xr-x 334 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/python

from socket import *
import psutil

HOST = 'localhost'
PORT = 1027
ADDR = (HOST,PORT)

serv = socket(AF_INET, SOCK_DGRAM)
serv.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
while True:
  cpu_percent = str(psutil.cpu_percent(interval=0.5))
  serv.sendto(cpu_percent.encode(), ADDR)
  print('written ' + cpu_percent, ADDR)