Skip to content
Snippets Groups Projects
Commit 3143fc83 authored by John-Paul Robinson's avatar John-Paul Robinson
Browse files

Expand date range of power stats over past year

parent 65dc2d42
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Power Stats # Power Stats
Use RestAPI to read power consumption info for cluster nodes and generate usage reports. this is based on the [pandas time series tutorial by Jennifer Walker](https://www.dataquest.io/blog/tutorial-time-series-analysis-with-pandas/) Use RestAPI to read power consumption info for cluster nodes and generate usage reports. this is based on the [pandas time series tutorial by Jennifer Walker](https://www.dataquest.io/blog/tutorial-time-series-analysis-with-pandas/)
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
import requests import requests
import pprint import pprint
import datetime import datetime
import os import os
import numpy as np import numpy as np
import pandas as pd import pandas as pd
import seaborn as sns import seaborn as sns
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import matplotlib.dates as mdates import matplotlib.dates as mdates
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
plt.rcParams["figure.figsize"] = (20,6) plt.rcParams["figure.figsize"] = (20,6)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Set up credentials to query RestAPI. Bright controls access based on the user identity. The user's cert.pem and cert.key are automatically generated but the cacert.pem needs to be constructed from the certs returned by the master. Set up credentials to query RestAPI. Bright controls access based on the user identity. The user's cert.pem and cert.key are automatically generated but the cacert.pem needs to be constructed from the certs returned by the master.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
cert_file='~/.cm/cert.pem' cert_file='~/.cm/cert.pem'
key_file='~/.cm/cert.key' key_file='~/.cm/cert.key'
ca_file='cacert.pem' ca_file='cacert.pem'
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
cert=(os.path.expanduser(cert_file), os.path.expanduser(key_file)) cert=(os.path.expanduser(cert_file), os.path.expanduser(key_file))
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Gather Cluster Power Data ## Gather Cluster Power Data
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
startdate = '2020/01/01 00:00:00' startdate = '2020/01/01 00:00:00'
enddate = '2020/07/10 00:00:00' enddate = '2021/02/21 00:00:00'
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
params = ( params = (
('start', startdate), ('start', startdate),
('measurable', 'Pwr_Consumption'), ('measurable', 'Pwr_Consumption'),
('indent', '1'), ('indent', '1'),
) )
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
response = requests.get('https://master:8081/rest/v1/monitoring/dump', params=params, cert=cert, verify=False) response = requests.get('https://master:8081/rest/v1/monitoring/dump', params=params, cert=cert, verify=False)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Simply read the json response into a dataframe for futher parsing. Simply read the json response into a dataframe for futher parsing.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
df = pd.DataFrame(response.json()["data"]) df = pd.DataFrame(response.json()["data"])
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Some of data values report unrealistic power values. Any reading over 10kW is considered invalid. Some of data values report unrealistic power values. Any reading over 10kW is considered invalid.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
df = df.loc[df['raw'] < 10000] df = df.loc[df['raw'] < 10000]
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Create a datatime type column from the reported sample times. Create a datatime type column from the reported sample times.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
df['datetime'] = pd.to_datetime(df.time, format="%Y/%m/%d %H:%M:%S") df['datetime'] = pd.to_datetime(df.time, format="%Y/%m/%d %H:%M:%S")
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Create an index for the hourly Create an index for the hourly
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
hourly_idx=pd.date_range(startdate, enddate, freq='H') hourly_idx=pd.date_range(startdate, enddate, freq='H')
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
debug=False debug=False
# prepare data frame to append to, use zeros for default column # prepare data frame to append to, use zeros for default column
m6_hourly_pwr=pd.DataFrame(np.zeros((1,len(hourly_idx))).T, index=hourly_idx, columns=['sum']) m6_hourly_pwr=pd.DataFrame(np.zeros((1,len(hourly_idx))).T, index=hourly_idx, columns=['sum'])
for num, entity in enumerate(df.entity.unique()): for num, entity in enumerate(df.entity.unique()):
if entity not in ['c0108', 'c0009']: if entity not in ['c0108', 'c0009']:
node_pwr=df[df.entity==entity].set_index("datetime") node_pwr=df[df.entity==entity].set_index("datetime")
node_pwr=node_pwr[['raw']].resample('H').mean() node_pwr=node_pwr[['raw']].resample('H').mean()
node_pwr=node_pwr[startdate:enddate].fillna(method="ffill") node_pwr=node_pwr[startdate:enddate].fillna(method="ffill")
if debug: if debug:
print(node_pwr) print(node_pwr)
missing = node_pwr['raw'].isnull().sum() missing = node_pwr['raw'].isnull().sum()
print("{}: {} missing {}\n".format(num, entity, missing)) print("{}: {} missing {}\n".format(num, entity, missing))
m6_hourly_pwr[entity]= node_pwr[startdate:enddate] m6_hourly_pwr[entity]= node_pwr[startdate:enddate]
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Plot Per-node Hourly ## Plot Per-node Hourly
This is just to see the data for each node in one plot and get a feel for how the nodes behave relative to each other. There is too much data to decern individual behavior of specific nodes This is just to see the data for each node in one plot and get a feel for how the nodes behave relative to each other. There is too much data to decern individual behavior of specific nodes
but it does give a sense of how the total power adds up. but it does give a sense of how the total power adds up.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
m6_hourly_pwr['2020-02-01':'2020-07-09'].iloc[:,1:].plot(legend=False) m6_hourly_pwr['2020-02-01':'2020-07-09'].iloc[:,1:].plot(legend=False)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Plot Power Usage Graph # Plot Power Usage Graph
Pick the start and end date for the plots from the data range selected above. Generate the sum and plot only it's values. Pick the start and end date for the plots from the data range selected above. Generate the sum and plot only it's values.
We skip over the first month of collection because it is uncommonly noisy. We skip over the first month of collection because it is uncommonly noisy.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
kW = m6_hourly_pwr['2020-02-01':'2020-07-09'].sum(axis=1)/1000 kW = m6_hourly_pwr['2020-02-01':'2021-02-21'].sum(axis=1)/1000
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
ax = kW.plot() ax = kW.plot()
ax.set_ylabel("Power (kW)") ax.set_ylabel("Power (kW)")
ax.set_title("Cheaha compute and login node hourly power use") ax.set_title("Cheaha compute and login node hourly power use")
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Resample hourly sum to support the seven day average. Resample hourly sum to support the seven day average.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
kW_d = kW.resample('D').mean() kW_d = kW.resample('D').mean()
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
# Compute the centered 7-day rolling mean # Compute the centered 7-day rolling mean
# https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.rolling.html # https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.rolling.html
kW_7d = kW_d.rolling(7, center=True).mean() kW_7d = kW_d.rolling(7, center=True).mean()
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
# Plot houry, daily, 7-day rolling mean # Plot houry, daily, 7-day rolling mean
fig, ax = plt.subplots() fig, ax = plt.subplots()
ax.plot(kW, marker='.', markersize=2, color='gray', linestyle='None', label='Hourly Average') ax.plot(kW, marker='.', markersize=2, color='gray', linestyle='None', label='Hourly Average')
ax.plot(kW_d, color='brown', linewidth=2, label='1-day Average') ax.plot(kW_d, color='brown', linewidth=2, label='1-day Average')
ax.plot(kW_7d, color='black', linewidth=4, label='7-day Rolling Average') ax.plot(kW_7d, color='black', linewidth=4, label='7-day Rolling Average')
label='Trend (7 day Rolling Mean)' label='Trend (7 day Rolling Mean)'
ax.legend() ax.legend()
ax.set_ylabel('Power (kW)') ax.set_ylabel('Power (kW)')
ax.set_title('Cheaha Trends in Electricity Consumption'); ax.set_title('Cheaha Trends in Electricity Consumption');
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment