首页 > 其他 > 详细

[py]监控内存并出图

时间:2018-01-24 12:08:59      阅读:173      评论:0      收藏:0      [点我收藏+]

监控内存出图

先将内存数据搞到数据库

已使用内存算法

used = int(total) - int(free) - int(butffers) - int(cache)

技术分享图片

pymysql模块使用


db = ms.connect(host="localhost", user="root", password="123456", db="mem")
db.autocommit(True)
cur = db.cursor()

cur.execute(sql)

pymysql入库脚本

from time import sleep, time
import pymysql as ms

db = ms.connect(host="localhost", user="root", password="123456", db="mem")
db.autocommit(True)
cur = db.cursor()


def get_mem():
    with open("/proc/meminfo") as f:
        total = f.readline().split()[1]
        free = f.readline().split()[1]
        f.readline()
        butffers = f.readline().split()[1]
        cache = f.readline().split()[1]
    used = int(total) - int(free) - int(butffers) - int(cache)
    sql = 'insert into mem_used values (%d,%d)' % (used / 1024, time())
    cur.execute(sql)
    return int(used / 1024)


while True:
    mem = get_mem()
    print(mem)
    sleep(1)

[py]监控内存并出图

原文:https://www.cnblogs.com/iiiiiher/p/8340717.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!