Skip to content

Commit

Permalink
Merge pull request #693 from pixelpark/rework_web_config_support
Browse files Browse the repository at this point in the history
Rework web-config support for multiple exporters
  • Loading branch information
rwaffen authored Nov 17, 2023
2 parents 443d1ca + f6e42ad commit eb76304
Show file tree
Hide file tree
Showing 21 changed files with 813 additions and 294 deletions.
415 changes: 236 additions & 179 deletions REFERENCE.md

Large diffs are not rendered by default.

42 changes: 39 additions & 3 deletions manifests/apache_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
# Optional proxy server, with port number if needed. ie: https://example.com:8080
# @param proxy_type
# Optional proxy server type (none|http|https|ftp)
# @param web_config_file
# 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
class prometheus::apache_exporter (
String[1] $scrape_uri = 'http://localhost/server-status/?auto',
String $download_extension = 'tar.gz',
Expand Down Expand Up @@ -86,6 +90,8 @@
Optional[Hash] $scrape_job_labels = undef,
Optional[String[1]] $proxy_server = undef,
Optional[Enum['none', 'http', 'https', 'ftp']] $proxy_type = undef,
Stdlib::Absolutepath $web_config_file = '/etc/apache_exporter_web-config.yml',
Prometheus::Web_config $web_config_content = {},
) inherits prometheus {
#Please provide the download_url for versions < 0.9.0
$real_download_url = pick($download_url,"${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}")
Expand All @@ -94,12 +100,42 @@
default => undef,
}

