python系统监控程序 时间 CPU内存使用率 硬盘大小 天气 日历

这篇具有很好参考价值的文章主要介绍了python系统监控程序 时间 CPU内存使用率 硬盘大小 天气 日历。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

import sys
from PyQt5.QtGui import QPainter, QColor, QFont
from PyQt5.QtCore import Qt, QPoint, QTimer, QTime, QDate, QThread
import psutil
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout
import subprocess
from PyQt5.QtWidgets import QApplication, QWidget, QCalendarWidget
import wmi
import urllib.request
import re


class CustomWindow1(QWidget):
    def __init__(self):
        super().__init__()

        # 设置窗口属性
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)

        # 设置窗口大小
        self.resize(400, 120)

        # 创建两个label控件
        self.label1 = QLabel(self)
        self.label1.move(20, 20)
        self.label1.setFont(QFont('Arial', 12))
        self.label2 = QLabel(self)
        self.label2.move(20, 60)
        self.label2.setFont(QFont('Arial', 12))

        # 创建定时器,每秒更新时间和日期
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.updateTime)
        self.timer.start(1000)

        # 初始更新时间和日期
        self.updateTime()

    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(Qt.NoPen)

        # 绘制上半部分背景
        painter.setBrush(QColor(43, 55, 64))
        painter.drawRoundedRect(0, 0, self.width(), self.height() // 2, 10, 10)

        # 绘制下半部分背景
        painter.setBrush(QColor(60, 78, 91))
        painter.drawRoundedRect(0, self.height() // 2, self.width(), self.height() // 2, 10, 10)

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.dragPosition = event.globalPos() - self.frameGeometry().topLeft()

    def mouseMoveEvent(self, event):
        if event.buttons() == Qt.LeftButton:
            self.move(event.globalPos() - self.dragPosition)

    def updateTime(self):
        # 获取当前时间和日期
        current_time = QTime.currentTime()
        current_date = QDate.currentDate()

        # 更新label控件显示
        self.label1.setText(current_time.toString('hh:mm:ss'))
        self.label2.setText(
            current_date.toString('yyyy-MM-dd') + ' ' + current_date.longDayName(current_date.dayOfWeek()))


class CustomWindow2(QWidget):
    def __init__(self):
        super().__init__()

        # 设置窗口属性
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)

        # 设置窗口大小
        self.resize(400, 120)

        # 创建两个label控件
        self.label1 = QLabel(self)
        self.label1.setGeometry(20, 20, 360, 40)
        # self.label1.setStyleSheet("background-color: white; border: 1px solid black;")
        self.label1.setAlignment(Qt.AlignCenter)
        self.label1.setFont(QFont("Arial", 12))
        self.label2 = QLabel(self)
        self.label2.setGeometry(20, 70, 360, 40)
        # self.label2.setStyleSheet("background-color: white; border: 1px solid black;")
        self.label2.setAlignment(Qt.AlignCenter)
        self.label2.setFont(QFont("Arial", 12))

        # 创建定时器,每秒更新CPU和内存使用率
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.updateUsage)
        self.timer.start(1000)

    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(Qt.NoPen)

        # 绘制上半部分背景
        painter.setBrush(QColor(43, 55, 64))
        painter.drawRoundedRect(0, 0, self.width(), self.height() // 2, 10, 10)

        # 绘制下半部分背景
        painter.setBrush(QColor(60, 78, 91))
        painter.drawRoundedRect(0, self.height() // 2, self.width(), self.height() // 2, 10, 10)

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.drag_position = event.globalPos() - self.frameGeometry().topLeft()

    def mouseMoveEvent(self, event):
        if event.buttons() == Qt.LeftButton:
            self.move(event.globalPos() - self.drag_position)

    def updateUsage(self):
        # 获取CPU和内存使用率
        cpu_percent = psutil.cpu_percent()
        mem_percent = psutil.virtual_memory().percent

        # 更新label控件显示
        self.label1.setText("CPU 使用率: {}%".format(cpu_percent))
        self.label2.setText("Memory 使用率: {}%".format(mem_percent))


class CustomWindow3(QWidget):
    def __init__(self):
        super().__init__()
        # 设置窗口属性
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)

        # 设置窗口大小
        self.resize(400, 120)

        # 创建一个label控件
        self.label = QLabel(self)
        self.label.setGeometry(20, 20, 360, 80)
        self.label.setAlignment(Qt.AlignCenter)
        self.label.setFont(QFont("Arial", 6))

        # 创建定时器,每秒更新ping的返回信息
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.updatePing)
        self.timer.start(1000)

    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(Qt.NoPen)

        # 绘制上半部分背景
        painter.setBrush(QColor(43, 55, 64))
        painter.drawRoundedRect(0, 0, self.width(), self.height() // 2, 10, 10)

        # 绘制下半部分背景
        painter.setBrush(QColor(60, 78, 91))
        painter.drawRoundedRect(0, self.height() // 2, self.width(), self.height() // 2, 10, 10)

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.drag_position = event.globalPos() - self.frameGeometry().topLeft()

    def mouseMoveEvent(self, event):
        if event.buttons() == Qt.LeftButton:
            self.move(event.globalPos() - self.drag_position)

    def updatePing(self):
        # 执行ping命令,获取返回信息
        result = subprocess.run(['ping', '-n', '1', 'www.baidu.com'], capture_output=True, text=True)
        output = result.stdout
        # print(output)
        lst = output.split(":")  # 分割字符串
        # print(lst[0])
        # print(lst[1])
        # print(lst[2])
        # 更新label控件显示
        self.label.setText(lst[2])


class CustomWindow4(QWidget):
    def __init__(self):
        super().__init__()

        # 设置窗口属性
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)

        # 设置窗口大小
        self.resize(400, 360)

        # 创建一个日历控件
        self.calendar = QCalendarWidget(self)
        self.calendar.setGeometry(20, 20, 360, 320)
        self.calendar.setStyleSheet("background-color: rgb(60, 78, 91);"
                                    "QTableView::item:first {background-color: rgb(60, 78, 91);}"
                                    "QTableView::item:selected:active {background-color: rgb(60, 78, 91);}"
                                    "QTableView::item:selected:!active {background-color: rgb(60, 78, 91);}")

    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(Qt.NoPen)

        # 绘制背景
        painter.setBrush(QColor(60, 78, 91))
        painter.drawRoundedRect(0, 0, self.width(), self.height(), 10, 10)

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.drag_position = event.globalPos() - self.frameGeometry().topLeft()

    def mouseMoveEvent(self, event):
        if event.buttons() == Qt.LeftButton:
            self.move(event.globalPos() - self.drag_position)


class CustomWindow5(QWidget):
    def __init__(self):
        super().__init__()

        # 设置窗口属性
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)

        # 获取磁盘信息
        self.disk_info = self.get_fs_info()

        # 初始化鼠标位置
        self.dragPosition = None

        # 计算窗口高度
        self.window_height = 60 + len(self.disk_info) * 20

        # 设置窗口大小
        self.setFixedWidth(400)
        self.setFixedHeight(self.window_height)

        # 创建磁盘信息Label
        self.label = QLabel(self)
        self.label.setText("磁盘信息")
        self.label.setFont(QFont("Arial", 8))
        self.label.setStyleSheet("color: green;")
        self.label.move(20, 20)

    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(Qt.NoPen)

        # 绘制上半部分背景
        painter.setBrush(QColor(43, 55, 64))
        painter.drawRoundedRect(0, 0, self.width(), 60, 10, 10)

        # 绘制下半部分背景
        painter.setBrush(QColor(60, 78, 91))
        painter.drawRoundedRect(0, 60, self.width(), self.height() - 60, 10, 10)

        # 绘制磁盘信息文本
        painter.setPen(QColor(0, 255, 0))  # 设置颜色为绿色
        painter.setFont(QFont("Arial", 8))  # 设置字体大小为8
        for i, disk in enumerate(self.disk_info):
            disk_name = disk['Caption']
            disk_FreeSpace = "{:.2f}".format(disk['FreeSpace'])
            text = f"{disk_name} 剩余 {disk_FreeSpace}G"
            painter.drawText(QPoint(20, 80 + i * 20), text)

    def get_fs_info(self):
        """
        获取文件系统信息
        包含分区的大小、已用量、可用量、使用率、挂载点信息
        """
        tmplist = []
        c = wmi.WMI()
        for physical_disk in c.Win32_DiskDrive():
            for partition in physical_disk.associators("Win32_DiskDriveToDiskPartition"):
                for logical_disk in partition.associators("Win32_LogicalDiskToPartition"):
                    tmpdict = {}
                    tmpdict["Caption"] = logical_disk.Caption
                    tmpdict["DiskTotal"] = int(logical_disk.Size) / 1024 / 1024 / 1024
                    tmpdict["UseSpace"] = (int(logical_disk.Size) - int(logical_disk.FreeSpace)) / 1024 / 1024 / 1024
                    tmpdict["FreeSpace"] = int(logical_disk.FreeSpace) / 1024 / 1024 / 1024
                    tmpdict["Percent"] = int(
                        100.0 * (int(logical_disk.Size) - int(logical_disk.FreeSpace)) / int(logical_disk.Size))
                    tmplist.append(tmpdict)
        return tmplist

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.dragPosition = event.globalPos() - self.frameGeometry().topLeft()

    def mouseMoveEvent(self, event):
        if event.buttons() == Qt.LeftButton and self.dragPosition is not None:
            self.move(event.globalPos() - self.dragPosition)

    def mouseReleaseEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.dragPosition = None


