forked from grafana/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.libsonnet
429 lines (379 loc) · 14 KB
/
config.libsonnet
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
{
_images+:: {
agent: 'grafana/agent:latest',
agentctl: 'grafana/agentctl:latest',
},
_config+:: {
//
// Deployment options
//
agent_cluster_role_name: 'grafana-agent',
agent_configmap_name: 'grafana-agent',
agent_deployment_configmap_name: self.agent_configmap_name + '-deployment',
agent_pod_name: 'grafana-agent',
agent_deployment_pod_name: self.agent_pod_name + '-deployment',
cluster_dns_tld: 'local',
cluster_dns_suffix: 'cluster.' + self.cluster_dns_tld,
cluster_name: error 'must specify cluster name',
namespace: error 'must specify namespace',
agent_config_hash_annotation: true,
//
// Prometheus instance options
//
// Enabling this causes the agent to only scrape metrics on the same node
// on which it is currently running.
//
// Take CAUTION when disabling this! If the agent is deployed
// as a DaemonSet (like it is here by default), then disabling this will
// scrape all metrics multiple times, once per node, leading to
// duplicate samples being rejected and might hit limits.
agent_host_filter: true,
// The directory where the WAL is stored for all instances.
agent_wal_dir: '/var/lib/agent/data',
prometheus_kubernetes_api_server_address: 'kubernetes.default.svc.%(cluster_dns_suffix)s:443' % self,
prometheus_insecure_skip_verify: false,
scrape_api_server_endpoints: true,
//
// Config passed to the agent
//
// agent_config is rendered as a YAML and is the configuration file used
// to control the agent. A single instance is hard-coded and its
// scrape_configs are defined below.
//
// deployment_agent_config is a copy of `agent_config` that is used by the
// single-replica deployment to scrape jobs that don't work in host
// filtering mode.
agent_config: {
server: {
log_level: 'info',
},
prometheus: {
global: {
scrape_interval: '15s',
},
wal_directory: $._config.agent_wal_dir,
configs: [{
name: 'agent',
host_filter: $._config.agent_host_filter,
scrape_configs:
if $._config.agent_host_filter then
$._config.kubernetes_scrape_configs + $._config.deployment_scrape_configs
else
$._config.kubernetes_scrape_configs,
remote_write: $._config.agent_remote_write,
}],
},
},
deployment_agent_config: self.agent_config {
prometheus+: {
configs: [{
name: 'agent',
host_filter: false,
scrape_configs: $._config.deployment_scrape_configs,
remote_write: $._config.agent_remote_write,
}],
},
},
//
// We have two optional extension points for scrape config. One for the
// statefulset that holds all the agents attached to a node
// (kubernetes_scrape_configs) and One for the single replica deployment
// that is used to scrape jobs that don't work with host filtering mode
// (deployment_scrape_configs) the later is only used when host_filter =
// true.
deployment_scrape_configs: [
{
job_name: 'default/kubernetes',
kubernetes_sd_configs: [{
role:
if $._config.scrape_api_server_endpoints
then 'endpoints'
else 'service',
}],
scheme: 'https',
tls_config: {
ca_file: '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt',
insecure_skip_verify: $._config.prometheus_insecure_skip_verify,
},
bearer_token_file: '/var/run/secrets/kubernetes.io/serviceaccount/token',
relabel_configs: [{
source_labels: ['__meta_kubernetes_service_label_component'],
regex: 'apiserver',
action: 'keep',
}],
// Drop some high cardinality metrics.
metric_relabel_configs: [
{
source_labels: ['__name__'],
regex: 'apiserver_admission_controller_admission_latencies_seconds_.*',
action: 'drop',
},
{
source_labels: ['__name__'],
regex: 'apiserver_admission_step_admission_latencies_seconds_.*',
action: 'drop',
},
],
},
],
kubernetes_scrape_configs: [
{
job_name: 'kubernetes-pods',
kubernetes_sd_configs: [{
role: 'pod',
}],
tls_config: {
ca_file: '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt',
insecure_skip_verify: $._config.prometheus_insecure_skip_verify,
},
bearer_token_file: '/var/run/secrets/kubernetes.io/serviceaccount/token',
// You can specify the following annotations (on pods):
// prometheus.io/scrape: false - don't scrape this pod
// prometheus.io/scheme: https - use https for scraping
// prometheus.io/port - scrape this port
// prometheus.io/path - scrape this path
// prometheus.io/param-<parameter> - send ?parameter=value with the scrape
relabel_configs: [
// Drop anything annotated with prometheus.io/scrape=false
{
source_labels: ['__meta_kubernetes_pod_annotation_prometheus_io_scrape'],
action: 'drop',
regex: 'false',
},
// Drop any endpoint whose pod port name does not end with metrics
{
source_labels: ['__meta_kubernetes_pod_container_port_name'],
action: 'keep',
regex: '.*-metrics',
},
// Allow pods to override the scrape scheme with prometheus.io/scheme=https
{
source_labels: ['__meta_kubernetes_pod_annotation_prometheus_io_scheme'],
action: 'replace',
target_label: '__scheme__',
regex: '(https?)',
replacement: '$1',
},
// Allow service to override the scrape path with prometheus.io/path=/other_metrics_path
{
source_labels: ['__meta_kubernetes_pod_annotation_prometheus_io_path'],
action: 'replace',
target_label: '__metrics_path__',
regex: '(.+)',
replacement: '$1',
},
// Allow services to override the scrape port with prometheus.io/port=1234
{
source_labels: ['__address__', '__meta_kubernetes_pod_annotation_prometheus_io_port'],
action: 'replace',
target_label: '__address__',
regex: '(.+?)(\\:\\d+)?;(\\d+)',
replacement: '$1:$3',
},
// Drop pods without a name label
{
source_labels: ['__meta_kubernetes_pod_label_name'],
action: 'drop',
regex: '',
},
// Rename jobs to be <namespace>/<name, from pod name label>
{
source_labels: ['__meta_kubernetes_namespace', '__meta_kubernetes_pod_label_name'],
action: 'replace',
separator: '/',
target_label: 'job',
replacement: '$1',
},
// But also include the namespace as a separate label for routing alerts
{
source_labels: ['__meta_kubernetes_namespace'],
action: 'replace',
target_label: 'namespace',
},
{
source_labels: ['__meta_kubernetes_pod_name'],
action: 'replace',
target_label: 'pod', // Not 'pod_name', which disappeared in K8s 1.16.
},
{
source_labels: ['__meta_kubernetes_pod_container_name'],
action: 'replace',
target_label: 'container', // Not 'container_name', which disappeared in K8s 1.16.
},
// Rename instances to the concatenation of pod:container:port.
// All three components are needed to guarantee a unique instance label.
{
source_labels: [
'__meta_kubernetes_pod_name',
'__meta_kubernetes_pod_container_name',
'__meta_kubernetes_pod_container_port_name',
],
action: 'replace',
separator: ':',
target_label: 'instance',
},
// Map prometheus.io/param-<name>=value fields to __param_<name>=value
{
regex: '__meta_kubernetes_pod_annotation_prometheus_io_param_(.+)',
action: 'labelmap',
replacement: '__param_$1',
},
// Drop pods with phase Succeeded or Failed
{
source_labels: ['__meta_kubernetes_pod_phase'],
action: 'drop',
regex: 'Succeeded|Failed',
},
],
},
// A separate scrape config for kube-state-metrics which doesn't add a
// namespace label and instead takes the namespace label from the
// exported timeseries. This prevents the exported namespace label from
// being renamed to exported_namespace and allows us to route alerts
// based on namespace.
{
job_name: '%s/kube-state-metrics' % $._config.namespace,
kubernetes_sd_configs: [{
role: 'pod',
namespaces: {
names: [$._config.namespace],
},
}],
tls_config: {
ca_file: '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt',
insecure_skip_verify: $._config.prometheus_insecure_skip_verify,
},
bearer_token_file: '/var/run/secrets/kubernetes.io/serviceaccount/token',
relabel_configs: [
// Drop anything whose service is not kube-state-metrics
{
source_labels: ['__meta_kubernetes_pod_label_name'],
regex: 'kube-state-metrics',
action: 'keep',
},
// Rename instances to the concatenation of pod:container:port.
// In the specific case of KSM, we could leave out the container
// name and still have a unique instance label, but we leave it
// in here for consistency with the normal pod scraping.
{
source_labels: [
'__meta_kubernetes_pod_name',
'__meta_kubernetes_pod_container_name',
'__meta_kubernetes_pod_container_port_name',
],
action: 'replace',
separator: ':',
target_label: 'instance',
},
],
},
// A separate scrape config for node-exporter which maps the nodename
// onto the instance label.
{
job_name: '%s/node-exporter' % $._config.namespace,
kubernetes_sd_configs: [{
role: 'pod',
namespaces: {
names: [$._config.namespace],
},
}],
tls_config: {
ca_file: '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt',
insecure_skip_verify: $._config.prometheus_insecure_skip_verify,
},
bearer_token_file: '/var/run/secrets/kubernetes.io/serviceaccount/token',
relabel_configs: [
// Drop anything whose name is not node-exporter.
{
source_labels: ['__meta_kubernetes_pod_label_name'],
regex: 'node-exporter',
action: 'keep',
},
// Rename instances to be the node name.
{
source_labels: ['__meta_kubernetes_pod_node_name'],
action: 'replace',
target_label: 'instance',
},
// But also include the namespace as a separate label, for
// routing alerts.
{
source_labels: ['__meta_kubernetes_namespace'],
action: 'replace',
target_label: 'namespace',
},
],
},
// This scrape config gathers all kubelet metrics.
{
job_name: 'kube-system/kubelet',
kubernetes_sd_configs: [{
role: 'node',
}],
tls_config: {
ca_file: '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt',
insecure_skip_verify: $._config.prometheus_insecure_skip_verify,
},
bearer_token_file: '/var/run/secrets/kubernetes.io/serviceaccount/token',
relabel_configs: [
{
target_label: '__address__',
replacement: $._config.prometheus_kubernetes_api_server_address,
},
{
target_label: '__scheme__',
replacement: 'https',
},
{
source_labels: ['__meta_kubernetes_node_name'],
regex: '(.+)',
target_label: '__metrics_path__',
replacement: '/api/v1/nodes/${1}/proxy/metrics',
},
],
},
// As of k8s 1.7.3, cAdvisor metrics are available via kubelet using
// the /metrics/cadvisor path.
{
job_name: 'kube-system/cadvisor',
kubernetes_sd_configs: [{
role: 'node',
}],
scheme: 'https',
tls_config: {
ca_file: '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt',
insecure_skip_verify: $._config.prometheus_insecure_skip_verify,
},
bearer_token_file: '/var/run/secrets/kubernetes.io/serviceaccount/token',
relabel_configs: [
{
target_label: '__address__',
replacement: $._config.prometheus_kubernetes_api_server_address,
},
{
source_labels: ['__meta_kubernetes_node_name'],
regex: '(.+)',
target_label: '__metrics_path__',
replacement: '/api/v1/nodes/${1}/proxy/metrics/cadvisor',
},
],
metric_relabel_configs: [
// Drop container_* metrics with no image.
{
source_labels: ['__name__', 'image'],
regex: 'container_([a-z_]+);',
action: 'drop',
},
// Drop a bunch of metrics which are disabled but still sent,
// see https://github.com/google/cadvisor/issues/1925.
{
source_labels: ['__name__'],
regex: 'container_(network_tcp_usage_total|network_udp_usage_total|tasks_state|cpu_load_average_10s)',
action: 'drop',
},
],
},
],
agent_remote_write: [],
},
}