Skip to content

Commit

Permalink
Add support to sysctl node-exporter collector
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Goncalves <[email protected]>
  • Loading branch information
cgoncalves committed May 7, 2024
1 parent ac5f674 commit b5f423f
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [#2302](https://github.com/openshift/cluster-monitoring-operator/issues/2302) Enable feature `extra-scrape-metrics` in Prometheus user-workload
- [#2319](https://github.com/openshift/cluster-monitoring-operator/pull/2319) Allow read-only access to the Alertmanager API (use `monitoring-alertmanager-view`).
- [#2078](https://github.com/openshift/cluster-monitoring-operator/pull/2078) Support exporting VPA metrics from KSM.
- [#2339](https://github.com/openshift/cluster-monitoring-operator/pull/2339) Add support to sysctl node-exporter collector

## 4.15

Expand Down
19 changes: 19 additions & 0 deletions Documentation/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Configuring Cluster Monitoring is optional. If the config does not exist or is e
* [NodeExporterCollectorNetClassConfig](#nodeexportercollectornetclassconfig)
* [NodeExporterCollectorNetDevConfig](#nodeexportercollectornetdevconfig)
* [NodeExporterCollectorProcessesConfig](#nodeexportercollectorprocessesconfig)
* [NodeExporterCollectorSysctlConfig](#nodeexportercollectorsysctlconfig)
* [NodeExporterCollectorSystemdConfig](#nodeexportercollectorsystemdconfig)
* [NodeExporterCollectorTcpStatConfig](#nodeexportercollectortcpstatconfig)
* [NodeExporterConfig](#nodeexporterconfig)
Expand Down Expand Up @@ -250,6 +251,7 @@ The `NodeExporterCollectorConfig` resource defines settings for individual colle
| mountstats | [NodeExporterCollectorMountStatsConfig](#nodeexportercollectormountstatsconfig) | Defines the configuration of the `mountstats` collector, which collects statistics about NFS volume I/O activities. Disabled by default. |
| ksmd | [NodeExporterCollectorKSMDConfig](#nodeexportercollectorksmdconfig) | Defines the configuration of the `ksmd` collector, which collects statistics from the kernel same-page merger daemon. Disabled by default. |
| processes | [NodeExporterCollectorProcessesConfig](#nodeexportercollectorprocessesconfig) | Defines the configuration of the `processes` collector, which collects statistics from processes and threads running in the system. Disabled by default. |
| sysctl | [NodeExporterCollectorSysctlConfig](#nodeexportercollectorsysctlconfig) | Defines the configuration of the `sysctl` collector, which collects sysctl metrics. Disabled by default. |
| systemd | [NodeExporterCollectorSystemdConfig](#nodeexportercollectorsystemdconfig) | Defines the configuration of the `systemd` collector, which collects statistics on the systemd daemon and its managed services. Disabled by default. |

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

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

## NodeExporterCollectorSysctlConfig

#### Description

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.


<em>appears in: [NodeExporterCollectorConfig](#nodeexportercollectorconfig)</em>

| Property | Type | Description |
| -------- | ---- | ----------- |
| enabled | bool | A Boolean flag that enables or disables the `sysctl` collector. |
| includeSysctlMetrics | *[]string | A list of numeric sysctl values. |
| 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. |

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

## NodeExporterCollectorSystemdConfig

#### Description
Expand Down
1 change: 1 addition & 0 deletions Documentation/openshiftdocs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ The configuration file itself is always defined under the `config.yaml` key in t
* link:modules/nodeexportercollectornetclassconfig.adoc[NodeExporterCollectorNetClassConfig]
* link:modules/nodeexportercollectornetdevconfig.adoc[NodeExporterCollectorNetDevConfig]
* link:modules/nodeexportercollectorprocessesconfig.adoc[NodeExporterCollectorProcessesConfig]
* link:modules/nodeexportercollectorsysctlconfig.adoc[NodeExporterCollectorSysctlConfig]
* link:modules/nodeexportercollectorsystemdconfig.adoc[NodeExporterCollectorSystemdConfig]
* link:modules/nodeexportercollectortcpstatconfig.adoc[NodeExporterCollectorTcpStatConfig]
* link:modules/nodeexporterconfig.adoc[NodeExporterConfig]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Appears in: link:nodeexporterconfig.adoc[NodeExporterConfig]

|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.

|sysctl|link:nodeexportercollectorsysctlconfig.adoc[NodeExporterCollectorSysctlConfig]|Defines the configuration of the `sysctl` collector, which collects sysctl metrics. Disabled by default.

|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.

|===
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// DO NOT EDIT THE CONTENT IN THIS FILE. It is automatically generated from the
// source code for the Cluster Monitoring Operator. Any changes made to this
// file will be overwritten when the content is re-generated. If you wish to
// make edits, read the docgen utility instructions in the source code for the
// CMO.
:_content-type: ASSEMBLY

== NodeExporterCollectorSysctlConfig

=== Description

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.



Appears in: link:nodeexportercollectorconfig.adoc[NodeExporterCollectorConfig]

[options="header"]
|===
| Property | Type | Description
|enabled|bool|A Boolean flag that enables or disables the `sysctl` collector.

|includeSysctlMetrics|*[]string|A list of numeric sysctl values.

|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.

|===

link:../index.adoc[Back to TOC]
5 changes: 5 additions & 0 deletions pkg/manifests/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ func defaultClusterMonitoringConfiguration() ClusterMonitoringConfiguration {
Systemd: NodeExporterCollectorSystemdConfig{
Enabled: false,
},
Sysctl: NodeExporterCollectorSysctlConfig{
Enabled: false,
IncludeSysctlMetrics: &[]string{},
IncludeInfoSysctlMetrics: &[]string{},
},
},
},
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/manifests/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,21 @@ func (f *Factory) updateNodeExporterArgs(args []string) ([]string, error) {
args = setArg(args, "--no-collector.tcpstat", "")
}

if f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.Sysctl.Enabled {
includeSysctlMetrics := *f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.Sysctl.IncludeSysctlMetrics
includeInfoSysctlMetrics := *f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.Sysctl.IncludeInfoSysctlMetrics

args = setArg(args, "--collector.sysctl", "")
for _, sysctl := range includeSysctlMetrics {
args = append(args, fmt.Sprintf("--collector.sysctl.include=%s", sysctl))
}
for _, sysctl := range includeInfoSysctlMetrics {
args = append(args, fmt.Sprintf("--collector.sysctl.include-info=%s", sysctl))
}
} else {
args = setArg(args, "--no-collector.sysctl", "")
}

var excludedDevices string
if f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.NetDev.Enabled ||
f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.NetClass.Enabled {
Expand Down
34 changes: 34 additions & 0 deletions pkg/manifests/manifests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3380,6 +3380,7 @@ func TestNodeExporterCollectorSettings(t *testing.T) {
name: "default config",
config: "",
argsPresent: []string{"--no-collector.cpufreq",
"--no-collector.sysctl",
"--no-collector.tcpstat",
"--collector.netdev",
"--collector.netclass",
Expand All @@ -3392,6 +3393,7 @@ func TestNodeExporterCollectorSettings(t *testing.T) {
"--no-collector.systemd",
},
argsAbsent: []string{"--collector.cpufreq",
"--collector.sysctl",
"--collector.tcpstat",
"--no-collector.netdev",
"--no-collector.netclass",
Expand Down Expand Up @@ -3557,6 +3559,38 @@ nodeExporter:
"--collector.systemd.unit-include=^(network.+|nss.+)$"},
argsAbsent: []string{"--no-collector.systemd"},
},
{
name: "disable sysctl collector",
config: `
nodeExporter:
collectors:
sysctl:
enabled: false
`,
argsPresent: []string{"--no-collector.sysctl"},
argsAbsent: []string{"--collector.sysctl"},
},
{
name: "enable sysctl collector",
config: `
nodeExporter:
collectors:
sysctl:
enabled: true
includeSysctlMetrics:
- net.ipv4.tcp_rmem:min,default,max
- net.ipv4.tcp_mem
includeInfoSysctlMetrics:
- kernel.core_pattern
- kernel.seccomp.actions_avail
`,
argsPresent: []string{"--collector.sysctl",
"--collector.sysctl.include=net.ipv4.tcp_rmem:min,default,max",
"--collector.sysctl.include=net.ipv4.tcp_mem",
"--collector.sysctl.include-info=kernel.core_pattern",
"--collector.sysctl.include-info=kernel.seccomp.actions_avail"},
argsAbsent: []string{"--no-collector.sysctl"},
},
}

for _, test := range tests {
Expand Down
15 changes: 15 additions & 0 deletions pkg/manifests/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ type NodeExporterCollectorConfig struct {
// Defines the configuration of the `processes` collector, which collects statistics from processes and threads running in the system.
// Disabled by default.
Processes NodeExporterCollectorProcessesConfig `json:"processes,omitempty"`
// Defines the configuration of the `sysctl` collector, which collects sysctl metrics.
// Disabled by default.
Sysctl NodeExporterCollectorSysctlConfig `json:"sysctl,omitempty"`
// Defines the configuration of the `systemd` collector, which collects statistics on the systemd daemon and its managed services.
// Disabled by default.
Systemd NodeExporterCollectorSystemdConfig `json:"systemd,omitempty"`
Expand All @@ -376,6 +379,18 @@ type NodeExporterCollectorTcpStatConfig struct {
Enabled bool `json:"enabled,omitempty"`
}

// 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.
type NodeExporterCollectorSysctlConfig struct {
// A Boolean flag that enables or disables the `sysctl` collector.
Enabled bool `json:"enabled,omitempty"`
// A list of numeric sysctl values.
IncludeSysctlMetrics *[]string `json:"includeSysctlMetrics,omitempty"`
// 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.
IncludeInfoSysctlMetrics *[]string `json:"includeInfoSysctlMetrics,omitempty"`
}

// The `NodeExporterCollectorNetDevConfig` resource works as an on/off switch for
// the `netdev` collector of the `node-exporter` agent.
// By default, the `netdev` collector is enabled.
Expand Down

0 comments on commit b5f423f

Please sign in to comment.