python - 确定 CPU 利用率的时间
问题描述
我有兴趣了解我的系统的 CPU 使用率保持在 70% 或更高的时间。我的示例数据如下所示。完整的数据在这里
Time CPUDemandPercentage
2019-03-06 03:55:00 40.17
2019-03-06 14:15:00 77.33
2019-03-06 14:20:00 79.66
为了实现我想要的,我探索了以下事情。我试图:
- 确定峰值位置
- 确定峰宽
import numpy as np
import matplotlib.pyplot as plt
import scipy.signal
from pandas import read_csv
data=read_csv('data.csv',header=0,usecols=["CPUDemandPercentage"])
y = np.array(data['CPUDemandPercentage'])
indexes = scipy.signal.find_peaks_cwt(y, np.arange(1, 4))
plt.plot(indexes, y[indexes], "xr"); plt.plot(y); plt.legend(['Peaks'])
plt.show()
- 它不是很准确,没有显示负峰。我怎样才能在这里提高准确性。
- 还有我如何找到峰的宽度。
我在这里毫无头绪。有人能帮我吗。
解决方案
另一个答案完整的熊猫:这个解决方案是通用的,不需要有相同的 timedelta betwwen 措施
df['Time']=df['Time'].apply((lambda x: pd.to_datetime(x)))
df['TimeDelta'] = df['Time'].shift(-1) - df['Time']
filter = df['CPUDemandPercentage'] >= 70.0
df['changes'] = [(x,y) for x,y in zip(filter , filter.shift(-1))]
result = df[df['changes']==(True,True)]['TimeDelta'].sum()
print(f'TimeCPU>=70%: {result} or {result.total_seconds()/60} minutes')
输出:
TimeCPU>70%: 0 days 03:10:00 or 190.0 minutes
推荐阅读
- java - 如何在 Oreo+ 中永久运行服务
- chapel - 是否可以在记录中为泛型类型声明 LinkedList 字段?
- c++ - 将已经初始化的基类分配给派生类
- tsql - 麻烦将总销售额汇总到 T-sql 中的一行
- nlp - PolyAnalyst:是否有词性标签列表?
- google-chrome-extension - 无法将 innerHTML 的属性设置为 null
- java - SIGAR api 抛出 NoClassDefFoundError
- reactjs - ReactJS 在组件中捕获向前按钮按下
- javascript - CSS snap scroll:如何在 div 中间诱导 snap 滚动?
- javascript - 如何将 javascript 数组元素流式传输/发送到 S3 存储桶?