gc panel: use for loop to add prometheus targets

Grafonnet doesn't yet provide addSeriesOverrides() accepting an array.
Also use a different color for each gc so that switching to another
gc shows up in the graph.

Change-Id: I4e424280d44a63f57ad7196dfdb7e77ba2f13f24
This commit is contained in:
Matthias Sohn 2021-02-06 00:29:02 +01:00
parent c6a7a985cd
commit 73d4326206

View file

@ -4,6 +4,39 @@ local prometheus = grafana.prometheus;
local barGraph = import '../../../globals/bar-graph.libsonnet';
local yAxis = import '../../../globals/yaxis.libsonnet';
local METRICS = [
{
name: 'G1_Young_Generation',
label: 'gc time G1 young gen',
color: '#3274D9',
},
{
name: 'G1_Old_Generation',
label: 'gc time G1 old gen',
color: '#F2CC0C',
},
{
name: 'PS_Scavenge',
label: 'gc time PS Scavange',
color: '#8AB8FF',
},
{
name: 'PS_MarkSweep',
label: 'gc time PS MarkSweep',
color: '#E02F44',
},
{
name: 'ZGC',
label: 'gc time ZGC',
color: '#95F0CF',
},
{
name: 'ShenandoahGC',
label: 'gc time ShenandoahGC',
color: '#B4D61A',
},
];
barGraph.new(
title='Java - % of time spent in GC',
yAxis1=yAxis.new(
@ -11,81 +44,47 @@ barGraph.new(
format='percentunit',
),
)
.addTarget(
.addTargets([
prometheus.target(
'increase(proc_jvm_gc_time_G1_Young_Generation{instance="$instance",replica="$replica"}[2m])/increase(proc_uptime{instance="$instance",replica="$replica"}[2m])',
legendFormat='gc time G1 young gen',
std.format('increase(proc_jvm_gc_time_%s{instance="$instance",replica="$replica"}[2m])/increase(proc_uptime{instance="$instance",replica="$replica"}[2m])', METRICS[i]['name']),
legendFormat=METRICS[i]['label'],
interval='1m',
)
)
.addTarget(
prometheus.target(
'increase(proc_jvm_gc_time_G1_Old_Generation{instance="$instance",replica="$replica"}[2m])/increase(proc_uptime{instance="$instance",replica="$replica"}[2m])',
legendFormat='gc time G1 old gen',
interval='1m',
)
)
.addTarget(
prometheus.target(
'increase(proc_jvm_gc_time_PS_MarkSweep{instance="$instance",replica="$replica"}[2m])/increase(proc_uptime{instance="$instance",replica="$replica"}[2m])',
legendFormat='gc time PS MarkSweep',
interval='1m',
)
)
.addTarget(
prometheus.target(
'increase(proc_jvm_gc_time_PS_Scavenge{instance="$instance",replica="$replica"}[2m])/increase(proc_uptime{instance="$instance",replica="$replica"}[2m])',
legendFormat='gc time PS Scavange',
interval='1m',
)
)
.addTarget(
prometheus.target(
'increase(proc_jvm_gc_time_ZGC{instance="$instance",replica="$replica"}[2m])/increase(proc_uptime{instance="$instance",replica="$replica"}[2m])',
legendFormat='gc time ZGC',
interval='1m',
)
)
.addTarget(
prometheus.target(
'increase(proc_jvm_gc_time_ShenandoahGC{instance="$instance",replica="$replica"}[2m])/increase(proc_uptime{instance="$instance",replica="$replica"}[2m])',
legendFormat='gc time ShenandoahGC',
interval='1m',
)
)
for i in std.range(0, std.length(METRICS) - 1)
])
.addSeriesOverride(
{
alias: 'gc time G1 old gen',
color: '#F2CC0C',
alias: METRICS[0]['label'],
color: METRICS[0]['color'],
}
)
.addSeriesOverride(
{
alias: 'gc time G1 young gen',
color: '#3274D9',
alias: METRICS[1]['label'],
color: METRICS[1]['color'],
}
)
.addSeriesOverride(
{
alias: 'gc time PS Scavange',
color: '#8AB8FF',
alias: METRICS[2]['label'],
color: METRICS[2]['color'],
}
)
.addSeriesOverride(
{
alias: 'gc time PS MarkSweep',
color: '#E02F44',
alias: METRICS[3]['label'],
color: METRICS[3]['color'],
}
)
.addSeriesOverride(
{
alias: 'gc time ZGC',
color: '#3274D9',
alias: METRICS[4]['label'],
color: METRICS[4]['color'],
}
)
.addSeriesOverride(
{
alias: 'gc time ShenandoahGC',
color: '#3274D9',
alias: METRICS[5]['label'],
color: METRICS[5]['color'],
}
)