Prometheus告警大屏

前言

众所周知,prometheus结合alertmanager可将告警信息通过邮件、短信、微信、webhook或者其他方式通知到运维人员,大部分监控系统也都是采用这种告警通知方式。

这里介绍另外一种告警通知方式——告警大屏,对于有24*7值班人员的企业,这种方式反而更实用。

在办公室显眼的地方放一个显示器,显示告警大屏。值班人员实时关注告警大屏,发生故障时再第一时间通知到运维人员处理。

部署

假设已经部署好prometheusalertmanager以及grafana环境。

Prometheus的告警规则

Prometheus的告警规则里,需要定义告警级别标签。

如下系统负载超标定义为普通警告(severity: warning),根分区使用率大于90%为严重警告(severity: critical)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
- name: system_load.rules
rules:
- alert: 系统负载超标
expr: node_load1/count without (cpu, mode) (node_cpu_seconds_total{mode="system"})>1.1
for: 2m
labels:
severity: warning
annotations:
summary: 系统负载超标
description: '{{$labels.instance}} 当前负载超标率 {{printf "%.2f" $value}}'

- name: partion_used.rules
rules:
- alert: 分区使用率大于90%
expr: ceil(100 - ((node_filesystem_avail_bytes{fstype != "rootfs"} * 100) / node_filesystem_size_bytes{fstype != "rootfs"}))>90
for: 1m
labels:
severity: critical
annotations:
summary: "{{$labels.mountpoint}} 分区空间紧张"
description: "{{$labels.instance}} {{$labels.mountpoint}}分区空间使用率 {{$value}}%"

grafana安装prometheus-alertmanager-datasource插件

1
grafana-cli plugins install camptocamp-prometheus-alertmanager-datasource

添加Prometheus AlertManager数据源

登录grafanaConfiguration->Data sources->Add data srouces,选择Prometheus AlertManager,输入alermanager的地址

1576562623402

1576567699221

创建告警大屏

