forked from openshift/cluster-monitoring-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-exporter.libsonnet
328 lines (319 loc) · 13.2 KB
/
node-exporter.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
local textfileDir = '/var/node_exporter/textfile';
local textfileVolumeName = 'node-exporter-textfile';
local tlsVolumeName = 'node-exporter-tls';
local wtmpPath = '/var/log/wtmp';
local wtmpVolumeName = 'node-exporter-wtmp';
local nodeExporter = import 'github.com/prometheus-operator/kube-prometheus/jsonnet/kube-prometheus/components/node-exporter.libsonnet';
local generateSecret = import '../utils/generate-secret.libsonnet';
local generateServiceMonitor = import '../utils/generate-service-monitors.libsonnet';
function(params)
local cfg = params;
nodeExporter(cfg) {
// Adding the serving certs annotation causes the serving certs controller
// to generate a valid and signed serving certificate and put it in the
// specified secret.
service+: {
metadata+: {
annotations+: {
'service.beta.openshift.io/serving-cert-secret-name': 'node-exporter-tls',
},
},
},
// This changes node-exporter to be scraped with validating TLS.
serviceMonitor+: {
metadata+: {
labels+: {
'monitoring.openshift.io/collection-profile': 'full',
},
},
spec+: {
endpoints: [
endpoint {
local metricRelabelingsOld = if std.objectHas(endpoint, 'metricRelabelings') then endpoint.metricRelabelings else [],
metricRelabelings:
metricRelabelingsOld +
[
{
// Drop other metrics from mountstats collector than these 3 metrics:
// 1. node_mountstats_nfs_read_bytes_total
// 2. node_mountstats_nfs_write_bytes_total
// 3. node_mountstats_nfs_operations_requests_total
sourceLabels: ['__name__'],
regex+: '(' + std.join('|', [
'node_mountstats_nfs_read_bytes_total',
'node_mountstats_nfs_write_bytes_total',
'node_mountstats_nfs_operations_requests_total',
]) + ')',
action: 'replace',
targetLabel: '__tmp_keep',
replacement: 'true',
},
{
action: 'drop',
sourceLabels: ['__name__', '__tmp_keep'],
regex: 'node_mountstats_nfs_.+;',
},
{
action: 'labeldrop',
regex: '__tmp_keep',
},
],
}
for endpoint in super.endpoints
],
},
},
minimalServiceMonitor: generateServiceMonitor.minimal(
super.serviceMonitor, std.join('|',
[
'node_cpu_info',
'node_cpu_seconds_total',
'node_disk_io_time_seconds_total',
'node_disk_io_time_weighted_seconds_total',
'node_disk_read_time_seconds_total',
'node_disk_reads_completed_total',
'node_disk_write_time_seconds_total',
'node_disk_writes_completed_total',
'node_filefd_allocated',
'node_filefd_maximum',
'node_filesystem_avail_bytes',
'node_filesystem_files',
'node_filesystem_files_free',
'node_filesystem_free_bytes',
'node_filesystem_readonly',
'node_filesystem_size_bytes',
'node_load1',
'node_memory_Buffers_bytes',
'node_memory_Cached_bytes',
'node_memory_MemAvailable_bytes',
'node_memory_MemFree_bytes',
'node_memory_MemTotal_bytes',
'node_memory_Slab_bytes',
'node_netstat_TcpExt_TCPSynRetrans',
'node_netstat_Tcp_OutSegs',
'node_netstat_Tcp_RetransSegs',
'node_network_receive_bytes_total',
'node_network_receive_drop_total',
'node_network_receive_errs_total',
'node_network_receive_packets_total',
'node_network_transmit_bytes_total',
'node_network_transmit_drop_total',
'node_network_transmit_errs_total',
'node_network_transmit_packets_total',
'node_network_up',
'node_nf_conntrack_entries',
'node_nf_conntrack_entries_limit',
'node_textfile_scrape_error',
'node_timex_maxerror_seconds',
'node_timex_offset_seconds',
'node_timex_sync_status',
'node_vmstat_pgmajfault',
'process_start_time_seconds',
'virt_platform',
])
),
securityContextConstraints: {
allowHostDirVolumePlugin: true,
allowHostNetwork: true,
allowHostPID: true,
allowHostPorts: true,
allowPrivilegedContainer: true,
apiVersion: 'security.openshift.io/v1',
kind: 'SecurityContextConstraints',
metadata: {
annotations: {
'kubernetes.io/description': 'node-exporter scc is used for the Prometheus node exporter',
},
name: 'node-exporter',
},
readOnlyRootFilesystem: false,
runAsUser: {
type: 'RunAsAny',
},
seLinuxContext: {
type: 'RunAsAny',
},
users: [],
},
clusterRole+: {
rules+: [{
apiGroups: ['security.openshift.io'],
resources: ['securitycontextconstraints'],
resourceNames: ['node-exporter'],
verbs: ['use'],
}],
},
// This configures the kube-rbac-proxies to use the serving cert
// configured on the `Service` above and adds the default init text
// collectors to the process.
daemonset+: {
metadata+: {
labels+: {
'app.kubernetes.io/managed-by': 'cluster-monitoring-operator',
},
},
spec+: {
template+: {
metadata+: {
labels+: {
'app.kubernetes.io/managed-by': 'cluster-monitoring-operator',
},
},
spec+: {
initContainers+: [
{
name: 'init-textfile',
command: ['/bin/sh', '-c', '[[ ! -d /node_exporter/collectors/init ]] || find /node_exporter/collectors/init -perm /111 -type f -exec {} \\;'],
env: [{ name: 'TMPDIR', value: '/tmp' }],
image: cfg.image,
resources: {
requests: {
cpu: '1m',
memory: '1Mi',
},
},
securityContext: {
privileged: true,
runAsUser: 0,
},
terminationMessagePolicy: 'FallbackToLogsOnError',
volumeMounts+: [
{
mountPath: textfileDir,
name: textfileVolumeName,
readOnly: false,
},
{
mountPath: wtmpPath,
name: wtmpVolumeName,
readOnly: true,
},
],
workingDir: textfileDir,
},
],
containers:
std.map(
function(c)
if c.name == 'kube-rbac-proxy' then
c {
args+: [
'--tls-cert-file=/etc/tls/private/tls.crt',
'--tls-private-key-file=/etc/tls/private/tls.key',
'--client-ca-file=/etc/tls/client/client-ca.crt',
'--config-file=/etc/kube-rbac-policy/config.yaml',
],
terminationMessagePolicy: 'FallbackToLogsOnError',
volumeMounts: [
{
mountPath: '/etc/tls/private',
name: tlsVolumeName,
readOnly: false,
},
{
mountPath: '/etc/tls/client',
name: 'metrics-client-ca',
readOnly: false,
},
{
mountPath: '/etc/kube-rbac-policy',
name: 'node-exporter-kube-rbac-proxy-config',
readOnly: true,
},
],
resources: {
requests: {
memory: '15Mi',
cpu: '1m',
},
},
}
else
c {
// Remove the flag to disable hwmon that is set upstream so we
// gather that data (especially for bare metal clusters), and
// add flags to collect the node_cpu_info metric + metrics
// from the text file.
// Disable btrfs collector as btrfs is not included in RHEL kernels
args: [a for a in c.args if (a != '--no-collector.hwmon' && a != '--no-collector.btrfs')] +
[
'--collector.cpu.info',
'--collector.textfile.directory=' + textfileDir,
'--no-collector.btrfs',
],
command: [
'/bin/sh',
'-c',
|||
export GOMAXPROCS=4
# We don't take CPU affinity into account as the container doesn't have integer CPU requests.
# In case of error, fallback to the default value.
NUM_CPUS=$(grep -c '^processor' "/proc/cpuinfo" 2>/dev/null || echo "0")
if [ "$NUM_CPUS" -lt "$GOMAXPROCS" ]; then
export GOMAXPROCS="$NUM_CPUS"
fi
echo "ts=$(date --iso-8601=seconds) num_cpus=$NUM_CPUS gomaxprocs=$GOMAXPROCS"
exec /bin/node_exporter "$0" "$@"
|||,
],
terminationMessagePolicy: 'FallbackToLogsOnError',
volumeMounts+: [{
mountPath: textfileDir,
name: textfileVolumeName,
readOnly: true,
}],
workingDir: textfileDir,
resources+: {
requests+: {
cpu: '8m',
memory: '32Mi',
},
},
// node-exporter has issue in rolling out with security context
// changes in kube-prometheus hence overidding the changes
securityContext: {},
},
super.containers,
),
volumes+: [
{
name: textfileVolumeName,
emptyDir: {},
},
{
name: tlsVolumeName,
secret: {
secretName: 'node-exporter-tls',
},
},
{
name: wtmpVolumeName,
hostPath: {
path: wtmpPath,
type: 'File',
},
},
{
name: 'metrics-client-ca',
configMap: {
name: 'metrics-client-ca',
},
},
{
name: 'node-exporter-kube-rbac-proxy-config',
secret: {
secretName: 'node-exporter-kube-rbac-proxy-config',
},
},
],
securityContext: {},
priorityClassName: 'system-cluster-critical',
tolerations: [
{ operator: 'Exists' },
],
},
},
},
},
kubeRbacProxySecret: generateSecret.staticAuthSecret(cfg.namespace, cfg.commonLabels, 'node-exporter-kube-rbac-proxy-config'),
}