Skip to content

Commit c90f629

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

File tree

9 files changed

+157
-0
lines changed

9 files changed

+157
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [#2302](https://github.com/openshift/cluster-monitoring-operator/issues/2302) Enable feature `extra-scrape-metrics` in Prometheus user-workload
66
- [#2319](https://github.com/openshift/cluster-monitoring-operator/pull/2319) Allow read-only access to the Alertmanager API (use `monitoring-alertmanager-view`).
77
- [#2078](https://github.com/openshift/cluster-monitoring-operator/pull/2078) Support exporting VPA metrics from KSM.
8+
- [#2339](https://github.com/openshift/cluster-monitoring-operator/pull/2339) Add support to sysctl node-exporter collector
89

910
## 4.15
1011

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)
@@ -250,6 +251,7 @@ The `NodeExporterCollectorConfig` resource defines settings for individual colle
250251
| mountstats | [NodeExporterCollectorMountStatsConfig](#nodeexportercollectormountstatsconfig) | Defines the configuration of the `mountstats` collector, which collects statistics about NFS volume I/O activities. Disabled by default. |
251252
| ksmd | [NodeExporterCollectorKSMDConfig](#nodeexportercollectorksmdconfig) | Defines the configuration of the `ksmd` collector, which collects statistics from the kernel same-page merger daemon. Disabled by default. |
252253
| processes | [NodeExporterCollectorProcessesConfig](#nodeexportercollectorprocessesconfig) | Defines the configuration of the `processes` collector, which collects statistics from processes and threads running in the system. Disabled by default. |
254+
| sysctl | [NodeExporterCollectorSysctlConfig](#nodeexportercollectorsysctlconfig) | Defines the configuration of the `sysctl` collector, which collects sysctl metrics. Disabled by default. |
253255
| systemd | [NodeExporterCollectorSystemdConfig](#nodeexportercollectorsystemdconfig) | Defines the configuration of the `systemd` collector, which collects statistics on the systemd daemon and its managed services. Disabled by default. |
254256

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

346348
[Back to TOC](#table-of-contents)
347349

350+
## NodeExporterCollectorSysctlConfig
351+
352+
#### Description
353+
354+
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.
355+
356+
357+
<em>appears in: [NodeExporterCollectorConfig](#nodeexportercollectorconfig)</em>
358+
359+
| Property | Type | Description |
360+
| -------- | ---- | ----------- |
361+
| enabled | bool | A Boolean flag that enables or disables the `sysctl` collector. |
362+
| 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`. |
363+
| 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`, ... |
364+
365+
[Back to TOC](#table-of-contents)
366+
348367
## NodeExporterCollectorSystemdConfig
349368

350369
#### 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
@@ -217,6 +217,11 @@ func defaultClusterMonitoringConfiguration() ClusterMonitoringConfiguration {
217217
Systemd: NodeExporterCollectorSystemdConfig{
218218
Enabled: false,
219219
},
220+
Sysctl: NodeExporterCollectorSysctlConfig{
221+
Enabled: false,
222+
IncludeSysctlMetrics: []string{},
223+
IncludeInfoSysctlMetrics: []string{},
224+
},
220225
},
221226
},
222227
}

pkg/manifests/manifests.go

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

879+
if f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.Sysctl.Enabled {
880+
includeSysctlMetrics := f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.Sysctl.IncludeSysctlMetrics
881+
includeInfoSysctlMetrics := f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.Sysctl.IncludeInfoSysctlMetrics
882+
883+
args = setArg(args, "--collector.sysctl", "")
884+
885+
sysctlSet := uniqueSet(includeSysctlMetrics)
886+
for _, sysctl := range sysctlSet {
887+
args = append(args, fmt.Sprintf("--collector.sysctl.include=%s", sysctl))
888+
}
889+
890+
sysctlSet = uniqueSet(includeInfoSysctlMetrics)
891+
for _, sysctl := range sysctlSet {
892+
args = append(args, fmt.Sprintf("--collector.sysctl.include-info=%s", sysctl))
893+
}
894+
} else {
895+
args = setArg(args, "--no-collector.sysctl", "")
896+
}
897+
879898
var excludedDevices string
880899
if f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.NetDev.Enabled ||
881900
f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.NetClass.Enabled {
@@ -2488,6 +2507,18 @@ func setArg(args []string, argName string, argValue string) []string {
24882507
return args
24892508
}
24902509

2510+
func uniqueSet(input []string) []string {
2511+
uniqueMap := make(map[string]struct{})
2512+
var unique []string
2513+
for _, str := range input {
2514+
if _, ok := uniqueMap[str]; !ok {
2515+
uniqueMap[str] = struct{}{}
2516+
unique = append(unique, str)
2517+
}
2518+
}
2519+
return unique
2520+
}
2521+
24912522
func (f *Factory) PrometheusRuleValidatingWebhook() (*admissionv1.ValidatingWebhookConfiguration, error) {
24922523
return f.NewValidatingWebhook(f.assets.MustNewAssetSlice(AdmissionWebhookRuleValidatingWebhook))
24932524
}

pkg/manifests/manifests_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3480,6 +3480,7 @@ func TestNodeExporterCollectorSettings(t *testing.T) {
34803480
name: "default config",
34813481
config: "",
34823482
argsPresent: []string{"--no-collector.cpufreq",
3483+
"--no-collector.sysctl",
34833484
"--no-collector.tcpstat",
34843485
"--collector.netdev",
34853486
"--collector.netclass",
@@ -3492,6 +3493,7 @@ func TestNodeExporterCollectorSettings(t *testing.T) {
34923493
"--no-collector.systemd",
34933494
},
34943495
argsAbsent: []string{"--collector.cpufreq",
3496+
"--collector.sysctl",
34953497
"--collector.tcpstat",
34963498
"--no-collector.netdev",
34973499
"--no-collector.netclass",
@@ -3657,6 +3659,38 @@ nodeExporter:
36573659
"--collector.systemd.unit-include=^(network.+|nss.+)$"},
36583660
argsAbsent: []string{"--no-collector.systemd"},
36593661
},
3662+
{
3663+
name: "disable sysctl collector",
3664+
config: `
3665+
nodeExporter:
3666+
collectors:
3667+
sysctl:
3668+
enabled: false
3669+
`,
3670+
argsPresent: []string{"--no-collector.sysctl"},
3671+
argsAbsent: []string{"--collector.sysctl"},
3672+
},
3673+
{
3674+
name: "enable sysctl collector",
3675+
config: `
3676+
nodeExporter:
3677+
collectors:
3678+
sysctl:
3679+
enabled: true
3680+
includeSysctlMetrics:
3681+
- net.ipv4.tcp_rmem:min,default,max
3682+
- net.ipv4.tcp_mem
3683+
includeInfoSysctlMetrics:
3684+
- kernel.core_pattern
3685+
- kernel.seccomp.actions_avail
3686+
`,
3687+
argsPresent: []string{"--collector.sysctl",
3688+
"--collector.sysctl.include=net.ipv4.tcp_rmem:min,default,max",
3689+
"--collector.sysctl.include=net.ipv4.tcp_mem",
3690+
"--collector.sysctl.include-info=kernel.core_pattern",
3691+
"--collector.sysctl.include-info=kernel.seccomp.actions_avail"},
3692+
argsAbsent: []string{"--no-collector.sysctl"},
3693+
},
36603694
}
36613695

36623696
for _, test := range tests {

pkg/manifests/types.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ type NodeExporterCollectorConfig struct {
351351
// Defines the configuration of the `processes` collector, which collects statistics from processes and threads running in the system.
352352
// Disabled by default.
353353
Processes NodeExporterCollectorProcessesConfig `json:"processes,omitempty"`
354+
// Defines the configuration of the `sysctl` collector, which collects sysctl metrics.
355+
// Disabled by default.
356+
Sysctl NodeExporterCollectorSysctlConfig `json:"sysctl,omitempty"`
354357
// Defines the configuration of the `systemd` collector, which collects statistics on the systemd daemon and its managed services.
355358
// Disabled by default.
356359
Systemd NodeExporterCollectorSystemdConfig `json:"systemd,omitempty"`
@@ -376,6 +379,38 @@ type NodeExporterCollectorTcpStatConfig struct {
376379
Enabled bool `json:"enabled,omitempty"`
377380
}
378381

382+
// The `NodeExporterCollectorSysctlConfig` resource works as an on/off switch for
383+
// the `sysctl` collector of the `node-exporter` agent.
384+
// Caution! Exposing metrics like kernel.random.uuid can disrupt Prometheus, as it generates new data series with every scrape. Use this option judiciously!
385+
// By default, the `sysctl` collector is disabled.
386+
type NodeExporterCollectorSysctlConfig struct {
387+
// A Boolean flag that enables or disables the `sysctl` collector.
388+
Enabled bool `json:"enabled,omitempty"`
389+
// A list of numeric sysctl values.
390+
// Note that a sysctl can contain multiple values, for example:
391+
// `net.ipv4.tcp_rmem = 4096 131072 6291456`.
392+
// Using `includeSysctlMetrics: ['net.ipv4.tcp_rmem']` the collector will expose:
393+
// `node_sysctl_net_ipv4_tcp_rmem{index="0"} 4096`,
394+
// `node_sysctl_net_ipv4_tcp_rmem{index="1"} 131072`,
395+
// `node_sysctl_net_ipv4_tcp_rmem{index="2"} 6291456`.
396+
// If the indexes have defined meaning like in this case, the values can be mapped to multiple metrics:
397+
// `includeSysctlMetrics: ['net.ipv4.tcp_rmem:min,default,max']`.
398+
// The collector will expose these metrics as such:
399+
// `node_sysctl_net_ipv4_tcp_rmem_min 4096`,
400+
// `node_sysctl_net_ipv4_tcp_rmem_default 131072`,
401+
// `node_sysctl_net_ipv4_tcp_rmem_max 6291456`.
402+
IncludeSysctlMetrics []string `json:"includeSysctlMetrics,omitempty"`
403+
// A list of string sysctl values.
404+
// For example:
405+
// `includeSysctlMetrics: ['kernel.core_pattern', 'kernel.seccomp.actions_avail = kill_process kill_thread']`.
406+
// The collector will expose these metrics as such:
407+
// `node_sysctl_info{name="kernel.core_pattern", value="core"} 1`,
408+
// `node_sysctl_info{name="kernel.seccomp.actions_avail", index="0", value="kill_process"} 1`,
409+
// `node_sysctl_info{name="kernel.seccomp.actions_avail", index="1", value="kill_thread"} 1`,
410+
// ...
411+
IncludeInfoSysctlMetrics []string `json:"includeInfoSysctlMetrics,omitempty"`
412+
}
413+
379414
// The `NodeExporterCollectorNetDevConfig` resource works as an on/off switch for
380415
// the `netdev` collector of the `node-exporter` agent.
381416
// By default, the `netdev` collector is enabled.

0 commit comments

Comments
 (0)