Skip to content

Commit 5a1b308

Browse files
schmikeiDasomeone
authored andcommitted
Update Varnish Mixin to use modern libraries (grafana#1480)
* update varnish mixin to use modern libraries * right side legends * apply PR feedback * make fmt --------- Co-authored-by: Emily <1282515+Dasomeone@users.noreply.github.com>
1 parent d734358 commit 5a1b308

21 files changed

+1840
-2247
lines changed

varnish-mixin/alerts/alerts.libsonnet renamed to varnish-mixin/alerts.libsonnet

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
2-
prometheusAlerts+:: {
3-
groups+: [
2+
new(this): {
3+
local config = this.config,
4+
5+
groups: [
46
{
57
name: 'varnish-cache',
68
rules: [
79
{
810
alert: 'VarnishCacheLowCacheHitRate',
911
expr: |||
10-
increase(varnish_main_cache_hit[10m]) / (clamp_min((increase(varnish_main_cache_hit[10m]) + increase(varnish_main_cache_miss[10m])), 1)) * 100 < %(alertsWarningCacheHitRate)s and (increase(varnish_main_cache_hit[10m]) + increase(varnish_main_cache_miss[10m]) > 0)
11-
||| % $._config,
12+
increase(varnish_main_cache_hit{%(filteringSelector)s}[10m]) / (clamp_min((increase(varnish_main_cache_hit{%(filteringSelector)s}[10m]) + increase(varnish_main_cache_miss{%(filteringSelector)s}[10m])), 1)) * 100 < %(alertsWarningCacheHitRate)s and (increase(varnish_main_cache_hit{%(filteringSelector)s}[10m]) + increase(varnish_main_cache_miss{%(filteringSelector)s}[10m]) > 0)
13+
||| % config,
1214
'for': '10m',
1315
labels: {
1416
severity: 'warning',
@@ -19,14 +21,14 @@
1921
(
2022
'The Cache hit rate is {{ printf "%%.0f" $value }} percent over the last 5 minutes on {{$labels.instance}}, ' +
2123
'which is below the threshold of %(alertsWarningCacheHitRate)s percent.'
22-
) % $._config,
24+
) % config,
2325
},
2426
},
2527
{
2628
alert: 'VarnishCacheHighMemoryUsage',
2729
expr: |||
28-
(varnish_sma_g_bytes{type="s0"} / (varnish_sma_g_bytes{type="s0"} + varnish_sma_g_space{type="s0"})) * 100 > %(alertsWarningHighMemoryUsage)s
29-
||| % $._config,
30+
(varnish_sma_g_bytes{%(filteringSelector)s,type="s0"} / (varnish_sma_g_bytes{%(filteringSelector)s,type="s0"} + varnish_sma_g_space{%(filteringSelector)s,type="s0"})) * 100 > %(alertsWarningHighMemoryUsage)s
31+
||| % config,
3032
'for': '5m',
3133
labels: {
3234
severity: 'warning',
@@ -37,14 +39,14 @@
3739
(
3840
'Current Memory Usage is {{ printf "%%.0f" $value }} percent on {{$labels.instance}}, ' +
3941
'which is above the threshold of %(alertsWarningHighMemoryUsage)s percent.'
40-
) % $._config,
42+
) % config,
4143
},
4244
},
4345
{
4446
alert: 'VarnishCacheHighCacheEvictionRate',
4547
expr: |||
46-
increase(varnish_main_n_lru_nuked[5m]) > %(alertsCriticalCacheEviction)s
47-
||| % $._config,
48+
increase(varnish_main_n_lru_nuked{%(filteringSelector)s}[5m]) > %(alertsCriticalCacheEviction)s
49+
||| % config,
4850
'for': '5m',
4951
labels: {
5052
severity: 'critical',
@@ -55,14 +57,14 @@
5557
(
5658
'The Cache has evicted {{ printf "%%.0f" $value }} objects over the last 5 minutes on {{$labels.instance}}, ' +
5759
'which is above the threshold of %(alertsCriticalCacheEviction)s.'
58-
) % $._config,
60+
) % config,
5961
},
6062
},
6163
{
6264
alert: 'VarnishCacheHighSaturation',
6365
expr: |||
64-
varnish_main_thread_queue_len > %(alertsWarningHighSaturation)s
65-
||| % $._config,
66+
varnish_main_thread_queue_len{%(filteringSelector)s} > %(alertsWarningHighSaturation)s
67+
||| % config,
6668
'for': '5m',
6769
labels: {
6870
severity: 'warning',
@@ -73,14 +75,14 @@
7375
(
7476
'The thread queue length is {{ printf "%%.0f" $value }} over the last 5 minutes on {{$labels.instance}}, ' +
7577
'which is above the threshold of %(alertsWarningHighSaturation)s.'
76-
) % $._config,
78+
) % config,
7779
},
7880
},
7981
{
8082
alert: 'VarnishCacheSessionsDropping',
8183
expr: |||
82-
increase(varnish_main_sessions{type="dropped"}[5m]) > %(alertsCriticalSessionsDropped)s
83-
||| % $._config,
84+
increase(varnish_main_sessions{%(filteringSelector)s,type="dropped"}[5m]) > %(alertsCriticalSessionsDropped)s
85+
||| % config,
8486
'for': '5m',
8587
labels: {
8688
severity: 'critical',
@@ -91,14 +93,14 @@
9193
(
9294
'The amount of sessions dropped is {{ printf "%%.0f" $value }} over the last 5 minutes on {{$labels.instance}}, ' +
9395
'which is above the threshold of %(alertsCriticalSessionsDropped)s.'
94-
) % $._config,
96+
) % config,
9597
},
9698
},
9799
{
98100
alert: 'VarnishCacheBackendUnhealthy',
99101
expr: |||
100-
increase(varnish_main_backend_unhealthy[5m]) > %(alertsCriticalBackendUnhealthy)s
101-
||| % $._config,
102+
increase(varnish_main_backend_unhealthy{%(filteringSelector)s}[5m]) > %(alertsCriticalBackendUnhealthy)s
103+
||| % config,
102104
'for': '5m',
103105
labels: {
104106
severity: 'critical',
@@ -109,7 +111,7 @@
109111
(
110112
'The amount of unhealthy backend statuses detected is {{ printf "%%.0f" $value }} over the last 5 minutes on {{$labels.instance}}, ' +
111113
'which is above the threshold of %(alertsCriticalBackendUnhealthy)s.'
112-
) % $._config,
114+
) % config,
113115
},
114116
},
115117
],

