/
prometheus-config-map.yml
519 lines (474 loc) · 18.5 KB
/
prometheus-config-map.yml
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
---
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus-server-conf
labels:
name: prometheus-server-conf
namespace: monitoring
data:
prometheus.rules: |-
groups:
- name: node.alerts
rules:
- alert: KubernetesHostHighCPUUsage
expr: 100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 90
for: 15m
labels:
severity: "warning"
context: "node"
cluster:
annotations:
summary: "High load on node"
description: "Node {{ $labels.instance }} has more than 90% CPU load"
- alert: KubernetesNodeDiskUsagePercentage
expr: (100 - 100 * sum(node_filesystem_avail_bytes{device!~"tmpfs|by-uuid",fstype=~"xfs|ext"} / node_filesystem_size_bytes{device!~"tmpfs|by-uuid",fstype=~"xfs|ext"}) BY (instance,device)) > 85
for: 15m
labels:
severity: "warning"
context: "node"
cluster:
annotations:
description: "Node disk usage above 85%"
summary: "Disk usage on target {{ $labels.instance }} device {{ $labels.device }} at 85%"
- alert: KubernetesNodeContainerOOMKilled
expr: sum by (instance) (changes(node_vmstat_oom_kill[2h])) > 3
labels:
severity: "warning"
context: "node"
cluster:
annotations:
description: "More than 3 OOM killed pods on a node within 2h"
summary: "More than 3 OOM killed pods on node {{ $labels.instance }} within 2h"
- alert: KubernetesNodeHighLoad15
expr: node_load15 > 20
for: 15m
labels:
severity: "warning"
context: "node"
cluster:
annotations:
description: "Load average over 20 in the last 15 minutes"
summary: "The node {{ $labels.instance }} load average is over 20 in the last 15 minutes"
- alert: KubernetesNodeDiskPressure
expr: kube_node_status_condition{app="kube-state-metrics",condition="DiskPressure",status="true"} == 1
for: 10m
labels:
severity: "warning"
context: "node"
cluster:
annotations:
description: "Insufficient disk space"
summary: "Node {{ $labels.node }} under pressure due to insufficient available disk space"
- alert: KubernetesNodeMemoryPressure
expr: kube_node_status_condition{app="kube-state-metrics",condition="MemoryPressure",status="true"} == 1
for: 10m
labels:
severity: "warning"
context: "node"
cluster:
annotations:
description: "Insufficient memory"
summary: "Node {{ $labels.node }} under pressure due to insufficient available memory"
- alert: KubernetesNodePIDPressure
expr: kube_node_status_condition{app="kube-state-metrics",condition="PIDPressure",status="true"} == 1
for: 10m
labels:
severity: "warning"
context: "node"
cluster:
annotations:
description: "Too many processes on the node"
summary: "Node {{ $labels.node }} under pressure due to too many processes"
- alert: KubernetesNodeUnschedulable
expr: sum by(node) (kube_node_spec_unschedulable{app="kube-state-metrics"} == 1)
for: 15m
labels:
severity: warning
context: node
cluster:
annotations:
description: "Node unschedulable"
summary: "Node {{ $labels.node }} is unschedulable for more than 15 min"
- name: pod.alerts
rules:
- alert: KubernetesPodWaiting
expr: (sum(kube_pod_container_status_waiting_reason{app="kube-state-metrics"}) by (container,namespace,reason)) > 0
for: 15m
labels:
severity: "warning"
context: "pod"
cluster:
annotations:
description: "Pod waiting to start"
summary: "Pod {{ $labels.container }} in {{ $labels.namespace }} namespace waiting to start for more than 15 min"
- alert: KubernetesPodHighAvailability
expr: (sum by(container,namespace) (kube_pod_container_status_running{app="kube-state-metrics",namespace="kube-system",container="coredns"} or kube_pod_container_status_running{app="kube-state-metrics",namespace="kube-system",container="etcd"} or kube_pod_container_status_running{app="kube-state-metrics",namespace="kube-system",container="kube-apiserver"}) < 2)
for: 15m
labels:
severity: "warning"
context: "pod"
cluster:
annotations:
description: "Pod high availability requirements not met"
summary: "Pod {{ $labels.container }} in {{ $labels.namespace }} namespace does not meet HA requirements, less than 2 pods running"
- alert: KubernetesPodPhasePending
expr: sum by(namespace) (kube_pod_status_phase{app="kube-state-metrics",phase="Pending"} > 0)
for: 15m
labels:
severity: warning
context: pod
cluster:
annotations:
description: "Pod in pending phase"
summary: "At least one pod in {{ $labels.namespace }} namespace is pending for more than 15 min"
- alert: KubernetesPodUnscheduleable
expr: sum by(namespace) (kube_pod_status_unschedulable > 0)
for: 15m
labels:
severity: warning
context: pod
cluster:
annotations:
description: "Pod in unschedulable state"
summary: "At least one pod in {{ $labels.namespace }} namespace is unschedulable for more than 15 min"
- name: CPU
rules:
- expr: sum(rate(container_cpu_usage_seconds_total{container_name!=""}[5m]))
record: cluster:cpu_usage:rate5m
- expr: rate(container_cpu_usage_seconds_total{container_name!=""}[5m])
record: cluster:cpu_usage_nosum:rate5m
- expr: avg(irate(container_cpu_usage_seconds_total{container_name!="POD", container_name!=""}[5m])) by (container_name,pod_name,namespace)
record: kubecost_container_cpu_usage_irate
- expr: sum(container_memory_working_set_bytes{container_name!="POD",container_name!=""}) by (container_name,pod_name,namespace)
record: kubecost_container_memory_working_set_bytes
- expr: sum(container_memory_working_set_bytes{container_name!="POD",container_name!=""})
record: kubecost_cluster_memory_working_set_bytes
- name: Savings
rules:
- expr: sum(avg(kube_pod_owner{owner_kind!="DaemonSet"}) by (pod) * sum(container_cpu_allocation) by (pod))
record: kubecost_savings_cpu_allocation
labels:
daemonset: "false"
- expr: sum(avg(kube_pod_owner{owner_kind="DaemonSet"}) by (pod) * sum(container_cpu_allocation) by (pod)) / sum(kube_node_info)
record: kubecost_savings_cpu_allocation
labels:
daemonset: "true"
- expr: sum(avg(kube_pod_owner{owner_kind!="DaemonSet"}) by (pod) * sum(container_memory_allocation_bytes) by (pod))
record: kubecost_savings_memory_allocation_bytes
labels:
daemonset: "false"
- expr: sum(avg(kube_pod_owner{owner_kind="DaemonSet"}) by (pod) * sum(container_memory_allocation_bytes) by (pod)) / sum(kube_node_info)
record: kubecost_savings_memory_allocation_bytes
labels:
daemonset: "true"
- expr: label_replace(sum(kube_pod_status_phase{phase="Running",namespace!="kube-system"} > 0) by (pod, namespace), "pod_name", "$1", "pod", "(.+)")
record: kubecost_savings_running_pods
- expr: sum(rate(container_cpu_usage_seconds_total{container_name!="",container_name!="POD",instance!=""}[5m])) by (namespace, pod_name, container_name, instance)
record: kubecost_savings_container_cpu_usage_seconds
- expr: sum(container_memory_working_set_bytes{container_name!="",container_name!="POD",instance!=""}) by (namespace, pod_name, container_name, instance)
record: kubecost_savings_container_memory_usage_bytes
- expr: avg(sum(kube_pod_container_resource_requests{resource="cpu", unit="core", namespace!="kube-system"}) by (pod, namespace, instance)) by (pod, namespace)
record: kubecost_savings_pod_requests_cpu_cores
- expr: avg(sum(kube_pod_container_resource_requests{resource="memory", unit="byte", namespace!="kube-system"}) by (pod, namespace, instance)) by (pod, namespace)
record: kubecost_savings_pod_requests_memory_bytes
prometheus.yml: |-
global:
evaluation_interval: 60s
scrape_interval: 15s
scrape_timeout: 10s
external_labels:
cluster: ${CLUSTER_NAME}
rule_files:
- /etc/prometheus/prometheus.rules
# Alertmanager configuration
alerting:
alert_relabel_configs:
- source_labels: [cluster]
action: replace
regex: (.*)
replacement: "$1"
target_label: cluster
alertmanagers:
- static_configs:
- targets:
- 'alertmanager.monitoring.svc:9093'
scrape_configs:
- job_name: 'kubernetes-apiservers'
kubernetes_sd_configs:
- role: endpoints
scheme: https
tls_config:
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
relabel_configs:
- source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
action: keep
regex: default;kubernetes;https
#--------------------------------------------
# Scrape config for nodes (kubelet).
#--------------------------------------------
- job_name: 'kubernetes-nodes'
kubernetes_sd_configs:
- role: node
relabel_configs:
- action: labelmap
regex: __meta_kubernetes_node_label_(.+)
- target_label: __address__
replacement: kubernetes.default.svc:443
- source_labels: [__meta_kubernetes_node_name]
regex: (.+)
target_label: __metrics_path__
replacement: /api/v1/nodes/${1}/proxy/metrics
scheme: https
tls_config:
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
#--------------------------------------------
# Scrape config for service endpoints. This will
# scrape node-exporter and kube-state-metrics services.
# You need this for the following Grafana dashboards:
# - Kubernetes Cluster Summary
# - Node Exporter Full
#--------------------------------------------
- job_name: kubernetes-service-endpoints
kubernetes_sd_configs:
- role: endpoints
relabel_configs:
- action: keep
regex: true
source_labels:
- __meta_kubernetes_service_annotation_prometheus_io_scrape
- action: replace
regex: (https?)
source_labels:
- __meta_kubernetes_service_annotation_prometheus_io_scheme
target_label: __scheme__
- action: replace
regex: (.+)
source_labels:
- __meta_kubernetes_service_annotation_prometheus_io_path
target_label: __metrics_path__
- action: replace
regex: ([^:]+)(?::\d+)?;(\d+)
replacement: $1:$2
source_labels:
- __address__
- __meta_kubernetes_service_annotation_prometheus_io_port
target_label: __address__
- action: labelmap
regex: __meta_kubernetes_service_label_(.+)
- action: replace
source_labels:
- __meta_kubernetes_namespace
target_label: kubernetes_namespace
- action: replace
source_labels:
- __meta_kubernetes_service_name
target_label: kubernetes_name
- action: replace
source_labels:
- __meta_kubernetes_pod_node_name
target_label: kubernetes_node
#--------------------------------------------
# Scrape config for pods.
#--------------------------------------------
- job_name: 'kubernetes-pods'
kubernetes_sd_configs:
- role: pod
relabel_configs:
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
action: keep
regex: true
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
action: replace
target_label: __metrics_path__
regex: (.+)
- source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
action: replace
regex: ([^:]+)(?::\d+)?;(\d+)
replacement: $1:$2
target_label: __address__
- action: labelmap
regex: __meta_kubernetes_pod_label_(.+)
- source_labels: [__meta_kubernetes_namespace]
action: replace
target_label: kubernetes_namespace
- source_labels: [__meta_kubernetes_pod_name]
action: replace
target_label: kubernetes_pod_name
- source_labels: [__meta_kubernetes_pod_name, __address__]
action: drop
regex: "loki-0;.*:(9095|7946)"
#--------------------------------------------
# Scrape config for cadvisor.
#--------------------------------------------
- job_name: 'kubernetes-cadvisor'
kubernetes_sd_configs:
- role: node
scheme: https
tls_config:
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
relabel_configs:
- action: labelmap
regex: __meta_kubernetes_node_label_(.+)
- target_label: __address__
replacement: kubernetes.default.svc:443
- source_labels: [__meta_kubernetes_node_name]
regex: (.+)
target_label: __metrics_path__
replacement: /api/v1/nodes/${1}/proxy/metrics/cadvisor
#--------------------------------------------
# Scrape the cost-model /metrics endpoint.
#--------------------------------------------
- job_name: 'kubecost'
honor_labels: true
scrape_interval: 1m
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
dns_sd_configs:
- names:
- kubecost-cost-analyzer.kubecost
type: 'A'
port: 9003
#--------------------------------------------
# Scrape static config for homelab.
#--------------------------------------------
- job_name: 'dns-master'
static_configs:
- targets: ['10.11.1.2:9153']
labels:
alias: admin1
- job_name: 'dns-slave1'
static_configs:
- targets: ['10.11.1.3:9153']
labels:
alias: admin2
- job_name: 'etcd'
static_configs:
- targets: ['10.11.1.31:2381','10.11.1.32:2381','10.11.1.33:2381']
- job_name: 'haproxy'
static_configs:
- targets: ['10.11.1.30:9101']
- job_name: 'admin1'
static_configs:
- targets: ['10.11.1.2:9100']
labels:
alias: admin1
- job_name: 'admin2'
static_configs:
- targets: ['10.11.1.3:9100']
labels:
alias: admin2
- job_name: 'pxe'
static_configs:
- targets: ['10.11.1.20:9100']
labels:
alias: pxe
- job_name: 'kvm1'
static_configs:
- targets: ['10.11.1.21:9100']
labels:
alias: kvm1
- job_name: 'kvm2'
static_configs:
- targets: ['10.11.1.22:9100']
labels:
alias: kvm2
- job_name: 'kvm3'
static_configs:
- targets: ['10.11.1.23:9100']
labels:
alias: kvm3
- job_name: 'media-pc'
static_configs:
- targets: ['10.11.1.28:9100']
labels:
alias: media-pc
- job_name: 'k8s-master1'
static_configs:
- targets: ['10.11.1.31:9100']
labels:
alias: k8s-master1
- job_name: 'k8s-master2'
static_configs:
- targets: ['10.11.1.32:9100']
labels:
alias: k8s-master2
- job_name: 'k8s-master3'
static_configs:
- targets: ['10.11.1.33:9100']
labels:
alias: k8s-master3
- job_name: 'k8s-node1'
static_configs:
- targets: ['10.11.1.34:9100']
labels:
alias: k8s-node1
- job_name: 'k8s-node2'
static_configs:
- targets: ['10.11.1.35:9100']
labels:
alias: k8s-node2
- job_name: 'k8s-node3'
static_configs:
- targets: ['10.11.1.36:9100']
labels:
alias: k8s-node3
- job_name: 'openvas'
static_configs:
- targets: ['10.11.1.40:9100']
labels:
alias: openvas
- job_name: 'raspberrypi'
static_configs:
- targets: ['10.11.1.7:9100']
labels:
alias: raspberrypi
- job_name: 'pihole-exporter'
static_configs:
- targets: ['pihole-exporter.monitoring.svc:9617']
labels:
alias: pihole-exporter
- job_name: 'vps'
static_configs:
- targets: ['vps.hl.test:9100']
labels:
alias: vps
- job_name: 'mysql'
static_configs:
- targets: ['vps.hl.test:9104']
labels:
alias: mysql
- job_name: 'mikrotik-exporter'
scrape_interval: 30s
static_configs:
- targets:
- 10.11.1.1 # your Mikrotik router IP you wish to monitor
metrics_path: /metrics
params:
module: [my_router]
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: mikrotik-exporter:9436
- job_name: 'mikrotik-lte-exporter'
scrape_interval: 30s
static_configs:
- targets:
- 10.11.1.11 # your Mikrotik LTE router IP you wish to monitor
metrics_path: /metrics
params:
module: [my_router]
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: mikrotik-lte-exporter:9437