<jupyter_start><jupyter_text>Example querying PrometheusPrometheus is queried using the http api.<jupyter_code>import time 
import requests
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
plt.style.use("seaborn")<jupyter_output><empty_output><jupyter_text>Prometheus url<jupyter_code>promsrv = "http://localhost:9090"<jupyter_output><empty_output><jupyter_text>Query and store the data into two numpy arrays (ib, ost)<jupyter_code># select time interval
stop = time.time()
start = stop - 60 * 15
#stop = 1530226822.0 + 120 
#start = stop - 200

# Query for psexport infiniband rate 
query = 'irate(node_infiniband_port_data_received_bytes{group="dtn", instance=~"psexport08.*"}[10s])'
payload = {'query': query,
           'start': int(start), 'end': int(stop), 'step': '5s'}
url = "{}/api/v1/query_range".format(promsrv)
r = requests.get(url, params=payload)

data = r.json()
point = data['data']['result'][0]
ib = np.array(point['values'], float).transpose()
ib[1] /= pow(2,20)

#Query OST zpool read rate of ana02, sum all osts 
query_zfs = 'sum(irate(node_zfs_zpool_nread{group="ana02"}[10s]))'
payload = {'query': query_zfs,
           'start': int(start), 'end': int(stop), 'step': '5s' }

url = "{}/api/v1/query_range".format(promsrv)
r = requests.get(url, params=payload)
data = r.json()
point = data['data']['result'][0]
ost = np.array(point['values'], float).transpose()
ost[1] /= pow(2,20)

#for point in res: 
#    #print(point['metric'])
#    #print("   ", point['values'])<jupyter_output><empty_output><jupyter_text>Plotting<jupyter_code>plt.scatter(ost[0], ost[1], marker='.', c='r', label="ost read")
plt.scatter(ib[0], ib[1], marker='+', c='g', label="ib read psexport")
plt.xlabel("unix time")
plt.ylabel("rate [MiB/s]")
plt.legend()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1847766133480419, 'fraction_numerical': 0.02923331494760066, 'mean_word_length': 6.314516129032258, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '393748', 'license': 'Apache-2.0', 'n_tokens_mistral': 735, 'n_tokens_neox': 696, 'n_words': 141, 'path': 'tools/prom/query_prom.ipynb', 'repo_name': 'slac-lcls/psdm-databooks', 'size': '1813'}