varnish-mixin/config.libsonnet

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,43 @@
11
{
2-
_config+:: {
3-
dashboardTags: ['varnish-cache-mixin'],
4-
dashboardPeriod: 'now-1h',
5-
dashboardTimezone: 'default',
6-
dashboardRefresh: '1m',
2+
local this = self,
3+
filteringSelector: 'job="integrations/varnish-cache"',
4+
groupLabels: ['job', 'cluster'],
5+
instanceLabels: ['instance'],
6+
dashboardTags: ['varnish-mixin'],
7+
uid: 'varnish',
8+
dashboardNamePrefix: 'Varnish',
79

8-
//alert thresholds
9-
alertsWarningCacheHitRate: 80, //%
10-
alertsWarningHighMemoryUsage: 90, //%
11-
alertsCriticalCacheEviction: 0,
12-
alertsWarningHighSaturation: 0,
13-
alertsCriticalSessionsDropped: 0,
14-
alertsCriticalBackendUnhealthy: 0,
15-
enableLokiLogs: true,
16-
enableMultiCluster: false,
17-
multiclusterSelector: 'job=~"$job"',
18-
varnishSelector: if self.enableMultiCluster then 'job=~"$job", cluster=~"$cluster"' else 'job=~"$job"',
10+
// additional params
11+
dashboardPeriod: 'now-1h',
12+
dashboardTimezone: 'default',
13+
dashboardRefresh: '1m',
14+
15+
// logs lib related
16+
enableLokiLogs: true,
17+
logLabels: ['job', 'instance', 'cluster', 'level'],
18+
extraLogLabels: [], // Required by logs-lib
19+
logsVolumeGroupBy: 'level',
20+
showLogsVolume: true,
21+
22+
// alert thresholds
23+
alertsWarningCacheHitRate: 80, //%
24+
alertsWarningHighMemoryUsage: 90, //%
25+
alertsCriticalCacheEviction: 0,
26+
alertsWarningHighSaturation: 0,
27+
alertsCriticalSessionsDropped: 0,
28+
alertsCriticalBackendUnhealthy: 0,
29+
30+
// metrics source for signals library
31+
metricsSource: 'prometheus',
32+
33+
legendCustomTemplate: std.join(' ', std.map(function(label) '{{' + label + '}}', this.instanceLabels)),
34+
signals+: {
35+
cache: (import './signals/cache.libsonnet')(this),
36+
requests: (import './signals/requests.libsonnet')(this),
37+
sessions: (import './signals/sessions.libsonnet')(this),
38+
memory: (import './signals/memory.libsonnet')(this),
39+
network: (import './signals/network.libsonnet')(this),
40+
threads: (import './signals/threads.libsonnet')(this),
41+
backend: (import './signals/backend.libsonnet')(this),
1942
},
2043
}

varnish-mixin/dashboards.libsonnet

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
local g = import './g.libsonnet';
2+
local logslib = import 'logs-lib/logs/main.libsonnet';
3+
{
4+
local root = self,
5+
new(this)::
6+
local prefix = this.config.dashboardNamePrefix;
7+
local links = this.grafana.links;
8+
local tags = this.config.dashboardTags;
9+
local uid = g.util.string.slugify(this.config.uid);
10+
local vars = this.grafana.variables;
11+
local annotations = this.grafana.annotations;
12+
local refresh = this.config.dashboardRefresh;
13+
local period = this.config.dashboardPeriod;
14+
local timezone = this.config.dashboardTimezone;
15+
16+
{
17+
'varnish-overview.json':
18+
g.dashboard.new(prefix + ' overview')
19+
+ g.dashboard.withPanels(
20+
g.util.panel.resolveCollapsedFlagOnRows(
21+
g.util.grid.wrapPanels(
22+
[
23+
this.grafana.rows.varnishStats,
24+
this.grafana.rows.varnishOverview,
25+
]
26+
)
27+
)
28+
)
29+
+ root.applyCommon(
30+
vars.multiInstance,
31+
uid + '_overview',
32+
tags,
33+
links { varnishOverview+:: {} },
34+
annotations,
35+
timezone,
36+
refresh,
37+
period
38+
),
39+
40+
}
41+
+
42+
if this.config.enableLokiLogs then
43+
{
44+
'varnish-logs.json':
45+
logslib.new(
46+
prefix + ' logs',
47+
datasourceName=this.grafana.variables.datasources.loki.name,
48+
datasourceRegex=this.grafana.variables.datasources.loki.regex,
49+
filterSelector=this.config.filteringSelector,
50+
labels=this.config.groupLabels + this.config.extraLogLabels,
51+
formatParser=null,
52+
showLogsVolume=this.config.showLogsVolume,
53+
)
54+
{
55+
dashboards+:
56+
{
57+
logs+:
58+
// reference to self, already generated variables, to keep them, but apply other common data in applyCommon
59+
root.applyCommon(super.logs.templating.list, uid=uid + '-logs', tags=tags, links=links { logs+:: {} }, annotations=annotations, timezone=timezone, refresh=refresh, period=period),
60+
},
61+
panels+:
62+
{
63+
// modify log panel
64+
logs+:
65+
g.panel.logs.options.withEnableLogDetails(true)
66+
+ g.panel.logs.options.withShowTime(false)
67+
+ g.panel.logs.options.withWrapLogMessage(false),
68+
},
69+
variables+: {
70+
// add prometheus datasource for annotations processing
71+
toArray+: [
72+
this.grafana.variables.datasources.prometheus { hide: 2 },
73+
],
74+
},
75+
}.dashboards.logs,
76+
}
77+
else {},
78+
79+
applyCommon(vars, uid, tags, links, annotations, timezone, refresh, period):
80+
g.dashboard.withTags(tags)
81+
+ g.dashboard.withUid(uid)
82+
+ g.dashboard.withLinks(std.objectValues(links))
83+
+ g.dashboard.withTimezone(timezone)
84+
+ g.dashboard.withRefresh(refresh)
85+
+ g.dashboard.time.withFrom(period)
86+
+ g.dashboard.withVariables(vars)
87+
+ g.dashboard.withAnnotations(std.objectValues(annotations)),
88+
}

0 commit comments

Comments
 (0)