Skip to content

Commit

Permalink
metrics_aggs: print max avg stats
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy committed Aug 23, 2024
1 parent c95cb91 commit ca25a1a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions test/heapwatch/metrics_aggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from plotly.subplots import make_subplots


from metrics_lib import MetricType, parse_metrics, gather_metrics_files_by_nick
from metrics_lib import Metric, MetricType, parse_metrics, gather_metrics_files_by_nick

logger = logging.getLogger(__name__)

Expand All @@ -53,6 +53,7 @@ def main():
ap.add_argument('--nick-lre', action='append', default=[], help='label:regexp to filter node names, may be repeated')
ap.add_argument('-s', '--save', type=str, choices=['png', 'html'], help=f'save plot to \'{default_img_filename}\' or \'{default_html_filename}\' file instead of showing it')
ap.add_argument('--verbose', default=False, action='store_true')
ap.add_argument('--avg-max', default=False, action='store_true', help='print avg and max values across nodes for each metric')

args = ap.parse_args()
if args.verbose:
Expand Down Expand Up @@ -99,6 +100,7 @@ def main():
}
fig['layout']['height'] = 500 * nrows

nick_series = {}

for nick, files_by_date in filesByNick.items():
active_metrics = {}
Expand Down Expand Up @@ -146,7 +148,10 @@ def main():
active_metric_names.sort()
active_metrics[full_name] = active_metric_names
idx += 1


if args.avg_max:
nick_series[nick] = raw_series

for i, metric_pair in enumerate(sorted(active_metrics.items())):
metric_name, metric_fullnames = metric_pair
for metric_fullname in metric_fullnames:
Expand All @@ -158,6 +163,19 @@ def main():
line=dict(width=1),
), i+1, 1)

if args.avg_max:
metric_names_nick_max_avg = {}
for nick, raw_series in nick_series.items():
for metric_name, rw in raw_series.items():
mmax = max(rw)
print(f'{nick}: {metric_name}: count {len(rw)}, max {mmax}, min {min(rw)}')
metric = Metric(metric_name, mmax, MetricType.COUNTER)
if metric.short_name() not in metric_names_nick_max_avg:
metric_names_nick_max_avg[metric.short_name()] = []
metric_names_nick_max_avg[metric.short_name()].append(mmax)
for metric_name, maxs in metric_names_nick_max_avg.items():
print(f'{metric_name}: max {max(maxs)}, avg {sum(maxs)/len(maxs)}')

if args.save:
if args.save == 'html':
target_path = os.path.join(args.dir, default_html_filename)
Expand Down

0 comments on commit ca25a1a

Please sign in to comment.