[Python Study Notes]CS架构远程访问获取信息--SERVER端

‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
>>文件: ps_server.py
>>作者: liu yang
>>邮箱: [email protected]

‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys, os
from socket import *
import  psutil
from time import sleep
# from cpu信息 import cpu_message
# from 内存信息 import memory_message
# from 电池信息 import battery_message
# from 磁盘信息 import disk_partitions
# from cpu使用率 import cpu_utilization

def cpu_utilization():

    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时间总和

    t1busy=t1all-cpu_start_alltime.idle#开始的忙碌时间=总时间-空闲时间
    t2busy=t2all-cpu_end_alltime.idle

    ‘‘‘cpu使用率:(结束的忙碌时间-开始的忙碌时间)/(结束的总时间-开始的总时间)‘‘‘
    cpu_busy=(t2busy-t1busy)/(t2all-t1all)*100
    # print("cpu使用率:%0.2f"%cpu_busy+‘%‘)
    return  cpu_busy

# 创建服务端 TCP/IP IPv4
server=socket(AF_INET,SOCK_STREAM)
server.bind((‘localhost‘,66))
server.listen(5)
print("等待客户端进行连接...")

while True:
    # 等待连接阻塞
    conn,addr=server.accept()
    # 元祖取值需要用方括号!!!
    print("%s已连接..."%addr[0])
    while True:
        data = conn.recv(1024).decode(‘utf-8‘)
        if data == ‘cpu‘:
            buf=str(cpu_utilization()).encode(‘utf-8‘)
            print(buf)
            conn.send(buf)
        if not data:
            print("客户按可能已断开连接...")
            break
            conn.close()

原文地址:https://www.cnblogs.com/liu66blog/p/8450346.html

时间: 2024-11-02 11:38:45

[Python Study Notes]CS架构远程访问获取信息--SERVER端的相关文章

[Python Study Notes]CS架构远程访问获取信息--SERVER端v2.0

更新内容: 1.增加内存信息获取 2.增加电池信息获取 3.增加磁盘信息获取 4.重新布局窗体 5.增加窗体名称 6.增加连接成功之前,不可按压 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' >>文件: ps_server.py >>作者: liu yang >>邮箱: [email protected] >&g

[Python Study Notes]CS架构远程访问获取信息--Client端v2.0

更新内容: 1.增加内存信息获取 2.增加电池信息获取 3.增加磁盘信息获取 4.重新布局窗体 5.增加窗体名称 6.增加连接成功之前,不可按压 效果图: ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' >>文件: ps_client.py >>作者: liu yang >>邮箱: [email protected] &

[Python Study Notes]CS架构远程访问获取信息--Client端

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' >>文件: ps_client.py >>作者: liu yang >>邮箱: [email protected] '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

[Python Study Notes]CS架构远程访问获取信息--Client端v1.0

更新内容: 1.添加entry栏默认ip和port口 2.修正退出功能 3.添加退出自动关闭窗口功能 4.优化cpu显示为固定保留两位小数 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' >>文件: ps_client.py >>作者: liu yang >>邮箱: [email protected] '''''''''

[Python Study Notes]进程信息(丁丁软件监控进程,http-post)

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' >>文件: 进程信息.py >>作者: liu yang >>邮箱: [email protected] ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

[Python Study Notes]内存信息

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' >>文件: 内存信息.py >>作者: liu yang >>邮箱: [email protected] ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

[Python Study Notes]电池信息

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' >>文件: 电池信息.py >>作者: liu yang >>邮箱: [email protected] ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

[Python Study Notes]cpu信息

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' >>文件: cpu信息.py >>作者: liu yang >>邮箱: [email protected] '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

[Python Study Notes]python面试题

1.什么是pickling和unpickling?(1分) Pickle模块接受任何Python对象,并将其转换为字符串,使用dump函数将其转储到文件中,这个过程称为pickling.从存储的字符串表示中检索原始Python对象的过程称为unpickling. 2.作为解释型语言,Python如何运行?(1分) Python是一种解释型语言.Python程序直接从源代码运行,将程序员编写的源代码转换成中间语言,再将中间语言翻译成必须执行的机器语言. 3.有哪些工具可以帮助查找错误或执行静态分析