Skip to content

Commit

Permalink
feat: add --web.listen-address flag to node_exporter if the scrap por…
Browse files Browse the repository at this point in the history
…t is changed

fixes #708
  • Loading branch information
TheMeier committed Aug 15, 2024
1 parent 8a77d48 commit aa55bf7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
21 changes: 12 additions & 9 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7619,9 +7619,9 @@ The following parameters are available in the `prometheus::node_exporter` class:
* [`proxy_type`](#-prometheus--node_exporter--proxy_type)
* [`web_config_file`](#-prometheus--node_exporter--web_config_file)
* [`web_config_content`](#-prometheus--node_exporter--web_config_content)
* [`scrape_port`](#-prometheus--node_exporter--scrape_port)
* [`scrape_host`](#-prometheus--node_exporter--scrape_host)
* [`export_scrape_job`](#-prometheus--node_exporter--export_scrape_job)
* [`scrape_port`](#-prometheus--node_exporter--scrape_port)
* [`scrape_job_name`](#-prometheus--node_exporter--scrape_job_name)
* [`scrape_job_labels`](#-prometheus--node_exporter--scrape_job_labels)
* [`bin_name`](#-prometheus--node_exporter--bin_name)
Expand Down Expand Up @@ -7821,6 +7821,8 @@ Data type: `String[1]`

The binary release version

Default value: `'1.8.1'`

##### <a name="-prometheus--node_exporter--env_vars"></a>`env_vars`

Data type: `Hash[String[1], Scalar]`
Expand Down Expand Up @@ -7869,6 +7871,15 @@ Unless empty the content of the web-config yaml which will handed over as option

Default value: `{}`

##### <a name="-prometheus--node_exporter--scrape_port"></a>`scrape_port`

Data type: `Stdlib::Port`

Scrape port for configuring scrape targets on the prometheus server via exported `prometheus::scrape_job` resources
If changed from default 9100 the option `--web.listen-address=':${scrape_port}'` will be added to the exporter

Default value: `9100`

##### <a name="-prometheus--node_exporter--scrape_host"></a>`scrape_host`

Data type: `Optional[Stdlib::Host]`
Expand All @@ -7885,14 +7896,6 @@ Data type: `Boolean`

Default value: `false`

##### <a name="-prometheus--node_exporter--scrape_port"></a>`scrape_port`

Data type: `Stdlib::Port`



Default value: `9100`

##### <a name="-prometheus--node_exporter--scrape_job_name"></a>`scrape_job_name`

Data type: `String[1]`
Expand Down
2 changes: 0 additions & 2 deletions data/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ prometheus::node_exporter::group: 'node-exporter'
prometheus::node_exporter::package_ensure: 'latest'
prometheus::node_exporter::package_name: 'node_exporter'
prometheus::node_exporter::user: 'node-exporter'
# renovate: depName=prometheus/node_exporter
prometheus::node_exporter::version: '1.8.1'
prometheus::beanstalkd_exporter::exporter_listen: ':9371'
prometheus::beanstalkd_exporter::beanstalkd_address: '127.0.0.1:11300'
prometheus::beanstalkd_exporter::download_extension: ''
Expand Down
12 changes: 11 additions & 1 deletion manifests/node_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
# Path of file where the web-config will be saved to
# @param web_config_content
# Unless empty the content of the web-config yaml which will handed over as option to the exporter
# @param scrape_port
# Scrape port for configuring scrape targets on the prometheus server via exported `prometheus::scrape_job` resources
# If changed from default 9100 the option `--web.listen-address=':${scrape_port}'` will be added to the command line arguments
class prometheus::node_exporter (
String $download_extension,
Prometheus::Uri $download_url_base,
Expand All @@ -74,7 +77,8 @@
String[1] $package_ensure,
String[1] $package_name,
String[1] $user,
String[1] $version,
# renovate: depName=prometheus/node_exporter
String[1] $version = '1.8.1',
Boolean $purge_config_dir = true,
Boolean $restart_on_change = true,
Boolean $service_enable = true,
Expand Down Expand Up @@ -156,11 +160,17 @@
}
}

if $scrape_port != 9100 {
$listen_address = "--web.listen-address=':${scrape_port}'"
} else {
$listen_address = ''
}
$options = [
$extra_options,
$cmd_collectors_enable.join(' '),
$cmd_collectors_disable.join(' '),
$_web_config,
$listen_address,
].filter |$x| { !$x.empty }.join(' ')

prometheus::daemon { $service_name:
Expand Down
16 changes: 16 additions & 0 deletions spec/classes/node_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,22 @@
it { is_expected.to contain_prometheus__daemon('node_exporter').with(options: '--web.config.file=/etc/node_exporter_web-config.yml') }
end
end

context 'with non default scrape port' do
let(:params) do
{
scrape_port: 9101
}
end

it { is_expected.to compile.with_all_deps }

if facts[:os]['name'] == 'Archlinux'
it { is_expected.to contain_prometheus__daemon('prometheus-node-exporter').with(options: '--web.listen-address=\':9101\'') }
else
it { is_expected.to contain_prometheus__daemon('node_exporter').with(options: '--web.listen-address=\':9101\'') }
end
end
end
end
end

0 comments on commit aa55bf7

Please sign in to comment.