pandas分析CPU和内存的利用率

import csv
import psutil
from time import strftime, localtime, sleep


flag = 1
with open('record.csv', 'w', newline='') as csvfile:
    writer = csv.writer(csvfile)
    writer.writerow(["date", "cpu", "memory"])
    while flag < 20:
        result = [(
            strftime("%H:%M:%S", localtime()),
            psutil.cpu_percent(1),
            psutil.virtual_memory().percent,
        )]
        print(result)
        writer.writerows(result)
        flag += 1
        sleep(2)
print("完成")
[('19:51:23', 12.6, 65.6)]
[('19:51:26', 11.9, 65.5)]
[('19:51:29', 14.6, 66.4)]
[('19:51:32', 10.8, 66.4)]
[('19:51:35', 12.0, 65.9)]
[('19:51:38', 7.3, 66.0)]
[('19:51:41', 7.0, 66.3)]
[('19:51:44', 7.8, 63.8)]
[('19:51:47', 10.1, 63.8)]
[('19:51:50', 30.9, 64.8)]
[('19:51:53', 12.5, 66.3)]
[('19:51:56', 6.2, 66.1)]
[('19:51:59', 31.3, 68.4)]
[('19:52:02', 12.0, 68.9)]
[('19:52:05', 7.4, 68.8)]
[('19:52:08', 5.4, 68.3)]
[('19:52:11', 20.3, 68.3)]
[('19:52:14', 2.7, 67.9)]
[('19:52:17', 7.7, 67.8)]
完成
import pandas as pd
from pyecharts import Line

df=pd.read_csv("record.csv")#读取csv文件

line = Line(title = "折线图",width = 600,height = 420)
date=df["date"].tolist()
cpu=df["cpu"].tolist()
memory=df["memory"].tolist()

print('统计信息:\n',df.describe())#统计信息

line.add(name = "CPU利用率", x_axis = date, y_axis = cpu,
line_width = 3,line_color = 'red',is_datazoom_show = True)
line.add(name = "内存利用率", x_axis = date, y_axis = memory,
line_width = 2,line_color = 'cyan',is_datazoom_show = True)
line.render( '折线图示范.html')

print("完成")
cpu利用率平均值是:
12.131579
内存利用率平均值是:
66.594737
统计信息:
              cpu     memory
count  19.000000  19.000000
mean   12.131579  66.594737
std     7.741522   1.577084
min     2.700000  63.800000
25%     7.350000  65.750000
50%    10.800000  66.300000
75%    12.550000  68.100000
max    31.300000  68.900000
完成

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值