diff --git a/REFERENCE.md b/REFERENCE.md index b40528da..9926731c 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -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) @@ -7821,6 +7821,8 @@ Data type: `String[1]` The binary release version +Default value: `'1.8.1'` + ##### `env_vars` Data type: `Hash[String[1], Scalar]` @@ -7869,6 +7871,15 @@ Unless empty the content of the web-config yaml which will handed over as option Default value: `{}` +##### `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` + ##### `scrape_host` Data type: `Optional[Stdlib::Host]` @@ -7885,14 +7896,6 @@ Data type: `Boolean` Default value: `false` -##### `scrape_port` - -Data type: `Stdlib::Port` - - - -Default value: `9100` - ##### `scrape_job_name` Data type: `String[1]` diff --git a/data/defaults.yaml b/data/defaults.yaml index 55e99a6c..018073ed 100644 --- a/data/defaults.yaml +++ b/data/defaults.yaml @@ -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: '' diff --git a/manifests/node_exporter.pp b/manifests/node_exporter.pp index 81856f45..755763ea 100644 --- a/manifests/node_exporter.pp +++ b/manifests/node_exporter.pp @@ -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, @@ -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, @@ -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: diff --git a/spec/classes/node_exporter_spec.rb b/spec/classes/node_exporter_spec.rb index 6eac024a..3f0b8c5b 100644 --- a/spec/classes/node_exporter_spec.rb +++ b/spec/classes/node_exporter_spec.rb @@ -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