if versioncmp($version, '0.8.0') < 0 {
$options = "-scrape_uri '${scrape_uri}' ${extra_options}"
$_web_config_ensure = $web_config_content.empty ? {
true => absent,
default => file,
}

file { $web_config_file:
ensure => $_web_config_ensure,
owner => $user,
group => $group,
mode => '0640',
content => $web_config_content.stdlib::to_yaml,
notify => $notify_service,
}

$_web_config = if $web_config_content.empty {
''
} else {
$options = "--scrape_uri '${scrape_uri}' ${extra_options}"
if versioncmp($version, '1.0.0') >= 0 {
"--web.config.file=${$web_config_file}"
} else {
"--web.config=${$web_config_file}"
}
}

$_scrape_uri = if versioncmp($version, '0.8.0') < 0 {
"-scrape_uri '${scrape_uri}'"
} else {
"--scrape_uri '${scrape_uri}'"
}

$options = [
$_scrape_uri,
$extra_options,
$_web_config,
].filter |$x| { !$x.empty }.join(' ')

prometheus::daemon { $service_name:
install_method => $install_method,
version => $version,
Expand Down
41 changes: 35 additions & 6 deletions manifests/blackbox_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
# Optional proxy server, with port number if needed. ie: https://example.com:8080
# @param proxy_type
# Optional proxy server type (none|http|https|ftp)
# @param web_config_file
# 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
# @example Example for configuring named blackbox modules via hiera
# prometheus::blackbox_exporter::modules:
# simple_ssl:
Expand Down Expand Up @@ -108,21 +112,46 @@
Optional[Hash] $scrape_job_labels = undef,
Optional[String[1]] $proxy_server = undef,
Optional[Enum['none', 'http', 'https', 'ftp']] $proxy_type = undef,
Stdlib::Absolutepath $web_config_file = '/etc/blackbox_exporter_web-config.yml',
Prometheus::Web_config $web_config_content = {},
) inherits prometheus {
# Prometheus added a 'v' on the release name at 0.1.0 of blackbox
if versioncmp ($version, '0.1.0') >= 0 {
$release = "v${version}"
}
else {
$release = $version
$release = if versioncmp ($version, '0.1.0') >= 0 {
"v${version}"
} else {
$version
}
$real_download_url = pick($download_url,"${download_url_base}/download/${release}/${package_name}-${version}.${os}-${arch}.${download_extension}")
$notify_service = $restart_on_change ? {
true => Service[$service_name],
default => undef,
}

$options = "--config.file=${config_file} ${extra_options}"
$_web_config_ensure = $web_config_content.empty ? {
true => absent,
default => file,
}

file { $web_config_file:
ensure => $_web_config_ensure,
owner => $user,
group => $group,
mode => '0640',
content => $web_config_content.stdlib::to_yaml,
notify => $notify_service,
}

$_web_config = if $web_config_content.empty {
''
} else {
"--web.config.file=${$web_config_file}"
}

$options = [
"--config.file=${config_file}",
$extra_options,
$_web_config,
].filter |$x| { !$x.empty }.join(' ')

file { $config_file:
ensure => file,
Expand Down
45 changes: 44 additions & 1 deletion manifests/elasticsearch_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
# Should puppet manage the service? (default true)
# @param manage_user
# Whether to create user or rely on external code for that
# @param export_scrape_job
# Whether to export a scrape job for this service
# @param scrape_host
# Hostname or IP address to scrape
# @param scrape_port
# Host port to scrape
# @param scrape_job_name
# Name of the scrape job to export, if export_scrape_job is true
# @param scrape_job_labels
# Labels to add to the scrape job, if export_scrape_job is true
# @param os
# Operating system (linux is the only one supported)
# @param package_ensure
Expand All @@ -43,6 +53,8 @@
# Whether to enable the service from puppet (default true)
# @param service_ensure
# State ensured for the service (default 'running')
# @param service_name
# Name of the node exporter service
# @param user
# User which runs the service
# @param version
Expand All @@ -55,6 +67,10 @@
# Optional proxy server, with port number if needed. ie: https://example.com:8080
# @param proxy_type
# Optional proxy server type (none|http|https|ftp)
# @param web_config_file
# 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
class prometheus::elasticsearch_exporter (
String[1] $cnf_uri,
String[1] $cnf_timeout,
Expand Down Expand Up @@ -89,6 +105,8 @@
Optional[Hash] $scrape_job_labels = undef,
Optional[String[1]] $proxy_server = undef,
Optional[Enum['none', 'http', 'https', 'ftp']] $proxy_type = undef,
Stdlib::Absolutepath $web_config_file = '/etc/elasticsearch_exporter_web-config.yml',
Prometheus::Web_config $web_config_content = {},
) inherits prometheus {
#Please provide the download_url for versions < 0.9.0
$real_download_url = pick($download_url,"${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}")
Expand All @@ -103,7 +121,32 @@
false => '-',
}

$options = "${flag_prefix}es.uri=${cnf_uri} ${flag_prefix}es.timeout=${cnf_timeout} ${extra_options}"
$_web_config_ensure = $web_config_content.empty ? {
true => absent,
default => file,
}

file { $web_config_file:
ensure => $_web_config_ensure,
owner => $user,
group => $group,
mode => '0640',
content => $web_config_content.stdlib::to_yaml,
notify => $notify_service,
}

$_web_config = if $web_config_content.empty {
''
} else {
"${flag_prefix}web.config.file=${$web_config_file}"
}

$options = [
"${flag_prefix}es.uri=${cnf_uri}",
"${flag_prefix}es.timeout=${cnf_timeout}",
$extra_options,
$_web_config,
].filter |$x| { !$x.empty }.join(' ')

prometheus::daemon { 'elasticsearch_exporter':
install_method => $install_method,
Expand Down
32 changes: 31 additions & 1 deletion manifests/haproxy_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
# Optional proxy server, with port number if needed. ie: https://example.com:8080
# @param proxy_type
# Optional proxy server type (none|http|https|ftp)
# @param web_config_file
# 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
class prometheus::haproxy_exporter (
Variant[Stdlib::HTTPUrl, Pattern[/unix:(?:\/.+)+/]] $cnf_scrape_uri,
String $download_extension,
Expand Down Expand Up @@ -83,14 +87,40 @@
Optional[Hash] $scrape_job_labels = undef,
Optional[String[1]] $proxy_server = undef,
Optional[Enum['none', 'http', 'https', 'ftp']] $proxy_type = undef,
Stdlib::Absolutepath $web_config_file = '/etc/haproxy_exporter_web-config.yml',
Prometheus::Web_config $web_config_content = {},
) inherits prometheus {
$real_download_url = pick($download_url,"${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}")
$notify_service = $restart_on_change ? {
true => Service[$service_name],
default => undef,
}

$options = "--haproxy.scrape-uri=\"${cnf_scrape_uri}\" ${extra_options}"
$_web_config_ensure = $web_config_content.empty ? {
true => absent,
default => file,
}

file { $web_config_file:
ensure => $_web_config_ensure,
owner => $user,
group => $group,
mode => '0640',
content => $web_config_content.stdlib::to_yaml,
notify => $notify_service,
}

$_web_config = if $web_config_content.empty {
''
} else {
"--web.config.file=${$web_config_file}"
}

$options = [
"--haproxy.scrape-uri=\"${cnf_scrape_uri}\"",
$extra_options,
$_web_config,
].filter |$x| { !$x.empty }.join(' ')

prometheus::daemon { $service_name:
install_method => $install_method,
Expand Down
38 changes: 35 additions & 3 deletions manifests/mysqld_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
# Optional proxy server, with port number if needed. ie: https://example.com:8080
# @param proxy_type
# Optional proxy server type (none|http|https|ftp)
# @param web_config_file
# 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
class prometheus::mysqld_exporter (
String $download_extension,
Prometheus::Uri $download_url_base,
Expand Down Expand Up @@ -102,6 +106,8 @@
Optional[Hash] $scrape_job_labels = undef,
Optional[String[1]] $proxy_server = undef,
Optional[Enum['none', 'http', 'https', 'ftp']] $proxy_type = undef,
Stdlib::Absolutepath $web_config_file = '/etc/mysqld_exporter_web-config.yml',
Prometheus::Web_config $web_config_content = {},
) inherits prometheus {
#Please provide the download_url for versions < 0.9.0
$real_download_url = pick($download_url,"${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}")
Expand Down Expand Up @@ -130,11 +136,37 @@
notify => $notify_service,
}

if versioncmp($version, '0.11.0') < 0 {
$options = "-config.my-cnf=${cnf_config_path} ${extra_options}"
$_web_config_ensure = $web_config_content.empty ? {
true => absent,
default => file,
}

file { $web_config_file:
ensure => $_web_config_ensure,
owner => $user,
group => $group,
mode => '0640',
content => $web_config_content.stdlib::to_yaml,
notify => $notify_service,
}

$_web_config = if $web_config_content.empty {
''
} else {
"--web.config.file=${$web_config_file}"
}
$_config_myconf = if versioncmp($version, '0.11.0') < 0 {
"-config.my-cnf=${cnf_config_path}"
} else {
$options = "--config.my-cnf=${cnf_config_path} ${extra_options}"
"--config.my-cnf=${cnf_config_path}"
}

$options = [
$_config_myconf,
$extra_options,
$_web_config,
].filter |$x| { !$x.empty }.join(' ')

prometheus::daemon { 'mysqld_exporter':
install_method => $install_method,
version => $version,
Expand Down
Loading

0 comments on commit eb76304

Please sign in to comment.