美文网首页
python搭建系统监控平台(psutil)

python搭建系统监控平台(psutil)

作者: 阿尼奥赛哟 | 来源:发表于2020-10-30 16:09 被阅读0次

psutil模块参数详解:https://www.cnblogs.com/iamjianghao/p/11894623.html

1. 读取服务器各项指标参数,存入数据库

import psutil

import time

import pymysql

db= pymysql.connect(user="root",passwd="Root@1997",db="test",host="172.16.22.196",port=3306)

db.autocommit(True)

cur= db.cursor()

def getinfo():

    mem= psutil.virtual_memory()

    memtotal= mem.total

    memfree= mem.free

    mempercent= mem.percent

    memused= mem.used

    cpu= psutil.cpu_percent(1)

return memtotal, memfree, memused, mempercent, cpu

if __name__== "__main__":

    while True:

        try:

            memtotal, memfree, memused, mempercent, cpu= getinfo()

           t=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

           sql= "insert into test (mem_free,mem_usage,mem_total,mempercent,cpu,time) value (%f,%f,%f,%s,%s,'%s')" % (

           memfree/1073741824,memused/1073741824,memtotal/1073741824, mempercent, cpu, t)

           cur.execute(sql)

           time.sleep(10)

except Exception as e:

            print(e)

结果:

相关文章

  • python搭建系统监控平台(psutil)

    psutil模块参数详解:https://www.cnblogs.com/iamjianghao/p/118946...

  • shirou/gopsutil/cpu

    psutil是一个跨平台进程和系统监控的Python库,gopsutil是其Go版本的实现。 仓库地址 https...

  • psutil 简单使用

    在 Python 中,可以使用psutil获取系统信息,用于系统监控、性能分析、进程管理等。 安装 获取CPU信息...

  • gopsutil

    psutil是一个跨平台进程和系统监控的Python库,而gopsutil是其Go语言版本的实现。本文介绍了它的基...

  • 【使用python监控Linux系统3】

    使用开源库监控Linux psutil psutil是一个开源且跨平台的库,其提供了便利的函数用来获取操作系统的信...

  • Python-Psutil系统监控

    详细文件移步Python学习笔记

  • python获取系统信息

    获取系统信息,可以用来监控反馈设备状态 psutil 是一个跨平台库(http://pythonhosted.or...

  • Python Tkinter与psutil完成网络速度监视

    psutil可以完成服务器状态监视,详情参考笔者以前的文章-Python使用psutil库监控服务器[https...

  • Python系统运维常用库

    【Python系统运维常用库】 1、psutil是一个跨平台库(http://code.google.com/p/...

  • 20170831

    看python自动化运维里有个psutil,加上最近又在做主机进程监控,在想使用psutil还是ps aux……感...

网友评论

      本文标题:python搭建系统监控平台(psutil)

      本文链接:https://www.haomeiwen.com/subject/ajedvktx.html