File: server_cpu_udp_socket.py

package info (click to toggle)
labplot 2.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 41,104 kB
  • sloc: cpp: 89,715; ansic: 4,251; python: 741; yacc: 480; xml: 174; sh: 124; makefile: 40; awk: 35
file content (14 lines) | stat: -rwxr-xr-x 345 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/python

import socket
import psutil

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