"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "", "" "". "" "" "" "" "" "" "" "," "" "" "," "" "" "," "" "," "" ">> Ps_server.py>> Author: Liu Yang>> e-mail: [email protected] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "." "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" #!/usr/bin/env python#-*-coding:utf-8-*-import sys, osfrom, "" ". Socket import *import psutilfrom time import sleep# from CPU information import cpu_message# from memory information import memory_message# from Battery information Import battery_message# from disk information import disk_partitions# from CPU Usage Import cpu_utilizationdef cpu_utilization (): What Cpu_start_alltime=psutil.cpu_times () "Print" Cpu_start_alltime: Scputimes (user=14088.359375, system= 20540.59375, idle=362071.6875, interrupt=847.9375019073486, dpc=3795.6875) ' T1all=sum (CPU _start_alltime) #开始的cpu时间总和 Sleep (1) #休眠一秒 cpu_end_alltime=psutil.cpu_times () t2all=sum (cpu_end_alltime) #结束时的cpu时间总 Busy time starting with t1busy=t1all-cpu_start_alltime.idle# = Total time-idle time T2Busy=t2all-cpu_end_alltime.idle ' CPU Usage: (end of busy time-start busy time)/(total time to end-total time to start) ' cpu_busy= (t2busy-t1busy)/( T2all-t1all) *100 # print ("CPU Usage:%0.2f"%cpu_busy+ '% ') return cpu_busy# Create server-side TCP/IP ipv4server=socket (af_inet,sock_ STREAM) server.bind ((' localhost ', $)) Server.listen (5) print ("Waiting for client to connect ...") while True: # waits for a connection to block conn,addr= Server.accept () # Primitive values need square brackets!!! Print ("%s connected ..."%addr[0]) while true:data = Conn.recv (1024x768). Decode (' Utf-8 ') if data = = ' CPU ': Buf=str (Cpu_utilization ()). Encode (' Utf-8 ') print (BUF) conn.send (BUF) if not data: Print ("Customer may have disconnected ...") Break Conn.close ()
[Python Study notes]cs schema remote access get information--server end