我感兴趣的是找出我的系统的CPU使用率保持在70%或更高的时间。我的示例数据如下所示。完整数据here

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()

这给了我一个像
python - 确定CPU利用率的时间-LMLPHP
它不是很精确,没有显示负峰。我怎样才能提高这里的准确性。
还有我如何找到峰的宽度。
我不知道这是怎么回事。有人能帮我吗。

最佳答案

另一个完整的答案是:这个解决方案是通用的,不需要有相同的时间差度量

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

关于python - 确定CPU利用率的时间,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55030374/

10-12 21:11