这里我已经配置好,直接导入如下json即可。当然也可以根据自己的需求自定义。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"description": "Monitor and set alerts for all the pings to your servers using blackbox exporter and prometheus.",
"editable": true,
"gnetId": 5990,
"graphTooltip": 0,
"id": 16,
"links": [],
"panels": [
{
"collapsed": false,
"datasource": null,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 0
},
"id": 27,
"panels": [],
"title": "告警记录",
"type": "row"
},
{
"cacheTimeout": null,
"colorBackground": true,
"colorValue": false,
"colors": [
"#299c46",
"rgba(237, 129, 40, 0.89)",
"rgba(237, 129, 40, 0.89)"
],
"datasource": "Prometheus AlertManager",
"format": "none",
"gauge": {
"maxValue": 100,
"minValue": 0,
"show": false,
"thresholdLabels": false,
"thresholdMarkers": true
},
"gridPos": {
"h": 3,
"w": 3,
"x": 0,
"y": 1
},
"id": 19,
"interval": null,
"links": [],
"mappingType": 1,
"mappingTypes": [
{
"name": "value to text",
"value": 1
},
{
"name": "range to text",
"value": 2
}
],
"maxDataPoints": 100,
"nullPointMode": "connected",
"nullText": null,
"options": {},
"postfix": "",
"postfixFontSize": "50%",
"prefix": "",
"prefixFontSize": "50%",
"rangeMaps": [
{
"from": "null",
"text": "N/A",
"to": "null"
}
],
"sparkline": {
"fillColor": "rgba(31, 118, 189, 0.18)",
"full": false,
"lineColor": "rgb(31, 120, 193)",
"show": false
},
"tableColumn": "",
"targets": [
{
"annotations": false,
"expr": "severity=warning",
"format": "time_series",
"intervalFactor": 1,
"labelSelector": "*",
"legendFormat": "",
"refId": "A",
"target": "Query",
"type": "timeserie"
}
],
"thresholds": "0.1,0.9",
"title": "警告",
"type": "singlestat",
"valueFontSize": "170%",
"valueMaps": [],
"valueName": "avg"
},
{
"cacheTimeout": null,
"colorBackground": true,
"colorValue": false,
"colors": [
"#299c46",
"rgba(237, 129, 40, 0.89)",
"#C4162A"
],
"datasource": "Prometheus AlertManager",
"format": "none",
"gauge": {
"maxValue": 100,
"minValue": 0,
"show": false,
"thresholdLabels": false,
"thresholdMarkers": true
},
"gridPos": {
"h": 3,
"w": 3,
"x": 3,
"y": 1
},
"id": 30,
"interval": null,
"links": [],
"mappingType": 1,
"mappingTypes": [
{
"name": "value to text",
"value": 1
},
{
"name": "range to text",
"value": 2
}
],
"maxDataPoints": 100,
"nullPointMode": "connected",
"nullText": null,
"options": {},
"postfix": "",
"postfixFontSize": "50%",
"prefix": "",
"prefixFontSize": "50%",
"rangeMaps": [
{
"from": "null",
"text": "N/A",
"to": "null"
}
],
"sparkline": {
"fillColor": "rgba(31, 118, 189, 0.18)",
"full": false,
"lineColor": "rgb(31, 120, 193)",
"show": false
},
"tableColumn": "",
"targets": [
{
"annotations": false,
"expr": "severity=critical",
"format": "time_series",
"intervalFactor": 1,
"labelSelector": "*",
"legendFormat": "",
"refId": "A",
"target": "Query",
"type": "timeserie"
}
],
"thresholds": "0.1,0.9",
"title": "严重",
"type": "singlestat",
"valueFontSize": "170%",
"valueMaps": [],
"valueName": "avg"
},
{
"columns": [],
"datasource": "Prometheus AlertManager",
"fontSize": "100%",
"gridPos": {
"h": 11,
"w": 24,
"x": 0,
"y": 4
},
"id": 16,
"links": [],
"options": {},
"pageSize": null,
"scroll": true,
"showHeader": true,
"sort": {
"col": 6,
"desc": true
},
"styles": [
{
"alias": "告警时间",
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"pattern": "Time",
"type": "date"
},
{
"alias": "告警名称",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 2,
"mappingType": 1,
"pattern": "alertname",
"thresholds": [],
"type": "string",
"unit": "short"
},
{
"alias": "机房",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 2,
"mappingType": 1,
"pattern": "dc",
"thresholds": [],
"type": "string",
"unit": "short",
"valueMaps": []
},
{
"alias": "告警类型",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 2,
"mappingType": 1,
"pattern": "job",
"thresholds": [],
"type": "string",
"unit": "short"
},
{
"alias": "告警明细",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 2,
"mappingType": 1,
"pattern": "description",
"thresholds": [],
"type": "string",
"unit": "short"
},
{
"alias": "告警概要",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 2,
"mappingType": 1,
"pattern": "summary",
"thresholds": [],
"type": "hidden",
"unit": "short"
},
{
"alias": "级别",
"colorMode": "row",
"colors": [
"rgba(50, 172, 45, 0.97)",
"rgba(237, 129, 40, 0.89)",
"rgba(245, 54, 54, 0.9)"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 2,
"mappingType": 1,
"pattern": "severity",
"thresholds": [
"1",
"3"
],
"type": "string",
"unit": "short",
"valueMaps": [
{
"text": "警告",
"value": "2"
},
{
"text": "严重",
"value": "4"
}
]
},
{
"alias": "",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 2,
"mappingType": 1,
"pattern": "target",
"thresholds": [],
"type": "hidden",
"unit": "short"
},
{
"alias": "实例",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 2,
"mappingType": 1,
"pattern": "instance",
"thresholds": [],
"type": "string",
"unit": "short"
},
{
"alias": "",
"colorMode": "row",
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"decimals": 2,
"pattern": "/.*/",
"thresholds": [
""
],
"type": "hidden",
"unit": "short"
}
],
"targets": [
{
"annotations": false,
"expr": "",
"format": "table",
"intervalFactor": 1,
"labelSelector": "time,dc,instance,alertname,description",
"legendFormat": "",
"refId": "A",
"target": "Query",
"type": "table"
}
],
"title": "实时告警列表",
"transform": "table",
"type": "table"
},
{
"collapsed": true,
"datasource": null,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 15
},
"id": 29,
"panels": [
{
"columns": [],
"datasource": "Prometheus",
"fontSize": "100%",
"gridPos": {
"h": 9,
"w": 24,
"x": 0,
"y": 14
},
"id": 25,
"links": [],
"options": {},
"pageSize": 1000,
"scroll": true,
"showHeader": true,
"sort": {
"col": 0,
"desc": true
},
"styles": [
{
"alias": "告警时间",
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"pattern": "Time",
"type": "date"
},
{
"alias": "告警名称",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 2,
"mappingType": 1,
"pattern": "alertname",
"thresholds": [],
"type": "string",
"unit": "short"
},
{
"alias": "机房",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 2,
"mappingType": 1,
"pattern": "dc",
"thresholds": [],
"type": "number",
"unit": "short"
},
{
"alias": "服务器",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 2,
"mappingType": 1,
"pattern": "instance",
"thresholds": [],
"type": "number",
"unit": "short"
},
{
"alias": "",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"decimals": 2,
"pattern": "/.*/",
"thresholds": [],
"type": "hidden",
"unit": "short"
}
],
"targets": [
{
"annotations": false,
"expr": "ALERTS{alertstate='firing'}[24h]",
"format": "table",
"instant": true,
"interval": "15s",
"intervalFactor": 1,
"labelSelector": "*",
"legendFormat": "",
"refId": "A",
"target": "Query",
"type": "timeserie"
}
],
"title": "24小时告警历史",
"transform": "table",
"type": "table"
}
],
"title": "告警历史",
"type": "row"
}
],
"refresh": "30s",
"schemaVersion": 20,
"style": "dark",
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-24h",
"to": "now"
},
"timepicker": {
"refresh_intervals": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
]
},
"timezone": "",
"title": "Alerts",
"uid": "pbHjqZzmk",
"version": 10
}

1576562665216

告警大屏

说明

  1. 主要由告警记录及实时告警列表组成
  2. 告警记录包含当前普通警告及严重告警的数量,告警列表展示所有告警的详细信息
  3. 普通告警背景为黄色,严重告警背景为红色

1576575477285

资料

Prometheus 入门与实践
Prometheus 实战
camptocamp-prometheus-alertmanager-datasource