def tianqi(url):
    res1 = urllib.request.urlopen(url)
    date = res1.read().decode("utf8")
    pattern = re.compile(r'value="(.*?)" /')
    res2 = re.findall(pattern, date)
    return res2[1]


class CustomWindow6(QWidget):
    def __init__(self):
        super().__init__()

        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)

        self.resize(400, 120)

        SHIreweath = tianqi("http://www.weather.com.cn/weather1d/101130301.shtml").split()

        layout = QVBoxLayout(self)
        self.label1 = QLabel("石河子" + ":" + str(SHIreweath[-2]) + str(SHIreweath[-1]))
        self.label1.setAlignment(Qt.AlignCenter)
        layout.addWidget(self.label1)

        reweath = tianqi("http://www.weather.com.cn/weather1d/101130101.shtml").split()
        self.label2 = QLabel("乌鲁木齐" + ":" + str(reweath[-2]) + str(reweath[-1]))
        self.label2.setAlignment(Qt.AlignCenter)
        layout.addWidget(self.label2)

    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(Qt.NoPen)

        painter.setBrush(QColor(43, 55, 64))
        painter.drawRoundedRect(0, 0, self.width(), self.height() // 2, 10, 10)

        painter.setBrush(QColor(60, 78, 91))
        painter.drawRoundedRect(0, self.height() // 2, self.width(), self.height() // 2, 10, 10)

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.dragPosition = event.globalPos() - self.frameGeometry().topLeft()

    def mouseMoveEvent(self, event):
        if event.buttons() == Qt.LeftButton:
            self.move(event.globalPos() - self.dragPosition)


if __name__ == "__main__":
    app = QApplication(sys.argv)

    locX = 1300
    # 创建窗口1
    window1 = CustomWindow1()
    window1.show()
    window1.move(locX, 0)

    # 创建窗口2
    window2 = CustomWindow2()
    window2.show()
    window2.move(locX, 130)

    # 创建窗口3
    window3 = CustomWindow3()
    window3.show()
    window3.move(locX, 260)

    # 创建窗口4
    window4 = CustomWindow4()
    window4.show()
    window4.move(locX, 390)

    # 创建窗口5
    window5 = CustomWindow5()
    window5.show()
    window5.move(locX, 760)

    # 创建窗口6
    window6 = CustomWindow6()
    window6.show()
    window6.move(locX, 910)

    sys.exit(app.exec_())

python系统监控程序 时间 CPU内存使用率 硬盘大小 天气 日历,python,数据库,开发语言文章来源地址https://www.toymoban.com/news/detail-644307.html

到了这里,关于python系统监控程序 时间 CPU内存使用率 硬盘大小 天气 日历的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Linux-提高CPU、内存使用率shell脚本

    目录 1、提升CPU利用率 (1)构造CPU达到100% (2) 结束命令 2、提高内存利用率 可以申请的内存 申请内存空间: 完成后释放内存: 3、 使用ChaosBlade工具 cpu注入: 内存注入: (1)构造CPU达到100% for i in `seq 1 $(cat /proc/cpuinfo |grep \\\"physical id\\\" |wc -l)`; do dd if=/dev/zero of=/dev/null done (

    2024年02月04日
    浏览(58)
  • qt使用QCustomplot绘制cpu和内存使用率图

                QCustomPlot是一个开源的Qt C++图表库,用于可视化数据。该库提供了多种类型的可定制的图表,包括散点图、线图、柱状图和等高线图等。它还支持自定义绘制,可以创建任意形状和大小的元素,并使其与其他元素交互。QCustomPlot易于集成到现有的Qt应用程序中

    2024年02月09日
    浏览(38)
  • Java CPU或内存使用率过高问题定位教程

    Spring cloud微服务广泛应用后,服务的监控和运维压力也与日俱增,经常有服务出现CPU或者内存使用率过高的告警,那么遇到这样的问题我们该如何排查呢?我们可以借助哪些工具来定位问题呢?本文将介绍一下遇到此类问题的解决思路和方法。 1.通过应用日志定位思路 对于业

    2024年03月28日
    浏览(44)
  • 【阿里云】云监控CPU、磁盘使用率告警、手机&企微机器人告警

    1、云监控官方文档 主机监控 - 云监控 - 阿里云 https://help.aliyun.com/document_detail/48161.html 2、选择云监控主机监控报警规则  3、创建报警规则,CPU使用大于一定值报警 创建实际规则  官方文档规则描述 监控项说明 - 云监控 - 阿里云 https://help.aliyun.com/document_detail/43505.html 4、创建

    2024年02月16日
    浏览(45)
  • STM32 CubeMX (第四步Freertos内存管理和CPU使用率)

    学习使用Freertos第四步 在 FreeRTOS 中,中断管理和软件定时: · taskENTER_CRITICAL() ·; 是一个函数在 FreeRTOS 中使用的,用于进入临界区(critical section)。在临界区内,中断会被禁用,这样可以确保在多任务环境下共享资源的安全性。你可以在需要保护共享资源的代码段中使用 ·

    2024年02月12日
    浏览(37)
  • 【Visio 2019 移动、缩放卡死,高内存 CPU 和磁盘使用率,亲测有效】

    正在使用Microsoft Visio 2019,里面有较多的插图连线,当缩放、移动时回变得很卡,内存占用率特标高。机器:联想拯救者2021r7000p。 我在另一个线程中找到了解决方案 您需要关闭Visio,然后删除注册表项:HKEY_CURRENT_USER SOFTWARE Microsoft Office 16.0 Common ExperimentConfigs Ecs

    2024年02月13日
    浏览(73)
  • linux获取内存与cpu使用率(附有C语言源码与shell脚本)

    linux内核提供了一种通过/proc文件系统来在运行时访问内核内部数据结构,改变内核设置的机制,各种硬件平台上的linux系统的/proc文件系统的基本概念都是相同的。 /proc文件系统是一种内核和内核模块用来向进程发送信息的机制。这个伪文件系统可以和内核内部的数据结构进

    2024年02月06日
    浏览(32)
  • MongoDB 按照时间段查询某个物理机的CPU使用率,按照时间倒序排序,取出最新的5条数据

    1、连接MongoDB 1)如果 没有设置用户名密码 ,命令如下: 2)如果 设置了用户名密码 (比如: ceilometer / password ),命令如下: 2、连接数据库 其中,ceilometer 是需要使用的数据库名。 3、执行查询 查询SQL如下: 其中, meter 是性能表名, physical.cpu.utilization 是指标名, times

    2024年02月15日
    浏览(35)
  • 51单片机锅炉监控系统仿真设计( proteus仿真+程序+原理图+报告+讲解视频)

    基于51单片机锅炉监控系统仿真设计( proteus仿真+程序+原理图+报告+讲解视频) 仿真图proteus7.8及以上 程序编译器:keil 4/keil 5 编程语言:C语言 设计编号:S0056 基于51单片机AT89C51/52(与AT89S51/52、AT89C51/52、STC89C51/52等51内核单片机通用) 1.系统实时通过LCD1602显示水位检测值,锅

    2024年02月06日
    浏览(28)
  • python实现监控指定进程的CPU利用率、内存占用

            因为需要一直关注被测软件的CPU利用率和内存占用,人工记录十分麻烦,所以想做一个应用程序来代替手工记录。 思路: 1.弹窗,输入进程号 2.获取进程对象 3.日志保存在一个csv文件中,文件命名方式为:进程名+Process+进程号 4.文件第一行写入进程名,第二行表

    2023年04月12日
    浏览(33)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包