簡體   English   中英

確定CPU利用率的時間

[英]Determining time for CPU Utilization

我有興趣了解我的系統的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()

這給了我一個圖表 峰

  • 它不是很准確,沒有顯示負峰值。 我怎樣才能在這里提高准確性。
  • 另外我如何找到峰的寬度。

我在這里沒有線索。 有人能幫我嗎。

以下不是基於熊貓的解決方案。 我們的想法是查看先前和當前的cpu級別,如果它們“足夠高”,則增加計數器

import csv

# Assuming delta time between rows is 5 minutes

DELTA_T = 5


def get_cpu_time_above_pct(pct):
    time_above_pct = 0
    previous_cpu_level = None
    with open('cpu.csv', 'rb') as f:
        reader = csv.reader(f, delimiter=',')
        for row in reader:
            current_cpu_level = float(row[1])
            if previous_cpu_level is not None and
               current_cpu_level >= pct and
               previous_cpu_level >= pct:
                   time_above_pct += DELTA_T
            previous_cpu_level = current_cpu_level

    return time_above_pct


print('CPU Time above 70\% : {} minutes'.format(get_cpu_time_above_pct(70)))

另一個答案是完整的熊貓:這個解決方案是通用的,不需要有相同的timedelta措施

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM