github.com/badrootd/nibiru-cometbft@v0.37.5-0.20240307173500-2a75559eee9b/scripts/qa/reporting/prometheus_plotter.py (about) 1 # pip install numpy pandas matplotlib requests 2 3 import sys 4 import os 5 6 import matplotlib as mpl 7 import matplotlib.pyplot as plt 8 9 import numpy as np 10 import pandas as pd 11 12 import requests 13 from urllib.parse import urljoin 14 15 from prometheus_pandas import query 16 17 release = 'v0.37.x-alpha3' 18 path = os.path.join('imgs') 19 prometheus = query.Prometheus('http://localhost:9090') 20 21 # Time window 22 #window_size = dict(seconds=150) #CMT 0.37.x-alpha3 23 window_size = dict(seconds=126) #TM v0.37 (200 nodes) baseline 24 #window_size = dict(seconds=130) #homogeneous 25 #window_size = dict(seconds=127) #baseline 26 ext_window_size = dict(seconds=180) 27 28 # Use the time provided by latency_plotter for the selected experiment. 29 #left_end = '2023-02-08T13:12:20Z' #cmt2 tm1 30 #left_end = '2023-02-08T10:31:50Z' #cmt1 tm2 31 #left_end = '2023-02-14T15:18:00Z' #cmt1 tm1 32 #left_end = '2023-02-07T18:07:00Z' #homogeneous 33 #left_end = '2022-10-13T19:41:23Z' #baseline 34 #left_end = '2023-02-22T18:56:29Z' #CMT 0.37.x-alpha3 35 left_end = '2022-10-13T15:57:50Z' #TM v0.37 (200 nodes) baseline 36 37 right_end = pd.to_datetime(left_end) + pd.Timedelta(**window_size) 38 time_window = (left_end, right_end.strftime('%Y-%m-%dT%H:%M:%SZ')) 39 40 ext_right_end = pd.to_datetime(left_end) + pd.Timedelta(**ext_window_size) 41 ext_time_window = (left_end, ext_right_end.strftime('%Y-%m-%dT%H:%M:%SZ')) 42 43 44 45 #fork='cometbft' 46 fork='tendermint' 47 48 # Do prometheus queries 49 queries = [ 50 (( fork + '_mempool_size', time_window[0], time_window[1], '1s'), 'mempool_size', dict(ylabel='TXs', xlabel='time (s)', title='Mempool Size', legend=False, figsize=(10,6), grid=True, kind='area',stacked=True), False), 51 (( fork + '_p2p_peers', time_window[0], time_window[1], '1s'), 'peers', dict(ylabel='# Peers', xlabel='time (s)', title='Peers', legend=False, figsize=(10,6), grid=True), True), 52 (( 'avg(' + fork + '_mempool_size)', time_window[0], time_window[1], '1s'), 'avg_mempool_size', dict(ylabel='TXs', xlabel='time (s)', title='Average Mempool Size', legend=False, figsize=(10,6), grid=True), False), 53 #(( 'cometbft_consensus_height', time_window[0], time_window[1], '1s'), 'blocks_regular', dict(ylabel='# Blocks', xlabel='time (s)', title='Blocks in time', legend=False, figsize=(10,6), grid=True), False), 54 (( fork + '_consensus_rounds', time_window[0], time_window[1], '1s'), 'rounds', dict(ylabel='# Rounds', xlabel='time (s)', title='Rounds per block', legend=False, figsize=(10,6), grid=True), False), 55 (( 'rate(' + fork + '_consensus_height[20s])*60', time_window[0], time_window[1], '1s'), 'block_rate_regular', dict(ylabel='Blocks/min', xlabel='time (s)', title='Rate of block creation', legend=False, figsize=(10,6), grid=True), True), 56 #(( 'avg(rate(cometbft_consensus_height[20s])*60)', time_window[0], time_window[1], '1s'), 'block_rate_avg_reg', dict(ylabel='Blocks/min', xlabel='time (s)', title='Rate of block creation', legend=False, figsize=(10,6), grid=True), False), 57 #(( 'cometbft_consensus_total_txs', time_window[0], time_window[1], '1s'), 'total_txs_regular', dict(ylabel='# TXs', xlabel='time (s)', title='Transactions in time', legend=False, figsize=(10,6), grid=True), False), 58 (( 'rate(' + fork + '_consensus_total_txs[20s])*60', time_window[0], time_window[1], '1s'), 'total_txs_rate_regular', dict(ylabel='TXs/min', xlabel='time (s)', title='Rate of transaction processing', legend=False, figsize=(10,6), grid=True), True), 59 #(( 'avg(rate(cometbft_consensus_total_txs[20s])*60)', time_window[0], time_window[1], '1s'), 'total_txs_rate_avg_reg', dict(ylabel='TXs/min', xlabel='time (s)', title='Rate of transaction processing', legend=False, figsize=(10,6), grid=True), False), 60 (( 'process_resident_memory_bytes', time_window[0], time_window[1], '1s'), 'memory', dict(ylabel='Memory (bytes)', xlabel='time (s)', title='Memory usage', legend=False, figsize=(10,6), grid=True), False), 61 (( 'avg(process_resident_memory_bytes)', time_window[0], time_window[1], '1s'), 'avg_memory', dict(ylabel='Memory (bytes)', xlabel='time (s)', title='Average Memory usage', legend=False, figsize=(10,6), grid=True), False), 62 (( 'node_load1', time_window[0], time_window[1], '1s'), 'cpu', dict(ylabel='Load', xlabel='time (s)', title='Node load', legend=False, figsize=(10,6), grid=True), False), 63 (( 'avg(node_load1)', time_window[0], time_window[1], '1s'), 'avg_cpu', dict(ylabel='Load', xlabel='time (s)', title='Average Node load', legend=False, figsize=(10,6), grid=True), False), 64 #extended window metrics 65 (( fork + '_consensus_height', ext_time_window[0], ext_time_window[1], '1s'), 'blocks', dict(ylabel='# Blocks', xlabel='time (s)', title='Blocks in time', legend=False, figsize=(10,6), grid=True), False), 66 (( 'rate(' + fork + '_consensus_height[20s])*60', ext_time_window[0], ext_time_window[1], '1s'), 'block_rate', dict(ylabel='Blocks/min', xlabel='time (s)', title='Rate of block creation', legend=False, figsize=(10,6), grid=True), True), 67 (( fork + '_consensus_total_txs', ext_time_window[0], ext_time_window[1], '1s'), 'total_txs', dict(ylabel='# TXs', xlabel='time (s)', title='Transactions in time', legend=False, figsize=(10,6), grid=True), False), 68 (( 'rate(' + fork + '_consensus_total_txs[20s])*60', ext_time_window[0], ext_time_window[1], '1s'), 'total_txs_rate', dict(ylabel='TXs/min', xlabel='time (s)', title='Rate of transaction processing', legend=False, figsize=(10,6), grid=True), True), 69 ] 70 71 for (query, file_name, pandas_params, plot_average) in queries: 72 print(query) 73 74 data_frame = prometheus.query_range(*query) 75 #Tweak the x ticks 76 delta_index = pd.to_timedelta(data_frame.index.strftime('%H:%M:%S')) 77 data_frame = data_frame.set_index(delta_index) 78 79 data_frame.plot(**pandas_params) 80 if plot_average: 81 average = data_frame.mean(axis=1) 82 data_frame['__average__'] = average 83 pandas_params['lw'] = 8 84 pandas_params['style'] = ['--'] 85 pandas_params['color'] = ['red'] 86 data_frame['__average__'].plot(**pandas_params) 87 88 plt.savefig(os.path.join(path, file_name + '.png')) 89 plt.plot() 90 91 plt.show()