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

Add all nodes power plot and update all plots for shared x axis

Create a meta-pattern plot for all nodes.
Clean up all multi-node plots with a shared x-axis and correct
legend placement on subplots.
parent 3aa25b34
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:
``` ```
# https://stackoverflow.com/a/9031848 # https://stackoverflow.com/a/9031848
import warnings import warnings
warnings.filterwarnings('ignore') warnings.filterwarnings('ignore')
``` ```
%% 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 = '2021/02/21 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:
## Clean Data and Resample ## Clean Data and Resample
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.
Shouldn't do that until later since it implicitly filters out NaN Shouldn't do that until later since it implicitly filters out NaN
%% 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(sorted(df.entity.unique())): for num, entity in enumerate(sorted(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")
node_pwr=node_pwr[startdate:enddate].fillna(method="bfill") node_pwr=node_pwr[startdate:enddate].fillna(method="bfill")
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. Plot nodes in individual subplotes to decern individual behavior of specific nodes. It does give a sense of how the total power adds up. 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. Plot nodes in individual subplotes to decern individual behavior of specific nodes. It does give a sense of how the total power adds up.
Inspect the nodes in the first rack. Inspect the nodes in the first rack.
Plot help on [shared x-axis](https://stackoverflow.com/a/37738851)
on [correct pandas legend use](https://stackoverflow.com/a/59797261)
and [subplot legend placement](https://stackoverflow.com/a/27017307)
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
num_nodes=36 num_nodes=36
fig, axes = plt.subplots(num_nodes,1, figsize=(20,30)) fig, axes = plt.subplots(num_nodes,1, sharex=True, figsize=(20,30))
for i in range(num_nodes): for i in range(num_nodes):
m6_hourly_pwr['2020-02-01':'2021-02-21'].iloc[:,i+1:i+2].plot(ax=axes[i], legend="left") m6_hourly_pwr['2020-02-01':'2021-02-21'].iloc[:,i+1:i+2].plot(ax=axes[i], legend=True)
axes[i].legend(loc='lower left')
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Overview plot reveals missing power data for a number of nodes. Inspect one up close. Overview plot reveals missing power data for a number of nodes. Inspect one up close.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
m6_hourly_pwr['2020-02-01':'2021-02-21'].iloc[:,1:2].plot() m6_hourly_pwr['2020-02-01':'2021-02-21'].iloc[:,1:2].plot()
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Identify nodes that have missing data ## Identify nodes that have missing data
Identify nodes by ones that have NaN values over the past month. Identify nodes by ones that have NaN values over the past month.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
nan_mask = m6_hourly_pwr['2021-02-01':'2021-02-02'].isna() nan_mask = m6_hourly_pwr['2021-02-01':'2021-02-02'].isna()
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
power_missing = nan_mask[nan_mask].apply(lambda row: row[row == True].index, axis=1)[1] power_missing = nan_mask[nan_mask].apply(lambda row: row[row == True].index, axis=1)[1]
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
num_nodes=len(power_missing) num_nodes=len(power_missing)
fig, axes = plt.subplots(num_nodes,1, figsize=(20,30)) fig, axes = plt.subplots(num_nodes,1, sharex=True, figsize=(20,30))
for i, node in enumerate(power_missing): for i, node in enumerate(power_missing):
m6_hourly_pwr[node].plot(ax=axes[i], legend="left") m6_hourly_pwr[node].plot(ax=axes[i], legend=True)
axes[i].legend(loc='lower left')
```
%% Cell type:markdown id: tags:
## Plot all nodes power
Create overview plot of all nodes to observe meta-patterns.
%% Cell type:code id: tags:
```
num_nodes=len(m6_hourly_pwr.iloc[:,1:].columns)
fig, axes = plt.subplots(num_nodes,1, sharex=True, figsize=(20,num_nodes))
for i, node in enumerate(m6_hourly_pwr.iloc[:,1:].columns):
if (i == num_nodes):
break
m6_hourly_pwr[node]['2020-02-01':'2021-02-21'].plot(ax=axes[i], legend=True)
axes[i].legend(loc='lower left')
``` ```
%% 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':'2021-02-21'].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