Skip to content

Commit c9bcba2

Browse files
committed
Add support to sysctl node-exporter collector
Signed-off-by: Carlos Goncalves <[email protected]>
1 parent eca25a9 commit c9bcba2

File tree

9 files changed

+160
-0
lines changed

9 files changed

+160
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Note: This CHANGELOG is only for the monitoring team to track all monitoring related changes. Please see OpenShift release notes for official changes.
22

3+
## 4.19
4+
5+
- [#2339](https://github.com/openshift/cluster-monitoring-operator/pull/2339) Add support to sysctl node-exporter collector
6+
37
## 4.18
48

59
- [#2503](https://github.com/openshift/cluster-monitoring-operator/issues/2503) Expose `scrapeInterval` setting for UWM Prometheus.

Documentation/api.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Configuring Cluster Monitoring is optional. If the config does not exist or is e
3434
* [NodeExporterCollectorNetClassConfig](#nodeexportercollectornetclassconfig)
3535
* [NodeExporterCollectorNetDevConfig](#nodeexportercollectornetdevconfig)
3636
* [NodeExporterCollectorProcessesConfig](#nodeexportercollectorprocessesconfig)
37+
* [NodeExporterCollectorSysctlConfig](#nodeexportercollectorsysctlconfig)
3738
* [NodeExporterCollectorSystemdConfig](#nodeexportercollectorsystemdconfig)
3839
* [NodeExporterCollectorTcpStatConfig](#nodeexportercollectortcpstatconfig)
3940
* [NodeExporterConfig](#nodeexporterconfig)
@@ -248,6 +249,7 @@ The `NodeExporterCollectorConfig` resource defines settings for individual colle
248249
| mountstats | [NodeExporterCollectorMountStatsConfig](#nodeexportercollectormountstatsconfig) | Defines the configuration of the `mountstats` collector, which collects statistics about NFS volume I/O activities. Disabled by default. |
249250
| ksmd | [NodeExporterCollectorKSMDConfig](#nodeexportercollectorksmdconfig) | Defines the configuration of the `ksmd` collector, which collects statistics from the kernel same-page merger daemon. Disabled by default. |
250251
| processes | [NodeExporterCollectorProcessesConfig](#nodeexportercollectorprocessesconfig) | Defines the configuration of the `processes` collector, which collects statistics from processes and threads running in the system. Disabled by default. |
252+
| sysctl | [NodeExporterCollectorSysctlConfig](#nodeexportercollectorsysctlconfig) | Defines the configuration of the `sysctl` collector, which collects sysctl metrics. Disabled by default. |
251253
| systemd | [NodeExporterCollectorSystemdConfig](#nodeexportercollectorsystemdconfig) | Defines the configuration of the `systemd` collector, which collects statistics on the systemd daemon and its managed services. Disabled by default. |
252254

253255
[Back to TOC](#table-of-contents)
@@ -343,6 +345,23 @@ The `NodeExporterCollectorProcessesConfig` resource works as an on/off switch fo
343345

344346
[Back to TOC](#table-of-contents)
345347

348+
## NodeExporterCollectorSysctlConfig
349+
350+
#### Description
351+
352+
The `NodeExporterCollectorSysctlConfig` resource works as an on/off switch for the `sysctl` collector of the `node-exporter` agent. Caution! Exposing metrics like kernel.random.uuid can disrupt Prometheus, as it generates new data series with every scrape. Use this option judiciously! By default, the `sysctl` collector is disabled.
353+
354+
355+
<em>appears in: [NodeExporterCollectorConfig](#nodeexportercollectorconfig)</em>
356+
357+
| Property | Type | Description |
358+
| -------- | ---- | ----------- |
359+
| enabled | bool | A Boolean flag that enables or disables the `sysctl` collector. |
360+
| includeSysctlMetrics | []string | A list of numeric sysctl values. Note that a sysctl can contain multiple values, for example: `net.ipv4.tcp_rmem = 4096\t131072\t6291456`. Using `includeSysctlMetrics: ['net.ipv4.tcp_rmem']` the collector will expose: `node_sysctl_net_ipv4_tcp_rmem{index=\"0\"} 4096`, `node_sysctl_net_ipv4_tcp_rmem{index=\"1\"} 131072`, `node_sysctl_net_ipv4_tcp_rmem{index=\"2\"} 6291456`. If the indexes have defined meaning like in this case, the values can be mapped to multiple metrics: `includeSysctlMetrics: ['net.ipv4.tcp_rmem:min,default,max']`. The collector will expose these metrics as such: `node_sysctl_net_ipv4_tcp_rmem_min 4096`, `node_sysctl_net_ipv4_tcp_rmem_default 131072`, `node_sysctl_net_ipv4_tcp_rmem_max 6291456`. |
361+
| includeInfoSysctlMetrics | []string | A list of string sysctl values. For example: `includeSysctlMetrics: ['kernel.core_pattern', 'kernel.seccomp.actions_avail = kill_process kill_thread']`. The collector will expose these metrics as such: `node_sysctl_info{name=\"kernel.core_pattern\", value=\"core\"} 1`, `node_sysctl_info{name=\"kernel.seccomp.actions_avail\", index=\"0\", value=\"kill_process\"} 1`, `node_sysctl_info{name=\"kernel.seccomp.actions_avail\", index=\"1\", value=\"kill_thread\"} 1`, ... |
362+
363+
[Back to TOC](#table-of-contents)
364+
346365
## NodeExporterCollectorSystemdConfig
347366

348367
#### Description

Documentation/openshiftdocs/index.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ The configuration file itself is always defined under the `config.yaml` key in t
5454
* link:modules/nodeexportercollectornetclassconfig.adoc[NodeExporterCollectorNetClassConfig]
5555
* link:modules/nodeexportercollectornetdevconfig.adoc[NodeExporterCollectorNetDevConfig]
5656
* link:modules/nodeexportercollectorprocessesconfig.adoc[NodeExporterCollectorProcessesConfig]
57+
* link:modules/nodeexportercollectorsysctlconfig.adoc[NodeExporterCollectorSysctlConfig]
5758
* link:modules/nodeexportercollectorsystemdconfig.adoc[NodeExporterCollectorSystemdConfig]
5859
* link:modules/nodeexportercollectortcpstatconfig.adoc[NodeExporterCollectorTcpStatConfig]
5960
* link:modules/nodeexporterconfig.adoc[NodeExporterConfig]

Documentation/openshiftdocs/modules/nodeexportercollectorconfig.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Appears in: link:nodeexporterconfig.adoc[NodeExporterConfig]
3434

3535
|processes|link:nodeexportercollectorprocessesconfig.adoc[NodeExporterCollectorProcessesConfig]|Defines the configuration of the `processes` collector, which collects statistics from processes and threads running in the system. Disabled by default.
3636

37+
|sysctl|link:nodeexportercollectorsysctlconfig.adoc[NodeExporterCollectorSysctlConfig]|Defines the configuration of the `sysctl` collector, which collects sysctl metrics. Disabled by default.
38+
3739
|systemd|link:nodeexportercollectorsystemdconfig.adoc[NodeExporterCollectorSystemdConfig]|Defines the configuration of the `systemd` collector, which collects statistics on the systemd daemon and its managed services. Disabled by default.
3840

3941
|===
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// DO NOT EDIT THE CONTENT IN THIS FILE. It is automatically generated from the
2+
// source code for the Cluster Monitoring Operator. Any changes made to this
3+
// file will be overwritten when the content is re-generated. If you wish to
4+
// make edits, read the docgen utility instructions in the source code for the
5+
// CMO.
6+
:_content-type: ASSEMBLY
7+
8+
== NodeExporterCollectorSysctlConfig
9+
10+
=== Description
11+
12+
The `NodeExporterCollectorSysctlConfig` resource works as an on/off switch for the `sysctl` collector of the `node-exporter` agent. Caution! Exposing metrics like kernel.random.uuid can disrupt Prometheus, as it generates new data series with every scrape. Use this option judiciously! By default, the `sysctl` collector is disabled.
13+
14+
15+
16+
Appears in: link:nodeexportercollectorconfig.adoc[NodeExporterCollectorConfig]
17+
18+
[options="header"]
19+
|===
20+
| Property | Type | Description
21+
|enabled|bool|A Boolean flag that enables or disables the `sysctl` collector.
22+
23+
|includeSysctlMetrics|[]string|A list of numeric sysctl values. Note that a sysctl can contain multiple values, for example: `net.ipv4.tcp_rmem = 4096\t131072\t6291456`. Using `includeSysctlMetrics: ['net.ipv4.tcp_rmem']` the collector will expose: `node_sysctl_net_ipv4_tcp_rmem{index=\"0\"} 4096`, `node_sysctl_net_ipv4_tcp_rmem{index=\"1\"} 131072`, `node_sysctl_net_ipv4_tcp_rmem{index=\"2\"} 6291456`. If the indexes have defined meaning like in this case, the values can be mapped to multiple metrics: `includeSysctlMetrics: ['net.ipv4.tcp_rmem:min,default,max']`. The collector will expose these metrics as such: `node_sysctl_net_ipv4_tcp_rmem_min 4096`, `node_sysctl_net_ipv4_tcp_rmem_default 131072`, `node_sysctl_net_ipv4_tcp_rmem_max 6291456`.
24+
25+
|includeInfoSysctlMetrics|[]string|A list of string sysctl values. For example: `includeSysctlMetrics: ['kernel.core_pattern', 'kernel.seccomp.actions_avail = kill_process kill_thread']`. The collector will expose these metrics as such: `node_sysctl_info{name=\"kernel.core_pattern\", value=\"core\"} 1`, `node_sysctl_info{name=\"kernel.seccomp.actions_avail\", index=\"0\", value=\"kill_process\"} 1`, `node_sysctl_info{name=\"kernel.seccomp.actions_avail\", index=\"1\", value=\"kill_thread\"} 1`, ...
26+
27+
|===
28+
29+
link:../index.adoc[Back to TOC]

pkg/manifests/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ func defaultClusterMonitoringConfiguration() ClusterMonitoringConfiguration {
308308
Systemd: NodeExporterCollectorSystemdConfig{
309309
Enabled: false,
310310
},
311+
Sysctl: NodeExporterCollectorSysctlConfig{
312+
Enabled: false,
313+
IncludeSysctlMetrics: []string{},
314+
IncludeInfoSysctlMetrics: []string{},
315+
},
311316
},
312317
},
313318
}

pkg/manifests/manifests.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,25 @@ func (f *Factory) updateNodeExporterArgs(args []string) ([]string, error) {
884884
args = setArg(args, "--no-collector.tcpstat", "")
885885
}
886886

887+
if f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.Sysctl.Enabled {
888+
includeSysctlMetrics := f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.Sysctl.IncludeSysctlMetrics
889+
includeInfoSysctlMetrics := f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.Sysctl.IncludeInfoSysctlMetrics
890+
891+
args = setArg(args, "--collector.sysctl", "")
892+
893+
sysctlSet := uniqueSet(includeSysctlMetrics)
894+
for _, sysctl := range sysctlSet {
895+
args = append(args, fmt.Sprintf("--collector.sysctl.include=%s", sysctl))
896+
}
897+
898+
sysctlSet = uniqueSet(includeInfoSysctlMetrics)
899+
for _, sysctl := range sysctlSet {
900+
args = append(args, fmt.Sprintf("--collector.sysctl.include-info=%s", sysctl))
901+
}
902+
} else {
903+
args = setArg(args, "--no-collector.sysctl", "")
904+
}
905+
887906
var excludedDevices string
888907
if f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.NetDev.Enabled ||
889908
f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.NetClass.Enabled {
@@ -2353,6 +2372,18 @@ func setArg(args []string, argName string, argValue string) []string {
23532372
return args
23542373
}
23552374

2375+
func uniqueSet(input []string) []string {
2376+
uniqueMap := make(map[string]struct{})
2377+
var unique []string
2378+
for _, str := range input {
2379+
if _, ok := uniqueMap[str]; !ok {
2380+
uniqueMap[str] = struct{}{}
2381+
unique = append(unique, str)
2382+
}
2383+
}
2384+
return unique
2385+
}
2386+
23562387
func (f *Factory) PrometheusRuleValidatingWebhook() (*admissionv1.ValidatingWebhookConfiguration, error) {
23572388
return f.NewValidatingWebhook(f.assets.MustNewAssetSlice(AdmissionWebhookRuleValidatingWebhook))
23582389
}

pkg/manifests/manifests_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3254,6 +3254,7 @@ func TestNodeExporterCollectorSettings(t *testing.T) {
32543254
name: "default config",
32553255
config: "",
32563256
argsPresent: []string{"--no-collector.cpufreq",
3257+
"--no-collector.sysctl",
32573258
"--no-collector.tcpstat",
32583259
"--collector.netdev",
32593260
"--collector.netclass",
@@ -3266,6 +3267,7 @@ func TestNodeExporterCollectorSettings(t *testing.T) {
32663267
"--no-collector.systemd",
32673268
},
32683269
argsAbsent: []string{"--collector.cpufreq",
3270+
"--collector.sysctl",
32693271
"--collector.tcpstat",
32703272
"--no-collector.netdev",
32713273
"--no-collector.netclass",
@@ -3431,6 +3433,38 @@ nodeExporter:
34313433
"--collector.systemd.unit-include=^(network.+|nss.+)$"},
34323434
argsAbsent: []string{"--no-collector.systemd"},
34333435
},
3436+
{
3437+
name: "disable sysctl collector",
3438+
config: `
3439+
nodeExporter:
3440+
collectors:
3441+
sysctl:
3442+
enabled: false
3443+
`,
3444+
argsPresent: []string{"--no-collector.sysctl"},
3445+
argsAbsent: []string{"--collector.sysctl"},
3446+
},
3447+
{
3448+
name: "enable sysctl collector",
3449+
config: `
3450+
nodeExporter:
3451+
collectors:
3452+
sysctl:
3453+
enabled: true
3454+
includeSysctlMetrics:
3455+
- net.ipv4.tcp_rmem:min,default,max
3456+
- net.ipv4.tcp_mem
3457+
includeInfoSysctlMetrics:
3458+
- kernel.core_pattern
3459+
- kernel.seccomp.actions_avail
3460+
`,
3461+
argsPresent: []string{"--collector.sysctl",
3462+
"--collector.sysctl.include=net.ipv4.tcp_rmem:min,default,max",
3463+
"--collector.sysctl.include=net.ipv4.tcp_mem",
3464+
"--collector.sysctl.include-info=kernel.core_pattern",
3465+
"--collector.sysctl.include-info=kernel.seccomp.actions_avail"},
3466+
argsAbsent: []string{"--no-collector.sysctl"},
3467+
},
34343468
}
34353469

34363470
for _, test := range tests {

pkg/manifests/types.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ type NodeExporterCollectorConfig struct {
367367
// Defines the configuration of the `processes` collector, which collects statistics from processes and threads running in the system.
368368
// Disabled by default.
369369
Processes NodeExporterCollectorProcessesConfig `json:"processes,omitempty"`
370+
// Defines the configuration of the `sysctl` collector, which collects sysctl metrics.
371+
// Disabled by default.
372+
Sysctl NodeExporterCollectorSysctlConfig `json:"sysctl,omitempty"`
370373
// Defines the configuration of the `systemd` collector, which collects statistics on the systemd daemon and its managed services.
371374
// Disabled by default.
372375
Systemd NodeExporterCollectorSystemdConfig `json:"systemd,omitempty"`
@@ -392,6 +395,38 @@ type NodeExporterCollectorTcpStatConfig struct {
392395
Enabled bool `json:"enabled,omitempty"`
393396
}
394397

398+
// The `NodeExporterCollectorSysctlConfig` resource works as an on/off switch for
399+
// the `sysctl` collector of the `node-exporter` agent.
400+
// Caution! Exposing metrics like kernel.random.uuid can disrupt Prometheus, as it generates new data series with every scrape. Use this option judiciously!
401+
// By default, the `sysctl` collector is disabled.
402+
type NodeExporterCollectorSysctlConfig struct {
403+
// A Boolean flag that enables or disables the `sysctl` collector.
404+
Enabled bool `json:"enabled,omitempty"`
405+
// A list of numeric sysctl values.
406+
// Note that a sysctl can contain multiple values, for example:
407+
// `net.ipv4.tcp_rmem = 4096 131072 6291456`.
408+
// Using `includeSysctlMetrics: ['net.ipv4.tcp_rmem']` the collector will expose:
409+
// `node_sysctl_net_ipv4_tcp_rmem{index="0"} 4096`,
410+
// `node_sysctl_net_ipv4_tcp_rmem{index="1"} 131072`,
411+
// `node_sysctl_net_ipv4_tcp_rmem{index="2"} 6291456`.
412+
// If the indexes have defined meaning like in this case, the values can be mapped to multiple metrics:
413+
// `includeSysctlMetrics: ['net.ipv4.tcp_rmem:min,default,max']`.
414+
// The collector will expose these metrics as such:
415+
// `node_sysctl_net_ipv4_tcp_rmem_min 4096`,
416+
// `node_sysctl_net_ipv4_tcp_rmem_default 131072`,
417+
// `node_sysctl_net_ipv4_tcp_rmem_max 6291456`.
418+
IncludeSysctlMetrics []string `json:"includeSysctlMetrics,omitempty"`
419+
// A list of string sysctl values.
420+
// For example:
421+
// `includeSysctlMetrics: ['kernel.core_pattern', 'kernel.seccomp.actions_avail = kill_process kill_thread']`.
422+
// The collector will expose these metrics as such:
423+
// `node_sysctl_info{name="kernel.core_pattern", value="core"} 1`,
424+
// `node_sysctl_info{name="kernel.seccomp.actions_avail", index="0", value="kill_process"} 1`,
425+
// `node_sysctl_info{name="kernel.seccomp.actions_avail", index="1", value="kill_thread"} 1`,
426+
// ...
427+
IncludeInfoSysctlMetrics []string `json:"includeInfoSysctlMetrics,omitempty"`
428+
}
429+
395430
// The `NodeExporterCollectorNetDevConfig` resource works as an on/off switch for
396431
// the `netdev` collector of the `node-exporter` agent.
397432
// By default, the `netdev` collector is enabled.

0 commit comments

Comments
 (0)