In this notebook we will use the netdata-pandas Python package to pull some data from some demo Netdata servers and make some pretty looking correlation heatmaps, because we all love a good heatmap don't we.
Note: you can click the "Open in Colab" button above to open this notebook in Google Colab where you can just get going with it without having to set up python enviornments or any messy stuff like that.
# if you need to, uncomment below to install netdata-pandas and seaborn packages
#!pip install seaborn==0.11.0 netdata-pandas==0.0.27
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from netdata_pandas.data import get_data
Lets pull the data from three demo nodes for a subset of charts for the last 15 minutes.
# inputs
hosts = ['london.my-netdata.io', 'cdn77.my-netdata.io', 'octopuscs.my-netdata.io']
charts = ['system.cpu', 'system.load', 'system.io', 'system.ram', 'system.net', 'system.ip', 'system.processes', 'system.intr', 'system.softnet_stat']
before = 0
after = -60*15
# get the data
df = get_data(hosts=hosts, charts=charts, after=after, before=before)
print(df.shape)
df.head()
(2700, 30)
system.cpu|guest | system.cpu|guest_nice | system.cpu|iowait | system.cpu|irq | system.cpu|nice | system.cpu|softirq | system.cpu|steal | system.cpu|system | system.cpu|user | system.intr|interrupts | ... | system.processes|running | system.ram|buffers | system.ram|cached | system.ram|free | system.ram|used | system.softnet_stat|dropped | system.softnet_stat|flow_limit_count | system.softnet_stat|processed | system.softnet_stat|received_rps | system.softnet_stat|squeezed | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
host | time_idx | |||||||||||||||||||||
cdn77.my-netdata.io | 1603460665 | 0.0 | 0.0 | 32.82828 | 0.0 | 0.0 | 0.0 | 0.0 | 2.020202 | 0.505050 | 339.1384 | ... | 2.0 | 244.9961 | 2650.066 | 392.9688 | 677.4180 | 0.0 | 0.0 | 185.18660 | 0.0 | 0.0 |
1603460666 | 0.0 | 0.0 | 0.00000 | 0.0 | 0.0 | 0.0 | 0.0 | 1.507538 | 2.010050 | 366.6814 | ... | 4.0 | 244.9961 | 2650.066 | 389.1836 | 681.2031 | 0.0 | 0.0 | 212.22230 | 0.0 | 0.0 | |
1603460667 | 0.0 | 0.0 | 0.00000 | 0.0 | 0.0 | 0.0 | 0.0 | 1.515151 | 0.505050 | 334.6279 | ... | 1.0 | 244.9961 | 2650.070 | 389.2617 | 681.1211 | 0.0 | 0.0 | 192.34850 | 0.0 | 0.0 | |
1603460668 | 0.0 | 0.0 | 0.00000 | 0.0 | 0.0 | 0.0 | 0.0 | 1.015228 | 0.507614 | 307.5347 | ... | 1.0 | 244.9961 | 2650.070 | 389.2305 | 681.1523 | 0.0 | 0.0 | 163.72629 | 0.0 | 0.0 | |
1603460669 | 0.0 | 0.0 | 0.00000 | 0.0 | 0.0 | 0.0 | 0.0 | 2.000000 | 1.000000 | 324.9979 | ... | 4.0 | 244.9961 | 2650.066 | 388.8750 | 681.5117 | 0.0 | 0.0 | 186.40330 | 0.0 | 0.0 |
5 rows × 30 columns
Lets just loop over our dataframe for each host and make our heatmap.
# set some plotting options
sns.set_theme(style="white")
cmap = sns.diverging_palette(230, 20, as_cmap=True)
for host in df.index.unique(0):
corr = df.loc[host].corr()
mask = np.triu(np.ones_like(corr, dtype=bool))
f, ax = plt.subplots(figsize=(11, 9))
sns.heatmap(
corr, mask=mask, cmap=cmap, vmax=.3, center=0,
square=True, linewidths=.5, cbar_kws={"shrink": .5}).set_title(f'{host} Correlation Heatmap')