Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 0cdcec8

Browse files
authored
Merge pull request #64 from grafana/add-resources-dashboards
Added 'Writes Resources' and 'Reads Resources' dashboards
2 parents 9353589 + 9b9aee2 commit 0cdcec8

File tree

5 files changed

+169
-0
lines changed

5 files changed

+169
-0
lines changed

cortex-mixin/config.libsonnet

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@
2525

2626
cortex_p99_latency_threshold_seconds: 2.5,
2727
alert_namespace_matcher: '',
28+
29+
// Whether resources dashboards are enabled (based on cAdvisor metrics).
30+
resources_dashboards_enabled: false,
2831
},
2932
}

cortex-mixin/dashboards.libsonnet

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@
1919
then import 'dashboards/comparison.libsonnet'
2020
else {}) +
2121

22+
(if !$._config.resources_dashboards_enabled then {} else
23+
(import 'dashboards/reads-resources.libsonnet') +
24+
(import 'dashboards/writes-resources.libsonnet')) +
25+
2226
{ _config:: $._config },
2327
}

cortex-mixin/dashboards/dashboard-utils.libsonnet

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,44 @@ local utils = import 'mixin-utils/utils.libsonnet';
107107
},
108108
},
109109

110+
containerCPUUsagePanel(title, containerName)::
111+
$.panel(title) +
112+
$.queryPanel([
113+
'sum by(pod_name) (rate(container_cpu_usage_seconds_total{%s,container_name="%s"}[$__interval]))' % [$.namespaceMatcher(), containerName],
114+
'min(container_spec_cpu_quota{%s,container_name="%s"} / container_spec_cpu_period{%s,container_name="%s"})' % [$.namespaceMatcher(), containerName, $.namespaceMatcher(), containerName],
115+
], ['{{pod_name}}', 'limit']) +
116+
{
117+
seriesOverrides: [
118+
{
119+
alias: 'limit',
120+
color: '#E02F44',
121+
fill: 0,
122+
},
123+
],
124+
},
125+
126+
containerMemoryWorkingSetPanel(title, containerName)::
127+
$.panel(title) +
128+
$.queryPanel([
129+
'sum by(pod_name) (container_memory_working_set_bytes{%s,container_name="%s"})' % [$.namespaceMatcher(), containerName],
130+
'min(container_spec_memory_limit_bytes{%s,container_name="%s"} > 0)' % [$.namespaceMatcher(), containerName],
131+
], ['{{pod_name}}', 'limit']) +
132+
{
133+
seriesOverrides: [
134+
{
135+
alias: 'limit',
136+
color: '#E02F44',
137+
fill: 0,
138+
},
139+
],
140+
yaxes: $.yaxes('bytes'),
141+
},
142+
143+
goHeapInUsePanel(title, jobName)::
144+
$.panel(title) +
145+
$.queryPanel('sum by(instance) (go_memstats_heap_inuse_bytes{%s})' % $.jobMatcher(jobName), '{{instance}}') +
146+
{ yaxes: $.yaxes('bytes') },
147+
110148
// Switches a panel from lines (default) to bars.
111149
bars:: {
112150
bars: true,
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
local utils = import 'mixin-utils/utils.libsonnet';
2+
3+
(import 'dashboard-utils.libsonnet') {
4+
'cortex-reads-resources.json':
5+
$.dashboard('Cortex / Reads Resources')
6+
.addClusterSelectorTemplates()
7+
.addRow(
8+
$.row('Gateway')
9+
.addPanel(
10+
$.containerCPUUsagePanel('CPU', 'cortex-gw'),
11+
)
12+
.addPanel(
13+
$.containerMemoryWorkingSetPanel('Memory (workingset)', 'cortex-gw'),
14+
)
15+
.addPanel(
16+
$.goHeapInUsePanel('Memory (go heap inuse)', 'cortex-gw'),
17+
)
18+
)
19+
.addRow(
20+
$.row('Query Frontend')
21+
.addPanel(
22+
$.containerCPUUsagePanel('CPU', 'query-frontend'),
23+
)
24+
.addPanel(
25+
$.containerMemoryWorkingSetPanel('Memory (workingset)', 'query-frontend'),
26+
)
27+
.addPanel(
28+
$.goHeapInUsePanel('Memory (go heap inuse)', 'query-frontend'),
29+
)
30+
)
31+
.addRow(
32+
$.row('Querier')
33+
.addPanel(
34+
$.containerCPUUsagePanel('CPU', 'querier'),
35+
)
36+
.addPanel(
37+
$.containerMemoryWorkingSetPanel('Memory (workingset)', 'querier'),
38+
)
39+
.addPanel(
40+
$.goHeapInUsePanel('Memory (go heap inuse)', 'querier'),
41+
)
42+
)
43+
.addRowIf(
44+
std.setMember('tsdb', $._config.storage_engine),
45+
$.row('Store-gateway')
46+
.addPanel(
47+
$.containerCPUUsagePanel('CPU', 'store-gateway'),
48+
)
49+
.addPanel(
50+
$.containerMemoryWorkingSetPanel('Memory (workingset)', 'store-gateway'),
51+
)
52+
.addPanel(
53+
$.goHeapInUsePanel('Memory (go heap inuse)', 'store-gateway'),
54+
)
55+
) + {
56+
templating+: {
57+
list: [
58+
// Do not allow to include all clusters/namespaces otherwise this dashboard
59+
// risks to explode because it shows resources per pod.
60+
l + (if (l.name == 'cluster' || l.name == 'namespace') then { includeAll: false } else {})
61+
for l in super.list
62+
],
63+
},
64+
},
65+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
local utils = import 'mixin-utils/utils.libsonnet';
2+
3+
(import 'dashboard-utils.libsonnet') {
4+
'cortex-writes-resources.json':
5+
$.dashboard('Cortex / Writes Resources')
6+
.addClusterSelectorTemplates()
7+
.addRow(
8+
$.row('Gateway')
9+
.addPanel(
10+
$.containerCPUUsagePanel('CPU', 'cortex-gw'),
11+
)
12+
.addPanel(
13+
$.containerMemoryWorkingSetPanel('Memory (workingset)', 'cortex-gw'),
14+
)
15+
.addPanel(
16+
$.goHeapInUsePanel('Memory (go heap inuse)', 'cortex-gw'),
17+
)
18+
)
19+
.addRow(
20+
$.row('Distributor')
21+
.addPanel(
22+
$.containerCPUUsagePanel('CPU', 'distributor'),
23+
)
24+
.addPanel(
25+
$.containerMemoryWorkingSetPanel('Memory (workingset)', 'distributor'),
26+
)
27+
.addPanel(
28+
$.goHeapInUsePanel('Memory (go heap inuse)', 'distributor'),
29+
)
30+
)
31+
.addRow(
32+
$.row('Ingester')
33+
.addPanel(
34+
$.panel('In-memory series') +
35+
$.queryPanel('sum by(instance) (cortex_ingester_memory_series{%s})' % $.jobMatcher('ingester'), '{{instance}}'),
36+
)
37+
.addPanel(
38+
$.containerCPUUsagePanel('CPU', 'ingester'),
39+
)
40+
)
41+
.addRow(
42+
$.row('')
43+
.addPanel(
44+
$.containerMemoryWorkingSetPanel('Memory (workingset)', 'ingester'),
45+
)
46+
.addPanel(
47+
$.goHeapInUsePanel('Memory (go heap inuse)', 'ingester'),
48+
)
49+
) + {
50+
templating+: {
51+
list: [
52+
// Do not allow to include all clusters/namespaces otherwise this dashboard
53+
// risks to explode because it shows resources per pod.
54+
l + (if (l.name == 'cluster' || l.name == 'namespace') then { includeAll: false } else {})
55+
for l in super.list
56+
],
57+
},
58+
},
59+
}

0 commit comments

Comments
 (0)