Skip to content

Commit f218f5f

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

File tree

8 files changed

+120
-0
lines changed

8 files changed

+120
-0
lines changed

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. 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. |
363+
| includeInfoSysctlMetrics | *[]string | A list of string sysctl values. An optional mapping can be given to expose each value as its own metric. Otherwise an index label is used to identify the different fields. |
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. 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.
24+
25+
|includeInfoSysctlMetrics|*[]string|A list of string sysctl values. An optional mapping can be given to expose each value as its own metric. Otherwise an index label is used to identify the different fields.
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,21 @@ 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+
for _, sysctl := range includeSysctlMetrics {
885+
args = append(args, fmt.Sprintf("--collector.sysctl.include=%s", sysctl))
886+
}
887+
for _, sysctl := range includeInfoSysctlMetrics {
888+
args = append(args, fmt.Sprintf("--collector.sysctl.include-info=%s", sysctl))
889+
}
890+
} else {
891+
args = setArg(args, "--no-collector.sysctl", "")
892+
}
893+
879894
var excludedDevices string
880895
if f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.NetDev.Enabled ||
881896
f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.NetClass.Enabled {

pkg/manifests/manifests_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3380,6 +3380,7 @@ func TestNodeExporterCollectorSettings(t *testing.T) {
33803380
name: "default config",
33813381
config: "",
33823382
argsPresent: []string{"--no-collector.cpufreq",
3383+
"--no-collector.sysctl",
33833384
"--no-collector.tcpstat",
33843385
"--collector.netdev",
33853386
"--collector.netclass",
@@ -3392,6 +3393,7 @@ func TestNodeExporterCollectorSettings(t *testing.T) {
33923393
"--no-collector.systemd",
33933394
},
33943395
argsAbsent: []string{"--collector.cpufreq",
3396+
"--collector.sysctl",
33953397
"--collector.tcpstat",
33963398
"--no-collector.netdev",
33973399
"--no-collector.netclass",
@@ -3557,6 +3559,38 @@ nodeExporter:
35573559
"--collector.systemd.unit-include=^(network.+|nss.+)$"},
35583560
argsAbsent: []string{"--no-collector.systemd"},
35593561
},
3562+
{
3563+
name: "disable sysctl collector",
3564+
config: `
3565+
nodeExporter:
3566+
collectors:
3567+
sysctl:
3568+
enabled: false
3569+
`,
3570+
argsPresent: []string{"--no-collector.sysctl"},
3571+
argsAbsent: []string{"--collector.sysctl"},
3572+
},
3573+
{
3574+
name: "enable sysctl collector",
3575+
config: `
3576+
nodeExporter:
3577+
collectors:
3578+
sysctl:
3579+
enabled: true
3580+
includeSysctlMetrics:
3581+
- net.ipv4.tcp_rmem:min,default,max
3582+
- net.ipv4.tcp_mem
3583+
includeInfoSysctlMetrics:
3584+
- kernel.core_pattern
3585+
- kernel.seccomp.actions_avail
3586+
`,
3587+
argsPresent: []string{"--collector.sysctl",
3588+
"--collector.sysctl.include=net.ipv4.tcp_rmem:min,default,max",
3589+
"--collector.sysctl.include=net.ipv4.tcp_mem",
3590+
"--collector.sysctl.include-info=kernel.core_pattern",
3591+
"--collector.sysctl.include-info=kernel.seccomp.actions_avail"},
3592+
argsAbsent: []string{"--no-collector.sysctl"},
3593+
},
35603594
}
35613595

35623596
for _, test := range tests {

pkg/manifests/types.go

Lines changed: 15 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,18 @@ 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+
// By default, the `sysctl` collector is disabled.
385+
type NodeExporterCollectorSysctlConfig struct {
386+
// A Boolean flag that enables or disables the `sysctl` collector.
387+
Enabled bool `json:"enabled,omitempty"`
388+
// A list of numeric sysctl values.
389+
IncludeSysctlMetrics *[]string `json:"includeSysctlMetrics,omitempty"`
390+
// A list of string sysctl values. An optional mapping can be given to expose each value as its own metric. Otherwise an index label is used to identify the different fields.
391+
IncludeInfoSysctlMetrics *[]string `json:"includeInfoSysctlMetrics,omitempty"`
392+
}
393+
379394
// The `NodeExporterCollectorNetDevConfig` resource works as an on/off switch for
380395
// the `netdev` collector of the `node-exporter` agent.
381396
// By default, the `netdev` collector is enabled.

0 commit comments

Comments
 (0)