首页 > 解决方案 > 确定 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()

这给了我一个像 顶峰

我在这里毫无头绪。有人能帮我吗。

标签: pythonpandasnumpyscipylinear-regression

解决方案


另一个答案完整的熊猫:这个解决方案是通用的,不需要有相同的 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

推荐阅读