From 79302a732485dc0c81d01604027fef719f3e7a29 Mon Sep 17 00:00:00 2001 From: Luke Swithenbank Date: Tue, 27 Dec 2016 20:52:08 +1100 Subject: [PATCH] Add Statsd Exporter, Mysqld Exporter, make exporters generic (#27) * add a statsd_exporter * update templates * :update to use a template * fix bug * migrate to using generic service configurations * update node_exporter * update to just daemon * move node_exporter to use a generic daemon * move the statsd_exporter and alert_manager to generic daemon install * update to make the daemon a resource * update * add mysqld_exporter * update default params * update to use different users * update to use newer version of node_exporter fix mysqld_exporter my.cnf location * update systemd daemon * update to use alertmanager instead of alert_manager * update template filename * update version so that alertmanager breaking changes are known * update from review * update systemd files * update readme * the service should be restarted when the configuration is updated * fix bug in params * fix sorting of an array of hashes * add a lockfile for Gems * update documentation and sort params alphabetically * add some tests * add .gitignore file * remove Gemfile.lock * remove fixture modules * fix comments * shellescape options variable * update statsd template * Fixed daemon.systemd template; fixed duplicate definitions of and in daemon.pp; fixed duplicate definition of in alertmanager.pp * Fixed daemon upstart script * Changed statsd mapping code for ruby 1.8.7 compatibility --- .gitignore | 2 + README.md | 4 +- files/statsd_mapping.conf | 12 + manifests/alert_manager.pp | 141 ---------- manifests/alert_manager/config.pp | 93 ------- manifests/alert_manager/install.pp | 74 ------ manifests/alert_manager/run_service.pp | 20 -- manifests/alertmanager.pp | 240 ++++++++++++++++++ manifests/daemon.pp | 165 ++++++++++++ manifests/mysqld_exporter.pp | 168 ++++++++++++ manifests/node_exporter.pp | 172 +++++++------ manifests/node_exporter/config.pp | 76 ------ manifests/node_exporter/install.pp | 66 ----- manifests/node_exporter/run_service.pp | 20 -- manifests/params.pp | 90 ++++--- manifests/statsd_exporter.pp | 156 ++++++++++++ metadata.json | 4 +- ...-version_spec.rb => node_exporter_spec.rb} | 28 +- spec/classes/statsd_exporter_spec.rb | 0 spec/defines/daemon_spec.rb | 68 +++++ spec/fixtures/manifests/site.pp | 0 templates/alert_manager.debian.erb | 173 ------------- templates/alert_manager.launchd.erb | 29 --- templates/alert_manager.sles.erb | 99 -------- templates/alert_manager.systemd.erb | 18 -- templates/alert_manager.sysv.erb | 125 --------- templates/alert_manager.upstart.erb | 31 --- templates/alert_manager.yaml.erb | 8 - templates/alertmanager.yaml.erb | 8 + ..._exporter.debian.erb => daemon.debian.erb} | 25 +- templates/daemon.launchd.erb | 24 ++ ...node_exporter.sles.erb => daemon.sles.erb} | 33 +-- templates/daemon.systemd.erb | 20 ++ ...node_exporter.sysv.erb => daemon.sysv.erb} | 49 ++-- templates/daemon.upstart.erb | 34 +++ templates/my.cnf.erb | 9 + templates/node_exporter.launchd.erb | 27 -- templates/node_exporter.systemd.erb | 17 -- templates/node_exporter.upstart.erb | 31 --- templates/statsd_mapping.conf.erb | 7 + tests/init.pp | 3 +- 41 files changed, 1138 insertions(+), 1231 deletions(-) create mode 100644 .gitignore create mode 100644 files/statsd_mapping.conf delete mode 100644 manifests/alert_manager.pp delete mode 100644 manifests/alert_manager/config.pp delete mode 100644 manifests/alert_manager/install.pp delete mode 100644 manifests/alert_manager/run_service.pp create mode 100644 manifests/alertmanager.pp create mode 100644 manifests/daemon.pp create mode 100644 manifests/mysqld_exporter.pp delete mode 100644 manifests/node_exporter/config.pp delete mode 100644 manifests/node_exporter/install.pp delete mode 100644 manifests/node_exporter/run_service.pp create mode 100644 manifests/statsd_exporter.pp rename spec/classes/{node_exporter-version_spec.rb => node_exporter_spec.rb} (50%) create mode 100644 spec/classes/statsd_exporter_spec.rb create mode 100644 spec/defines/daemon_spec.rb create mode 100644 spec/fixtures/manifests/site.pp delete mode 100644 templates/alert_manager.debian.erb delete mode 100644 templates/alert_manager.launchd.erb delete mode 100644 templates/alert_manager.sles.erb delete mode 100644 templates/alert_manager.systemd.erb delete mode 100644 templates/alert_manager.sysv.erb delete mode 100644 templates/alert_manager.upstart.erb delete mode 100644 templates/alert_manager.yaml.erb create mode 100644 templates/alertmanager.yaml.erb rename templates/{node_exporter.debian.erb => daemon.debian.erb} (84%) create mode 100644 templates/daemon.launchd.erb rename templates/{node_exporter.sles.erb => daemon.sles.erb} (66%) create mode 100644 templates/daemon.systemd.erb rename templates/{node_exporter.sysv.erb => daemon.sysv.erb} (56%) create mode 100644 templates/daemon.upstart.erb create mode 100644 templates/my.cnf.erb delete mode 100644 templates/node_exporter.launchd.erb delete mode 100644 templates/node_exporter.systemd.erb delete mode 100644 templates/node_exporter.upstart.erb create mode 100644 templates/statsd_mapping.conf.erb diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..1612d7f11 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Gemfile.lock +spec/fixtures/modules/* diff --git a/README.md b/README.md index e562856e6..338cb0bd2 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ This module automates the install and configuration of Prometheus monitoring too * Installs the prometheus daemon, alertmanager or exporters(via url or package) * The package method was implemented, but currently there isn't any package for prometheus -* Optionally installs a user to run it under +* Optionally installs a user to run it under (per exporter) * Installs a configuration file for prometheus daemon (/etc/prometheus/prometheus.yaml) or for alertmanager (/etc/prometheus/alert.rules) * Manages the services via upstart, sysv, or systemd * Optionally creates alert rules @@ -105,6 +105,8 @@ For more information regarding class parameters please take a look at class docs ## Limitations/Known issues +In version 0.1.14 of this module the alertmanager was configured to run as the service `alert_manager`. This has been changed in version 0.2.00 to be `alertmanager`. + Do not use version 1.0.0 of Prometheus: https://groups.google.com/forum/#!topic/prometheus-developers/vuSIxxUDff8 ; it does break the compatibility with thus module! Even if the module has templates for several linux distributions, only RH family distributions were tested. diff --git a/files/statsd_mapping.conf b/files/statsd_mapping.conf new file mode 100644 index 000000000..f0959b581 --- /dev/null +++ b/files/statsd_mapping.conf @@ -0,0 +1,12 @@ +test.dispatcher.*.*.* +name="dispatcher_events_total" +processor="$1" +action="$2" +outcome="$3" +job="test_dispatcher" + +*.signup.*.* +name="signup_events_total" +provider="$2" +outcome="$3" +job="${1}_server" diff --git a/manifests/alert_manager.pp b/manifests/alert_manager.pp deleted file mode 100644 index c20ae4851..000000000 --- a/manifests/alert_manager.pp +++ /dev/null @@ -1,141 +0,0 @@ -# Class: prometheus::alert_manager -# -# This module manages prometheus alert_manager -# -# Parameters: -# -# [*manage_user*] -# Whether to create user for prometheus or rely on external code for that -# -# [*user*] -# User running prometheus -# -# [*manage_group*] -# Whether to create user for prometheus or rely on external code for that -# -# [*purge_config_dir*] -# Purge config files no longer generated by Puppet -# -# [*group*] -# Group under which prometheus is running -# -# [*bin_dir*] -# Directory where binaries are located -# -# [*arch*] -# Architecture (amd64 or i386) -# -# [*version*] -# Prometheus alert_manager release -# -# [*install_method*] -# Installation method: url or package (only url is supported currently) -# -# [*os*] -# Operating system (linux is the only one supported) -# -# [*download_url*] -# Complete URL corresponding to the Prometheus alert_manager release, default to undef -# -# [*download_url_base*] -# Base URL for prometheus alert_manager -# -# [*download_extension*] -# Extension of Prometheus alert_manager binaries archive -# -# [*package_name*] -# Prometheus alert_manager package name - not available yet -# -# [*package_ensure*] -# If package, then use this for package ensure default 'latest' -# -# [*config_file*] -# The configuration file for alert manager (it should be under $prometheus::config_dir directory, it depends on it) -# -# [*extra_options*] -# Extra options added to prometheus startup command -# -# [*service_enable*] -# Whether to enable or not prometheus alert_manager service from puppet (default true) -# -# [*service_ensure*] -# State ensured from prometheus alert_manager service (default 'running') -# -# [*manage_service*] -# Should puppet manage the prometheus alert_manager service? (default true) -# -# [*restart_on_change*] -# Should puppet restart prometheus alert_manager on configuration change? (default true) -# -# [*init_style*] -# Service startup scripts style (e.g. rc, upstart or systemd) -# -# Actions: -# -# Requires: see Modulefile -# -# Sample Usage: -# -class prometheus::alert_manager ( - $manage_user = true, - $user = $::prometheus::params::user, - $manage_group = true, - $purge_config_dir = true, - $group = $::prometheus::params::group, - $bin_dir = $::prometheus::params::bin_dir, - $arch = $::prometheus::params::arch, - $version = $::prometheus::params::alert_manager_version, - $install_method = $::prometheus::params::install_method, - $os = $::prometheus::params::os, - $download_url = undef, - $download_url_base = $::prometheus::params::alert_manager_download_url_base, - $download_extension = $::prometheus::params::alert_manager_download_extension, - $package_name = $::prometheus::params::alert_manager_package_name, - $package_ensure = $::prometheus::params::alert_manager_package_ensure, - $storage_path = $::prometheus::params::alert_manager_storage_path, - $config_dir = $::prometheus::params::alert_manager_config_dir, - $config_file = $::prometheus::params::alert_manager_config_file, - $global = $::prometheus::params::alert_manager_global, - $route = $::prometheus::params::alert_manager_route, - $receivers = $::prometheus::params::alert_manager_receivers, - $templates = $::prometheus::params::alert_manager_templates, - $inhibit_rules = $::prometheus::params::alert_manager_inhibit_rules, - $extra_options = '', - $config_mode = $::prometheus::params::config_mode, - $service_enable = true, - $service_ensure = 'running', - $manage_service = true, - $restart_on_change = true, - $init_style = $::prometheus::params::init_style, -) inherits prometheus::params { - if( versioncmp($::prometheus::alert_manager::version, '0.3.0') == -1 ){ - $real_download_url = pick($download_url, - "${download_url_base}/download/${version}/${package_name}-${version}.${os}-${arch}.${download_extension}") - } else { - $real_download_url = pick($download_url, - "${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}") - } - validate_bool($purge_config_dir) - validate_bool($manage_user) - validate_bool($manage_service) - validate_bool($restart_on_change) - validate_array($templates) - validate_array($receivers) - validate_array($inhibit_rules) - validate_hash($global) - validate_hash($route) - $notify_service = $restart_on_change ? { - true => Class['::prometheus::alert_manager::run_service'], - default => undef, - } - - anchor {'alert_manager_first': } - -> - class { '::prometheus::alert_manager::install': } -> - class { '::prometheus::alert_manager::config': - purge => $purge_config_dir, - notify => $notify_service, - } -> - class { '::prometheus::alert_manager::run_service': } -> - anchor {'alert_manager_last': } -} diff --git a/manifests/alert_manager/config.pp b/manifests/alert_manager/config.pp deleted file mode 100644 index 1ad1b705f..000000000 --- a/manifests/alert_manager/config.pp +++ /dev/null @@ -1,93 +0,0 @@ -# Class prometheus::alert_manager::config -# Configuration class for prometheus node exporter -class prometheus::alert_manager::config( - $purge = true, -) { - - if $prometheus::alert_manager::init_style { - - case $prometheus::alert_manager::init_style { - 'upstart' : { - file { '/etc/init/alert_manager.conf': - mode => '0444', - owner => 'root', - group => 'root', - content => template('prometheus/alert_manager.upstart.erb'), - } - file { '/etc/init.d/alert_manager': - ensure => link, - target => '/lib/init/upstart-job', - owner => 'root', - group => 'root', - mode => '0755', - } - } - 'systemd' : { - file { '/lib/systemd/system/alert_manager.service': - mode => '0644', - owner => 'root', - group => 'root', - content => template('prometheus/alert_manager.systemd.erb'), - }~> - exec { 'alert_manager-systemd-reload': - command => 'systemctl daemon-reload', - path => [ '/usr/bin', '/bin', '/usr/sbin' ], - refreshonly => true, - } - } - 'sysv' : { - file { '/etc/init.d/alert_manager': - mode => '0555', - owner => 'root', - group => 'root', - content => template('prometheus/alert_manager.sysv.erb') - } - } - 'debian' : { - file { '/etc/init.d/alert_manager': - mode => '0555', - owner => 'root', - group => 'root', - content => template('prometheus/alert_manager.debian.erb') - } - } - 'sles' : { - file { '/etc/init.d/alert_manager': - mode => '0555', - owner => 'root', - group => 'root', - content => template('prometheus/alert_manager.sles.erb') - } - } - 'launchd' : { - file { '/Library/LaunchDaemons/io.alert_manager.daemon.plist': - mode => '0644', - owner => 'root', - group => 'wheel', - content => template('prometheus/alert_manager.launchd.erb') - } - } - default : { - fail("I don't know how to create an init script for style ${prometheus::alert_manager::init_style}") - } - } - } - - file { $prometheus::alert_manager::config_dir: - ensure => 'directory', - owner => $prometheus::alert_manager::user, - group => $prometheus::alert_manager::group, - purge => $purge, - recurse => $purge, - } - - file { $prometheus::alert_manager::config_file: - ensure => present, - owner => $prometheus::alert_manager::user, - group => $prometheus::alert_manager::group, - mode => $prometheus::alert_manager::config_mode, - content => template('prometheus/alert_manager.yaml.erb'), - require => File[$prometheus::alert_manager::config_dir], - } - -} diff --git a/manifests/alert_manager/install.pp b/manifests/alert_manager/install.pp deleted file mode 100644 index e36f62dd1..000000000 --- a/manifests/alert_manager/install.pp +++ /dev/null @@ -1,74 +0,0 @@ -# Class prometheus::alert_manager::install -# Install prometheus node alert_manager via different methods with parameters from init -# Currently only the install from url is implemented, when Prometheus will deliver packages for some Linux distros I will -# implement the package install method as well -# The package method needs specific yum or apt repo settings which are not made yet by the module -class prometheus::alert_manager::install -{ - if $::prometheus::alert_manager::storage_path - { - file { $::prometheus::alert_manager::storage_path: - ensure => 'directory', - owner => $::prometheus::alert_manager::user, - group => $::prometheus::alert_manager::group, - mode => '0755', - } - } - case $::prometheus::alert_manager::install_method { - 'url': { - include staging - $staging_file = "alert_manager-${prometheus::alert_manager::version}.${prometheus::alert_manager::download_extension}" - if( versioncmp($::prometheus::alert_manager::version, '0.1.0') == -1 ){ - $binary = "${::staging::path}/alertmanager-${::prometheus::alert_manager::version}.${::prometheus::alert_manager::os}-${::prometheus::alert_manager::arch}" - } else { - $binary = "${::staging::path}/alertmanager-${::prometheus::alert_manager::version}.${::prometheus::alert_manager::os}-${::prometheus::alert_manager::arch}/alertmanager" - } - staging::file { $staging_file: - source => $prometheus::alert_manager::real_download_url, - } -> - staging::extract { $staging_file: - target => $::staging::path, - creates => $binary, - } -> - file { - $binary: - owner => 'root', - group => 0, # 0 instead of root because OS X uses "wheel". - mode => '0555'; - "${::prometheus::alert_manager::bin_dir}/alert_manager": - ensure => link, - notify => $::prometheus::alert_manager::notify_service, - target => $binary, - } - } - 'package': { - package { $::prometheus::alert_manager::package_name: - ensure => $::prometheus::alert_manager::package_ensure, - } - if $::prometheus::alert_manager::manage_user { - User[$::prometheus::alert_manager::user] -> Package[$::prometheus::alert_manager::package_name] - } - } - 'none': {} - default: { - fail("The provided install method ${::prometheus::install_method} is invalid") - } - } - if $::prometheus::alert_manager::manage_user { - ensure_resource('user', [ $::prometheus::alert_manager::user ], { - ensure => 'present', - system => true, - groups => $::prometheus::alert_manager::extra_groups, - }) - - if $::prometheus::alert_manager::manage_group { - Group[$::prometheus::alert_manager::group] -> User[$::prometheus::alert_manager::user] - } - } - if $::prometheus::alert_manager::manage_group { - ensure_resource('group', [ $::prometheus::alert_manager::group ], { - ensure => 'present', - system => true, - }) - } -} diff --git a/manifests/alert_manager/run_service.pp b/manifests/alert_manager/run_service.pp deleted file mode 100644 index 0a483234e..000000000 --- a/manifests/alert_manager/run_service.pp +++ /dev/null @@ -1,20 +0,0 @@ -# == Class prometheus::alert_manager::service -# -# This class is meant to be called from prometheus::alert_manager -# It ensure the alert_manager service is running -# -class prometheus::alert_manager::run_service { - - $init_selector = $prometheus::alert_manager::init_style ? { - 'launchd' => 'io.alert_manager.daemon', - default => 'alert_manager', - } - - if $prometheus::alert_manager::manage_service == true { - service { 'alert_manager': - ensure => $prometheus::alert_manager::service_ensure, - name => $init_selector, - enable => $prometheus::alert_manager::service_enable, - } - } -} diff --git a/manifests/alertmanager.pp b/manifests/alertmanager.pp new file mode 100644 index 000000000..5e6b4be21 --- /dev/null +++ b/manifests/alertmanager.pp @@ -0,0 +1,240 @@ +# Class: prometheus::alertmanager +# +# This module manages prometheus alertmanager +# +# Parameters: +# [*arch*] +# Architecture (amd64 or i386) +# +# [*bin_dir*] +# Directory where binaries are located +# +# [*config_file*] +# The path to put the configuration file +# +# [*config_mode*] +# The permissions of the configuration files +# +# [*download_extension*] +# Extension for the release binary archive +# +# [*download_url*] +# Complete URL corresponding to the where the release binary archive can be downloaded +# +# [*download_url_base*] +# Base URL for the binary archive +# +# [*extra_groups*] +# Extra groups to add the binary user to +# +# [*extra_options*] +# Extra options added to the startup command +# +# [*global*] +# The global alertmanager configuration. +# Example (also default): +# +# prometheus::alertmanager::global: +# smtp_smarthost: 'localhost:25' +# smtp_from: 'alertmanager@localhost' +# +# [*group*] +# Group under which the binary is running +# +# [*inhibit_rules*] +# An array of inhibit rules. +# Example (also default): +# +# prometheus::alertmanager::inhibit_rules: +# - source_match: +# severity: 'critical' +# target_match: +# severity: 'warning' +# equal: +# - 'alertname' +# - 'cluster' +# - 'service' +# +# [*init_style*] +# Service startup scripts style (e.g. rc, upstart or systemd) +# +# [*install_method*] +# Installation method: url or package (only url is supported currently) +# +# [*manage_group*] +# Whether to create a group for or rely on external code for that +# +# [*manage_service*] +# Should puppet manage the service? (default true) +# +# [*manage_user*] +# Whether to create user or rely on external code for that +# +# [*os*] +# Operating system (linux is the only one supported) +# +# [*package_ensure*] +# If package, then use this for package ensure default 'latest' +# +# [*package_name*] +# The binary package name - not available yet +# +# [*purge_config_dir*] +# Purge config files no longer generated by Puppet +# +# [*receivers*] +# An array of receivers. +# Example (also default): +# +# prometheus::alertmanager::receivers: +# - name: 'Admin' +# email_configs: +# - to: 'root@localhost' +# +# [*restart_on_change*] +# Should puppet restart the service on configuration change? (default true) +# +# [*route*] +# The top level route. +# Example (also default): +# +# prometheus::alertmanager::route: +# group_by: +# - 'alertname' +# - 'cluster' +# - 'service' +# group_wait: '30s' +# group_interval: '5m' +# repeat_interval: '3h' +# receiver: 'Admin' +# +# [*service_enable*] +# Whether to enable the service from puppet (default true) +# +# [*service_ensure*] +# State ensured for the service (default 'running') +# +# [*storage_path*] +# The storage path to pass to the alertmanager. Defaults to '/var/lib/alertmanager' +# +# [*templates*] +# The array of template files. Defaults to [ "${config_dir}/*.tmpl" ] +# +# [*user*] +# User which runs the service +# +# [*version*] +# The binary release version +class prometheus::alertmanager ( + $arch = $::prometheus::params::arch, + $bin_dir = $::prometheus::params::bin_dir, + $config_dir = $::prometheus::params::alertmanager_config_dir, + $config_file = $::prometheus::params::alertmanager_config_file, + $config_mode = $::prometheus::params::config_mode, + $download_extension = $::prometheus::params::alertmanager_download_extension, + $download_url = undef, + $download_url_base = $::prometheus::params::alertmanager_download_url_base, + $extra_groups = $::prometheus::params::alertmanager_extra_groups, + $extra_options = '', + $global = $::prometheus::params::alertmanager_global, + $group = $::prometheus::params::alertmanager_group, + $inhibit_rules = $::prometheus::params::alertmanager_inhibit_rules, + $init_style = $::prometheus::params::init_style, + $install_method = $::prometheus::params::install_method, + $manage_group = true, + $manage_service = true, + $manage_user = true, + $os = $::prometheus::params::os, + $package_ensure = $::prometheus::params::alertmanager_package_ensure, + $package_name = $::prometheus::params::alertmanager_package_name, + $purge_config_dir = true, + $receivers = $::prometheus::params::alertmanager_receivers, + $restart_on_change = true, + $route = $::prometheus::params::alertmanager_route, + $service_enable = true, + $service_ensure = 'running', + $storage_path = $::prometheus::params::alertmanager_storage_path, + $templates = $::prometheus::params::alertmanager_templates, + $user = $::prometheus::params::alertmanager_user, + $version = $::prometheus::params::alertmanager_version, +) inherits prometheus::params { + if( versioncmp($::prometheus::alertmanager::version, '0.3.0') == -1 ){ + $real_download_url = pick($download_url, + "${download_url_base}/download/${version}/${package_name}-${version}.${os}-${arch}.${download_extension}") + } else { + $real_download_url = pick($download_url, + "${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}") + } + validate_bool($purge_config_dir) + validate_bool($manage_user) + validate_bool($manage_service) + validate_bool($restart_on_change) + validate_array($templates) + validate_array($receivers) + validate_array($inhibit_rules) + validate_hash($global) + validate_hash($route) + $notify_service = $restart_on_change ? { + true => Service['alertmanager'], + default => undef, + } + + file { $config_dir: + ensure => 'directory', + owner => $user, + group => $group, + purge => $purge_config_dir, + recurse => $purge_config_dir, + } + + file { $config_file: + ensure => present, + owner => $user, + group => $group, + mode => $config_mode, + content => template('prometheus/alertmanager.yaml.erb'), + require => File[$config_dir], + } + + # This is here to stop the previous alertmanager that was installed in version 0.1.14 + service { 'alert_manager': + ensure => 'stopped', + } + + if $storage_path { + file { $storage_path: + ensure => 'directory', + owner => $user, + group => $group, + mode => '0755', + } + + $options = "-config.file=${prometheus::alertmanager::config_file} -storage.path=${prometheus::alertmanager::storage_path} ${prometheus::alertmanager::extra_options}" + } else { + $options = "-config.file=${prometheus::alertmanager::config_file} ${prometheus::alertmanager::extra_options}" + } + + prometheus::daemon { 'alertmanager': + install_method => $install_method, + version => $version, + download_extension => $download_extension, + os => $os, + arch => $arch, + real_download_url => $real_download_url, + bin_dir => $bin_dir, + notify_service => $notify_service, + package_name => $package_name, + package_ensure => $package_ensure, + manage_user => $manage_user, + user => $user, + extra_groups => $extra_groups, + group => $group, + manage_group => $manage_group, + purge => $purge_config_dir, + options => $options, + init_style => $init_style, + service_ensure => $service_ensure, + service_enable => $service_enable, + manage_service => $manage_service, + } +} diff --git a/manifests/daemon.pp b/manifests/daemon.pp new file mode 100644 index 000000000..108a0dbb8 --- /dev/null +++ b/manifests/daemon.pp @@ -0,0 +1,165 @@ +define prometheus::daemon ( + $install_method, + $version, + $download_extension, + $os, + $arch, + $real_download_url, + $bin_dir, + $notify_service, + $package_name, + $package_ensure, + $manage_user, + $user, + $extra_groups, + $group, + $manage_group, + $purge, + $options, + $init_style, + $service_ensure, + $service_enable, + $manage_service, + ) { + case $install_method { + 'url': { + include staging + $staging_file = "${name}-${version}.${download_extension}" + $binary = "${::staging::path}/${name}-${version}.${os}-${arch}/${name}" + staging::file { $staging_file: + source => $real_download_url, + } -> + staging::extract { $staging_file: + target => $::staging::path, + creates => $binary, + } -> + file { $binary: + owner => 'root', + group => 0, # 0 instead of root because OS X uses "wheel". + mode => '0555', + } -> + file { "${bin_dir}/${name}": + ensure => link, + notify => $notify_service, + target => $binary, + } + } + 'package': { + package { $package_name: + ensure => $package_ensure, + } + if $manage_user { + User[$user] -> Package[$package_name] + } + } + 'none': {} + default: { + fail("The provided install method ${install_method} is invalid") + } + } + if $manage_user { + ensure_resource('user', [ $user ], { + ensure => 'present', + system => true, + groups => $extra_groups, + }) + + if $manage_group { + Group[$group] -> User[$user] + } + } + if $manage_group { + ensure_resource('group', [ $group ], { + ensure => 'present', + system => true, + }) + } + + + if $init_style { + + case $init_style { + 'upstart' : { + file { "/etc/init/${name}.conf": + mode => '0444', + owner => 'root', + group => 'root', + content => template('prometheus/daemon.upstart.erb'), + notify => $notify_service, + } + file { "/etc/init.d/${name}": + ensure => link, + target => '/lib/init/upstart-job', + owner => 'root', + group => 'root', + mode => '0755', + } + } + 'systemd' : { + file { "/etc/systemd/system/${name}.service": + mode => '0644', + owner => 'root', + group => 'root', + content => template('prometheus/daemon.systemd.erb'), + }~> + exec { "${name}-systemd-reload": + command => 'systemctl daemon-reload', + path => [ '/usr/bin', '/bin', '/usr/sbin' ], + refreshonly => true, + notify => $notify_service, + } + } + 'sysv' : { + file { "/etc/init.d/${name}": + mode => '0555', + owner => 'root', + group => 'root', + content => template('prometheus/daemon.sysv.erb'), + } + } + 'debian' : { + file { "/etc/init.d/${name}": + mode => '0555', + owner => 'root', + group => 'root', + content => template('prometheus/daemon.debian.erb'), + notify => $notify_service, + } + } + 'sles' : { + file { "/etc/init.d/${name}": + mode => '0555', + owner => 'root', + group => 'root', + content => template('prometheus/daemon.sles.erb'), + notify => $notify_service, + } + } + 'launchd' : { + file { "/Library/LaunchDaemons/io.${name}.daemon.plist": + mode => '0644', + owner => 'root', + group => 'wheel', + content => template('prometheus/daemon.launchd.erb'), + notify => $notify_service, + } + } + default : { + fail("I don't know how to create an init script for style ${init_style}") + } + } + } + + $init_selector = $init_style ? { + 'launchd' => "io.${name}.daemon", + default => $name, + } + + if $manage_service == true { + service { $name: + ensure => $service_ensure, + name => $init_selector, + enable => $service_enable, + } + } + } diff --git a/manifests/mysqld_exporter.pp b/manifests/mysqld_exporter.pp new file mode 100644 index 000000000..cc92e350d --- /dev/null +++ b/manifests/mysqld_exporter.pp @@ -0,0 +1,168 @@ +# Class: prometheus::mysqld_exporter +# +# This module manages prometheus mysqld_exporter +# +# Parameters: +# [*arch*] +# Architecture (amd64 or i386) +# +# [*bin_dir*] +# Directory where binaries are located +# +# [*cnf_config_path*] +# The path to put the my.cnf file +# +# [*cnf_host*] +# The mysql host. Defaults to 'localhost' +# +# [*cnf_password*] +# The mysql user password. Defaults to 'password' +# +# [*cnf_port*] +# The port for which the mysql host is running. Defaults to 3306 +# +# [*cnf_socket*] +# The socket which the mysql host is running. If defined, host and port are not used. +# +# [*cnf_user*] +# The mysql user to use when connecting. Defaults to 'login' +# +# [*config_mode*] +# The permissions of the configuration files +# +# [*download_extension*] +# Extension for the release binary archive +# +# [*download_url*] +# Complete URL corresponding to the where the release binary archive can be downloaded +# +# [*download_url_base*] +# Base URL for the binary archive +# +# [*extra_groups*] +# Extra groups to add the binary user to +# +# [*extra_options*] +# Extra options added to the startup command +# +# [*group*] +# Group under which the binary is running +# +# [*init_style*] +# Service startup scripts style (e.g. rc, upstart or systemd) +# +# [*install_method*] +# Installation method: url or package (only url is supported currently) +# +# [*manage_group*] +# Whether to create a group for or rely on external code for that +# +# [*manage_service*] +# Should puppet manage the service? (default true) +# +# [*manage_user*] +# Whether to create user or rely on external code for that +# +# [*os*] +# Operating system (linux is the only one supported) +# +# [*package_ensure*] +# If package, then use this for package ensure default 'latest' +# +# [*package_name*] +# The binary package name - not available yet +# +# [*purge_config_dir*] +# Purge config files no longer generated by Puppet +# +# [*restart_on_change*] +# Should puppet restart the service on configuration change? (default true) +# +# [*service_enable*] +# Whether to enable the service from puppet (default true) +# +# [*service_ensure*] +# State ensured for the service (default 'running') +# +# [*user*] +# User which runs the service +# +# [*version*] +# The binary release version +class prometheus::mysqld_exporter ( + $arch = $::prometheus::params::arch, + $bin_dir = $::prometheus::params::bin_dir, + $cnf_config_path = $::prometheus::params::mysqld_exporter_cnf_config_path, + $cnf_host = $::prometheus::params::mysqld_exporter_cnf_host, + $cnf_password = $::prometheus::params::mysqld_exporter_cnf_password, + $cnf_port = $::prometheus::params::mysqld_exporter_cnf_port, + $cnf_socket = undef, + $cnf_user = $::prometheus::params::mysqld_exporter_cnf_user, + $config_mode = $::prometheus::params::config_mode, + $download_extension = $::prometheus::params::mysqld_exporter_download_extension, + $download_url = undef, + $download_url_base = $::prometheus::params::mysqld_exporter_download_url_base, + $extra_groups = $::prometheus::params::mysqld_exporter_extra_groups, + $extra_options = '', + $group = $::prometheus::params::mysqld_exporter_group, + $init_style = $::prometheus::params::init_style, + $install_method = $::prometheus::params::install_method, + $manage_group = true, + $manage_service = true, + $manage_user = true, + $os = $::prometheus::params::os, + $package_ensure = $::prometheus::params::mysqld_exporter_package_ensure, + $package_name = $::prometheus::params::mysqld_exporter_package_name, + $purge_config_dir = true, + $restart_on_change = true, + $service_enable = true, + $service_ensure = 'running', + $user = $::prometheus::params::mysqld_exporter_user, + $version = $::prometheus::params::mysqld_exporter_version, +) inherits prometheus::params { + #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}") + validate_bool($purge_config_dir) + validate_bool($manage_user) + validate_bool($manage_service) + validate_bool($restart_on_change) + $notify_service = $restart_on_change ? { + true => Service['mysqld_exporter'], + default => undef, + } + + file { $cnf_config_path: + ensure => 'file', + mode => $config_mode, + owner => $user, + group => $group, + content => template('prometheus/my.cnf.erb'), + notify => $notify_service, + } + + $options = "-config.my-cnf=${cnf_config_path} ${extra_options}" + + prometheus::daemon { 'mysqld_exporter': + install_method => $install_method, + version => $version, + download_extension => $download_extension, + os => $os, + arch => $arch, + real_download_url => $real_download_url, + bin_dir => $bin_dir, + notify_service => $notify_service, + package_name => $package_name, + package_ensure => $package_ensure, + manage_user => $manage_user, + user => $user, + extra_groups => $extra_groups, + group => $group, + manage_group => $manage_group, + purge => $purge_config_dir, + options => $options, + init_style => $init_style, + service_ensure => $service_ensure, + service_enable => $service_enable, + manage_service => $manage_service, + } +} diff --git a/manifests/node_exporter.pp b/manifests/node_exporter.pp index a31234613..deab245cc 100644 --- a/manifests/node_exporter.pp +++ b/manifests/node_exporter.pp @@ -3,123 +3,135 @@ # This module manages prometheus node node_exporter # # Parameters: -# -# [*manage_user*] -# Whether to create user for prometheus or rely on external code for that -# -# [*user*] -# User running prometheus -# -# [*manage_group*] -# Whether to create user for prometheus or rely on external code for that -# -# [*purge_config_dir*] -# Purge config files no longer generated by Puppet +# [*arch*] +# Architecture (amd64 or i386) # -# [*group*] -# Group under which prometheus is running -# # [*bin_dir*] # Directory where binaries are located # -# [*arch*] -# Architecture (amd64 or i386) +# [*collectors*] +# The set of node node_exporter collectors # -# [*version*] -# Prometheus node node_exporter release -# -# [*install_method*] -# Installation method: url or package (only url is supported currently) -# -# [*os*] -# Operating system (linux is the only one supported) +# [*download_extension*] +# Extension for the release binary archive # -# [*download_url*] -# Complete URL corresponding to the Prometheus node node_exporter release, default to undef +# [*download_url*] +# Complete URL corresponding to the where the release binary archive can be downloaded # # [*download_url_base*] -# Base URL for prometheus node node_exporter +# Base URL for the binary archive # -# [*download_extension*] -# Extension of Prometheus node node_exporter binaries archive -# -# [*package_name*] -# Prometheus node node_exporter package name - not available yet +# [*extra_groups*] +# Extra groups to add the binary user to # -# [*package_ensure*] -# If package, then use this for package ensure default 'latest' +# [*extra_options*] +# Extra options added to the startup command # -# [*collectors*] -# The set of node node_exporter collectors +# [*group*] +# Group under which the binary is running # -# [*extra_options*] -# Extra options added to prometheus startup command +# [*init_style*] +# Service startup scripts style (e.g. rc, upstart or systemd) # -# [*service_enable*] -# Whether to enable or not prometheus node node_exporter service from puppet (default true) +# [*install_method*] +# Installation method: url or package (only url is supported currently) # -# [*service_ensure*] -# State ensured from prometheus node node_exporter service (default 'running') +# [*manage_group*] +# Whether to create a group for or rely on external code for that # # [*manage_service*] -# Should puppet manage the prometheus node node_exporter service? (default true) +# Should puppet manage the service? (default true) # -# [*restart_on_change*] -# Should puppet restart prometheus node node_exporter on configuration change? (default true) +# [*manage_user*] +# Whether to create user or rely on external code for that # -# [*init_style*] -# Service startup scripts style (e.g. rc, upstart or systemd) +# [*os*] +# Operating system (linux is the only one supported) # -# Actions: +# [*package_ensure*] +# If package, then use this for package ensure default 'latest' # -# Requires: see Modulefile +# [*package_name*] +# The binary package name - not available yet # -# Sample Usage: +# [*purge_config_dir*] +# Purge config files no longer generated by Puppet +# +# [*restart_on_change*] +# Should puppet restart the service on configuration change? (default true) # +# [*service_enable*] +# Whether to enable the service from puppet (default true) +# +# [*service_ensure*] +# State ensured for the service (default 'running') +# +# [*user*] +# User which runs the service +# +# [*version*] +# The binary release version class prometheus::node_exporter ( - $manage_user = true, - $user = $::prometheus::params::user, - $manage_group = true, - $purge_config_dir = true, - $group = $::prometheus::params::group, - $bin_dir = $::prometheus::params::bin_dir, $arch = $::prometheus::params::arch, - $version = $::prometheus::params::node_exporter_version, - $install_method = $::prometheus::params::install_method, - $os = $::prometheus::params::os, + $bin_dir = $::prometheus::params::bin_dir, + $collectors = $::prometheus::params::node_exporter_collectors, + $download_extension = $::prometheus::params::node_exporter_download_extension, $download_url = undef, - $extra_groups = $::prometheus::params::node_exporter_extra_groups, $download_url_base = $::prometheus::params::node_exporter_download_url_base, - $download_extension = $::prometheus::params::node_exporter_download_extension, - $package_name = $::prometheus::params::node_exporter_package_name, - $package_ensure = $::prometheus::params::node_exporter_package_ensure, - $collectors = $::prometheus::params::node_exporter_collectors, + $extra_groups = $::prometheus::params::node_exporter_extra_groups, $extra_options = '', - $config_mode = $::prometheus::params::config_mode, - $service_enable = true, - $service_ensure = 'running', + $group = $::prometheus::params::node_exporter_group, + $init_style = $::prometheus::params::init_style, + $install_method = $::prometheus::params::install_method, + $manage_group = true, $manage_service = true, + $manage_user = true, + $os = $::prometheus::params::os, + $package_ensure = $::prometheus::params::node_exporter_package_ensure, + $package_name = $::prometheus::params::node_exporter_package_name, + $purge_config_dir = true, $restart_on_change = true, - $init_style = $::prometheus::params::init_style, + $service_enable = true, + $service_ensure = 'running', + $user = $::prometheus::params::node_exporter_user, + $version = $::prometheus::params::node_exporter_version, ) inherits prometheus::params { - $real_download_url = pick($download_url,"${download_url_base}/download/${version}/${package_name}-${version}.${os}-${arch}.${download_extension}") + #Please provide the download_url for versions < 0.13.0 + $real_download_url = pick($download_url,"${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}") validate_bool($purge_config_dir) validate_bool($manage_user) validate_bool($manage_service) validate_bool($restart_on_change) validate_array($collectors) $notify_service = $restart_on_change ? { - true => Class['::prometheus::node_exporter::run_service'], + true => Service['node_exporter'], default => undef, } - anchor {'node_exporter_first': } - -> - class { '::prometheus::node_exporter::install': } -> - class { '::prometheus::node_exporter::config': - purge => $purge_config_dir, - notify => $notify_service, - } -> - class { '::prometheus::node_exporter::run_service': } -> - anchor {'node_exporter_last': } + $str_collectors = join($collectors, ',') + $options = "-collectors.enabled=${str_collectors} ${extra_options}" + + prometheus::daemon { 'node_exporter': + install_method => $install_method, + version => $version, + download_extension => $download_extension, + os => $os, + arch => $arch, + real_download_url => $real_download_url, + bin_dir => $bin_dir, + notify_service => $notify_service, + package_name => $package_name, + package_ensure => $package_ensure, + manage_user => $manage_user, + user => $user, + extra_groups => $extra_groups, + group => $group, + manage_group => $manage_group, + purge => $purge_config_dir, + options => $options, + init_style => $init_style, + service_ensure => $service_ensure, + service_enable => $service_enable, + manage_service => $manage_service, + } } diff --git a/manifests/node_exporter/config.pp b/manifests/node_exporter/config.pp deleted file mode 100644 index 8d49f6282..000000000 --- a/manifests/node_exporter/config.pp +++ /dev/null @@ -1,76 +0,0 @@ -# Class prometheus::node_exporter::config -# Configuration class for prometheus node exporter -class prometheus::node_exporter::config( - $purge = true, -) { - - if $prometheus::node_exporter::init_style { - - case $prometheus::node_exporter::init_style { - 'upstart' : { - file { '/etc/init/node_exporter.conf': - mode => '0444', - owner => 'root', - group => 'root', - content => template('prometheus/node_exporter.upstart.erb'), - } - file { '/etc/init.d/node_exporter': - ensure => link, - target => '/lib/init/upstart-job', - owner => 'root', - group => 'root', - mode => '0755', - } - } - 'systemd' : { - file { '/lib/systemd/system/node_exporter.service': - mode => '0644', - owner => 'root', - group => 'root', - content => template('prometheus/node_exporter.systemd.erb'), - }~> - exec { 'node_exporter-systemd-reload': - command => 'systemctl daemon-reload', - path => [ '/usr/bin', '/bin', '/usr/sbin' ], - refreshonly => true, - } - } - 'sysv' : { - file { '/etc/init.d/node_exporter': - mode => '0555', - owner => 'root', - group => 'root', - content => template('prometheus/node_exporter.sysv.erb') - } - } - 'debian' : { - file { '/etc/init.d/node_exporter': - mode => '0555', - owner => 'root', - group => 'root', - content => template('prometheus/node_exporter.debian.erb') - } - } - 'sles' : { - file { '/etc/init.d/node_exporter': - mode => '0555', - owner => 'root', - group => 'root', - content => template('prometheus/node_exporter.sles.erb') - } - } - 'launchd' : { - file { '/Library/LaunchDaemons/io.node_exporter.daemon.plist': - mode => '0644', - owner => 'root', - group => 'wheel', - content => template('prometheus/node_exporter.launchd.erb') - } - } - default : { - fail("I don't know how to create an init script for style ${prometheus::node_exporter::init_style}") - } - } - } - -} diff --git a/manifests/node_exporter/install.pp b/manifests/node_exporter/install.pp deleted file mode 100644 index 8c37b5ef5..000000000 --- a/manifests/node_exporter/install.pp +++ /dev/null @@ -1,66 +0,0 @@ -# Class prometheus::node_exporter::install -# Install prometheus node node_exporter via different methods with parameters from init -# Currently only the install from url is implemented, when Prometheus will deliver packages for some Linux distros I will -# implement the package install method as well -# The package method needs specific yum or apt repo settings which are not made yet by the module -class prometheus::node_exporter::install -{ - - case $::prometheus::node_exporter::install_method { - 'url': { - include staging - $staging_file = "node_exporter-${prometheus::node_exporter::version}.${prometheus::node_exporter::download_extension}" - if( versioncmp($::prometheus::node_exporter::version, '0.12.0') == -1 ){ - $binary = "${::staging::path}/node_exporter" - } else { - $binary = "${::staging::path}/node_exporter-${::prometheus::node_exporter::version}.${::prometheus::node_exporter::os}-${::prometheus::node_exporter::arch}/node_exporter" - } - staging::file { $staging_file: - source => $prometheus::node_exporter::real_download_url, - } -> - staging::extract { $staging_file: - target => $::staging::path, - creates => $binary, - } -> - file { - $binary: - owner => 'root', - group => 0, # 0 instead of root because OS X uses "wheel". - mode => '0555'; - "${::prometheus::node_exporter::bin_dir}/node_exporter": - ensure => link, - notify => $::prometheus::node_exporter::notify_service, - target => $binary, - } - } - 'package': { - package { $::prometheus::node_exporter::package_name: - ensure => $::prometheus::node_exporter::package_ensure, - } - if $::prometheus::node_exporter::manage_user { - User[$::prometheus::node_exporter::user] -> Package[$::prometheus::node_exporter::package_name] - } - } - 'none': {} - default: { - fail("The provided install method ${::prometheus::install_method} is invalid") - } - } - if $::prometheus::node_exporter::manage_user { - ensure_resource('user', [ $::prometheus::node_exporter::user ], { - ensure => 'present', - system => true, - groups => $::prometheus::node_exporter::extra_groups, - }) - - if $::prometheus::node_exporter::manage_group { - Group[$::prometheus::node_exporter::group] -> User[$::prometheus::node_exporter::user] - } - } - if $::prometheus::node_exporter::manage_group { - ensure_resource('group', [ $::prometheus::node_exporter::group ], { - ensure => 'present', - system => true, - }) - } -} diff --git a/manifests/node_exporter/run_service.pp b/manifests/node_exporter/run_service.pp deleted file mode 100644 index 5e168584a..000000000 --- a/manifests/node_exporter/run_service.pp +++ /dev/null @@ -1,20 +0,0 @@ -# == Class prometheus::node_exporter::service -# -# This class is meant to be called from prometheus::node_exporter -# It ensure the node_exporter service is running -# -class prometheus::node_exporter::run_service { - - $init_selector = $prometheus::node_exporter::init_style ? { - 'launchd' => 'io.node_exporter.daemon', - default => 'node_exporter', - } - - if $prometheus::node_exporter::manage_service == true { - service { 'node_exporter': - ensure => $prometheus::node_exporter::service_ensure, - name => $init_selector, - enable => $prometheus::node_exporter::service_enable, - } - } -} diff --git a/manifests/params.pp b/manifests/params.pp index aa8c2e177..a991a2764 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,45 +1,73 @@ # Class prometheus::params # Include default parameters for prometheus class class prometheus::params { - $user = 'prometheus' - $group = 'prometheus' - $extra_groups = [] + $alertmanager_config_dir = '/etc/alertmanager' + $alertmanager_config_file = "${alertmanager_config_dir}/alertmanager.yaml" + $alertmanager_download_extension = 'tar.gz' + $alertmanager_download_url_base = 'https://github.com/prometheus/alertmanager/releases' + $alertmanager_extra_groups = [] + $alertmanager_global = { 'smtp_smarthost' =>'localhost:25', 'smtp_from'=>'alertmanager@localhost' } + $alertmanager_group = 'alertmanager' + $alertmanager_inhibit_rules = [ { 'source_match' => { 'severity'=> 'critical' },'target_match'=> { 'severity'=>'warning'},'equal'=>['alertname','cluster','service']}] + $alertmanager_package_ensure = 'latest' + $alertmanager_package_name = 'alertmanager' + $alertmanager_receivers = [ { 'name' => 'Admin', 'email_configs'=> [ { 'to'=> 'root@localhost' }] }] + $alertmanager_route = { 'group_by' => [ 'alertname', 'cluster', 'service' ], 'group_wait'=> '30s', 'group_interval'=> '5m', 'repeat_interval'=> '3h', 'receiver'=> 'Admin' } + $alertmanager_storage_path='/var/lib/alertmanager' + $alertmanager_templates = [ "${alertmanager_config_dir}/*.tmpl" ] + $alertmanager_user = 'alertmanager' + $alertmanager_version = '0.3.0' + $alerts = [] $bin_dir = '/usr/local/bin' $config_dir = '/etc/prometheus' - $localstorage = '/var/lib/prometheus' - $shared_dir = '/usr/local/share/prometheus' - $install_method = 'url' - $package_ensure = 'latest' - $package_name = 'prometheus' - $download_url_base = 'https://github.com/prometheus/prometheus/releases' - $version = '1.0.1' + $config_mode = '0660' + $config_template = 'prometheus/prometheus.yaml.erb' $download_extension = 'tar.gz' - $node_exporter_download_url_base = 'https://github.com/prometheus/node_exporter/releases' - $node_exporter_version = '0.12.0' - $node_exporter_download_extension = 'tar.gz' + $download_url_base = 'https://github.com/prometheus/prometheus/releases' + $extra_groups = [] + $global_config = { 'scrape_interval'=> '15s', 'evaluation_interval'=> '15s', 'external_labels'=> { 'monitor'=>'master'}} + $group = 'prometheus' + $install_method = 'url' + $localstorage = '/var/lib/prometheus' + $mysqld_exporter_cnf_config_path = '/etc/.my.cnf' + $mysqld_exporter_cnf_host = 'localhost' + $mysqld_exporter_cnf_password = 'password' + $mysqld_exporter_cnf_port = 3306 + $mysqld_exporter_cnf_user = 'login' + $mysqld_exporter_download_extension = 'tar.gz' + $mysqld_exporter_download_url_base = 'https://github.com/prometheus/mysqld_exporter/releases' + $mysqld_exporter_extra_groups = [] + $mysqld_exporter_group = 'mysqld-exporter' + $mysqld_exporter_package_ensure = 'latest' + $mysqld_exporter_package_name = 'mysqld_exporter' + $mysqld_exporter_user = 'mysqld-exporter' + $mysqld_exporter_version = '0.9.0' $node_exporter_collectors = ['diskstats','filesystem','loadavg','meminfo','netdev','stat','time'] + $node_exporter_download_extension = 'tar.gz' + $node_exporter_download_url_base = 'https://github.com/prometheus/node_exporter/releases' + $node_exporter_extra_groups = [] + $node_exporter_group = 'node-exporter' $node_exporter_package_ensure = 'latest' $node_exporter_package_name = 'node_exporter' - $node_exporter_extra_groups = [] - $alert_manager_download_url_base = 'https://github.com/prometheus/alertmanager/releases' - $alert_manager_config_dir = '/etc/alert_manager' - $alert_manager_config_file = "${alert_manager_config_dir}/alertmanager.yaml" - $alert_manager_global = { 'smtp_smarthost' =>'localhost:25', 'smtp_from'=>'alertmanager@localhost' } - $alert_manager_templates = [ "${alert_manager_config_dir}/*.tmpl" ] - $alert_manager_route = { 'group_by' => [ 'alertname', 'cluster', 'service' ], 'group_wait'=> '30s', 'group_interval'=> '5m', 'repeat_interval'=> '3h', 'receiver'=> 'Admin' } - $alert_manager_receivers = [ { 'name' => 'Admin', 'email_configs'=> [ { 'to'=> 'root@localhost' }] }] - $alert_manager_inhibit_rules = [ { 'source_match' => { 'severity'=> 'critical' },'target_match'=> { 'severity'=>'warning'},'equal'=>['alertname','cluster','service']}] - $alert_manager_storage_path='/var/lib/alertmanager' - $alert_manager_version = '0.3.0' - $alert_manager_download_extension = 'tar.gz' - $alert_manager_package_ensure = 'latest' - $alert_manager_package_name = 'alertmanager' - $config_template = 'prometheus/prometheus.yaml.erb' - $config_mode = '0660' - $global_config = { 'scrape_interval'=> '15s', 'evaluation_interval'=> '15s', 'external_labels'=> { 'monitor'=>'master'}} + $node_exporter_user = 'node-exporter' + $node_exporter_version = '0.13.0' + $package_ensure = 'latest' + $package_name = 'prometheus' $rule_files = [ "${config_dir}/alert.rules" ] $scrape_configs = [ { 'job_name'=> 'prometheus', 'scrape_interval'=> '10s', 'scrape_timeout'=> '10s', 'static_configs'=> [ { 'targets'=> [ 'localhost:9090' ], 'labels'=> { 'alias'=> 'Prometheus'} } ] } ] - $alerts = [] + $shared_dir = '/usr/local/share/prometheus' + $statsd_exporter_download_extension = 'tar.gz' + $statsd_exporter_download_url_base = 'https://github.com/prometheus/statsd_exporter/releases' + $statsd_exporter_extra_groups = [] + $statsd_exporter_group = 'statsd-exporter' + $statsd_exporter_mapping_config_path = '/etc/statsd_mappings.conf' + $statsd_exporter_maps = [{'map' => 'test.dispatcher.*.*.*','name' =>'dispatcher_events_total','labels' => { 'processor'=>'$1', 'action'=>'$2', 'outcome'=>'$3', 'job'=>'test_dispatcher'}}] + $statsd_exporter_package_ensure = 'latest' + $statsd_exporter_package_name = 'statsd_exporter' + $statsd_exporter_user = 'statsd-exporter' + $statsd_exporter_version = '0.3.0' + $user = 'prometheus' + $version = '1.0.1' case $::architecture { 'x86_64', 'amd64': { $arch = 'amd64' } 'i386': { $arch = '386' } diff --git a/manifests/statsd_exporter.pp b/manifests/statsd_exporter.pp new file mode 100644 index 000000000..f457da4d2 --- /dev/null +++ b/manifests/statsd_exporter.pp @@ -0,0 +1,156 @@ +# Class: prometheus::statsd_exporter +# +# This module manages prometheus statsd_exporter +# +# Parameters: +# [*arch*] +# Architecture (amd64 or i386) +# +# [*bin_dir*] +# Directory where binaries are located +# +# [*config_mode*] +# The permissions of the configuration files +# +# [*download_extension*] +# Extension for the release binary archive +# +# [*download_url*] +# Complete URL corresponding to the where the release binary archive can be downloaded +# +# [*download_url_base*] +# Base URL for the binary archive +# +# [*extra_groups*] +# Extra groups to add the binary user to +# +# [*extra_options*] +# Extra options added to the startup command +# +# [*group*] +# Group under which the binary is running +# +# [*init_style*] +# Service startup scripts style (e.g. rc, upstart or systemd) +# +# [*install_method*] +# Installation method: url or package (only url is supported currently) +# +# [*manage_group*] +# Whether to create a group for or rely on external code for that +# +# [*manage_service*] +# Should puppet manage the service? (default true) +# +# [*manage_user*] +# Whether to create user or rely on external code for that +# +# [*os*] +# Operating system (linux is the only one supported) +# +# [*package_ensure*] +# If package, then use this for package ensure default 'latest' +# +# [*package_name*] +# The binary package name - not available yet +# +# [*purge_config_dir*] +# Purge config files no longer generated by Puppet +# +# [*restart_on_change*] +# Should puppet restart the service on configuration change? (default true) +# +# [*service_enable*] +# Whether to enable the service from puppet (default true) +# +# [*service_ensure*] +# State ensured for the service (default 'running') +# +# [*statsd_maps*] +# The hiera array for mappings: +# - map: 'test.dispatcher.*.*.*' +# name: 'dispatcher_events_total' +# labels: +# processor: '$2' +# action: '$1' +# +# [*user*] +# User which runs the service +# +# [*version*] +# The binary release version +class prometheus::statsd_exporter ( + $arch = $::prometheus::params::arch, + $bin_dir = $::prometheus::params::bin_dir, + $config_mode = $::prometheus::params::config_mode, + $download_extension = $::prometheus::params::statsd_exporter_download_extension, + $download_url = undef, + $download_url_base = $::prometheus::params::statsd_exporter_download_url_base, + $extra_groups = $::prometheus::params::statsd_exporter_extra_groups, + $extra_options = '', + $group = $::prometheus::params::statsd_exporter_group, + $init_style = $::prometheus::params::init_style, + $install_method = $::prometheus::params::install_method, + $manage_group = true, + $manage_service = true, + $manage_user = true, + $mapping_config_path = $::prometheus::params::statsd_exporter_mapping_config_path, + $os = $::prometheus::params::os, + $package_ensure = $::prometheus::params::statsd_exporter_package_ensure, + $package_name = $::prometheus::params::statsd_exporter_package_name, + $purge_config_dir = true, + $restart_on_change = true, + $service_enable = true, + $service_ensure = 'running', + $statsd_maps = $::prometheus::params::statsd_exporter_maps, + $user = $::prometheus::params::statsd_exporter_user, + $version = $::prometheus::params::statsd_exporter_version, +) inherits prometheus::params { + $real_download_url = pick($download_url,"${download_url_base}/download/${version}/${package_name}-${version}.${os}-${arch}.${download_extension}") + validate_bool($purge_config_dir) + validate_bool($manage_user) + validate_bool($manage_service) + validate_bool($restart_on_change) + $notify_service = $restart_on_change ? { + true => Service['statsd_exporter'], + default => undef, + } + + $extra_statsd_maps = hiera_array('prometheus::statsd_exporter::statsd_maps',[]) + $real_statsd_maps = concat($extra_statsd_maps, $prometheus::statsd_exporter::statsd_maps) + + file { $mapping_config_path: + ensure => 'file', + mode => $config_mode, + owner => $user, + group => $group, + content => template('prometheus/statsd_mapping.conf.erb'), + notify => $notify_service, + } + + $options = "-statsd.mapping-config=\'${prometheus::statsd_exporter::mapping_config_path}\' ${prometheus::statsd_exporter::extra_options}" + + prometheus::daemon { 'statsd_exporter': + install_method => $install_method, + version => $version, + download_extension => $download_extension, + os => $os, + arch => $arch, + real_download_url => $real_download_url, + bin_dir => $bin_dir, + notify_service => $notify_service, + package_name => $package_name, + package_ensure => $package_ensure, + manage_user => $manage_user, + user => $user, + extra_groups => $extra_groups, + group => $group, + manage_group => $manage_group, + purge => $purge_config_dir, + options => $options, + init_style => $init_style, + service_ensure => $service_ensure, + service_enable => $service_enable, + manage_service => $manage_service, + } +} diff --git a/metadata.json b/metadata.json index c2cc13f00..3e71145fd 100644 --- a/metadata.json +++ b/metadata.json @@ -4,7 +4,7 @@ {"name":"nanliu/staging","version_requirement":">=0.4.0 <2.0.0"}], "license": "Apache 2.0", "name": "brutus777-prometheus", - "operatingsystem_support": [ + "operatingsystem_support": [ { "operatingsystemrelease": [ "5", @@ -19,5 +19,5 @@ "source": "https://github.com/brutus333/puppet-prometheus", "summary": "Prometheus Puppet module", "tags": [], - "version": "0.1.14" + "version": "0.2.00" } diff --git a/spec/classes/node_exporter-version_spec.rb b/spec/classes/node_exporter_spec.rb similarity index 50% rename from spec/classes/node_exporter-version_spec.rb rename to spec/classes/node_exporter_spec.rb index 5b97fbf34..1bda49abd 100644 --- a/spec/classes/node_exporter-version_spec.rb +++ b/spec/classes/node_exporter_spec.rb @@ -1,41 +1,37 @@ require 'spec_helper' describe "prometheus::node_exporter" do - - context 'uses the correct binary path for version < 0.12.0' do - let(:facts) { { + let :default_facts do + { 'operatingsystem' => 'CentOS', 'osfamily' => 'Redhat', 'operatingsystemrelease' => '7.0', 'architecture' => 'amd64', 'kernel' => 'Linux', - } } + } + end + + context 'uses the correct binary path for version' do + let(:facts) { default_facts } let(:params) { {:version => '0.10.0', :arch => 'amd64', :os => 'linux'} } it do should contain_file('/usr/local/bin/node_exporter').with({ - 'target' => '/opt/staging/node_exporter' + 'target' => '/opt/staging/node_exporter-0.10.0.linux-amd64/node_exporter' }) end end - context 'uses the correct binary path for versions >= 0.12' do - let(:facts) { { - 'operatingsystem' => 'CentOS', - 'osfamily' => 'Redhat', - 'operatingsystemrelease' => '7.0', - 'architecture' => 'amd64', - 'kernel' => 'Linux', - } } + context 'uses the correct binary path for version' do + let(:facts) { default_facts } - let(:params) { {:version => '0.12.0', :arch => 'amd64', :os => 'linux'} } + let(:params) { {:version => '0.10.0', :arch => 'amd64', :os => 'linux'} } it do should contain_file('/usr/local/bin/node_exporter').with({ - 'target' => '/opt/staging/node_exporter-0.12.0.linux-amd64/node_exporter' + 'target' => '/opt/staging/node_exporter-0.10.0.linux-amd64/node_exporter' }) end end - end diff --git a/spec/classes/statsd_exporter_spec.rb b/spec/classes/statsd_exporter_spec.rb new file mode 100644 index 000000000..e69de29bb diff --git a/spec/defines/daemon_spec.rb b/spec/defines/daemon_spec.rb new file mode 100644 index 000000000..63cadf95e --- /dev/null +++ b/spec/defines/daemon_spec.rb @@ -0,0 +1,68 @@ +require 'spec_helper' + +describe "prometheus::daemon" do + let :title do + 'node_exporter' + end + + let :default_params do + { + install_method: 'url', + version: '0.13.0', + download_extension: 'tar.gz', + os: 'linux', + arch: 'amd64', + bin_dir: '/usr/local/bin', + notify_service: true, + manage_user: true, + user: 'node_exporter', + extra_groups: [], + group: 'node_exporter', + manage_group: true, + purge: true, + options: '', + init_style: 'systemd', + service_ensure: true, + service_enable: true, + manage_service: true, + real_download_url: "https://github.com/prometheus/node_exporter/releases/download/v0.13.0/node_exporter-0.13.0.linux-amd64.tar.gz", + package_name: 'node_exporter', + package_ensure: false, + } + end + + context 'should define a service' do + let(:params) { default_params } + + it do + should contain_service('node_exporter').with({ + 'ensure' => true, + 'enable' => true, + }) + end + end + + context 'should create a link to the downloaded binary' do + let(:params) { default_params } + + it do + should contain_file('/usr/local/bin/node_exporter').with({ + 'ensure' => 'link', + 'target' => '/opt/staging/node_exporter-0.13.0.linux-amd64/node_exporter' + }) + end + end + + context 'should create a user and group' do + let(:params) { default_params } + + it do + should contain_user('node_exporter').with({ + 'ensure' => 'present', + }) + should contain_group('node_exporter').with({ + 'ensure' => 'present', + }) + end + end +end diff --git a/spec/fixtures/manifests/site.pp b/spec/fixtures/manifests/site.pp new file mode 100644 index 000000000..e69de29bb diff --git a/templates/alert_manager.debian.erb b/templates/alert_manager.debian.erb deleted file mode 100644 index 445f0c5e0..000000000 --- a/templates/alert_manager.debian.erb +++ /dev/null @@ -1,173 +0,0 @@ -#! /bin/sh -### BEGIN INIT INFO -# Provides: alert_manager -# Required-Start: $local_fs $remote_fs -# Required-Stop: $local_fs $remote_fs -# Default-Start: 2 3 4 5 -# Default-Stop: S 0 1 6 -# Short-Description: Prometheus alert manager -# Description: The Alertmanager handles alerts sent by client applications such as the Prometheus server. -# -### END INIT INFO - -# Do NOT "set -e" - -# PATH should only include /usr/* if it runs after the mountnfs.sh script -PATH=/usr/sbin:/usr/bin:/sbin:/bin:<%= scope.lookupvar('prometheus::alert_manager::bin_dir') %> -DESC="Prometheus alert manager" -NAME=alert_manager -DAEMON=<%= scope.lookupvar('prometheus::alert_manager::bin_dir') %>/$NAME -PIDFILE=/var/run/$NAME/$NAME.pid -DAEMON_ARGS=" -config.file=<%= scope.lookupvar('prometheus::alert_manager::config_file') %> -storage.path=<%= scope.lookupvar('prometheus::alert_manager::storage_path') %> <%= scope.lookupvar('prometheus::alert_manager::extra_options') %>" -USER=<%= scope.lookupvar('prometheus::alert_manager::user') %> -SCRIPTNAME=/etc/init.d/$NAME - -# Exit if the package is not installed -[ -x "$DAEMON" ] || exit 0 - -# Read configuration variable file if it is present -[ -r /etc/default/$NAME ] && . /etc/default/$NAME - -# Load the VERBOSE setting and other rcS variables -[ -f /etc/default/rcS ] && . /etc/default/rcS - -# Define LSB log_* functions. -# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. -. /lib/lsb/init-functions - -# -# Function to create run directory -# -mkrundir() { - [ ! -d /var/run/prometheus ] && mkdir -p /var/run/prometheus - chown $USER /var/run/prometheus -} - -# -# Function that starts the daemon/service -# -do_start() -{ - # Return - # 0 if daemon has been started - # 1 if daemon was already running - # 2 if daemon could not be started - mkrundir - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --chuid $USER --background --make-pidfile --test > /dev/null \ - || return 1 - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --chuid $USER --background --make-pidfile -- \ - $DAEMON_ARGS \ - || return 2 - - for i in `seq 1 30`; do - if ! start-stop-daemon --quiet --stop --test --pidfile $PIDFILE --exec $DAEMON --user $USER; then - RETVAL=2 - sleep 1 - continue - fi - if "$DAEMON" info ${RPC_ADDR} >/dev/null; then - return 0 - fi - done - return "$RETVAL" -} - - -# -# Function that stops the daemon/service -# -do_stop() -{ - # Return - # 0 if daemon has been stopped - # 1 if daemon was already stopped - # 2 if daemon could not be stopped - # other if a failure occurred - start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME - RETVAL="$?" - [ "$RETVAL" = 2 ] && return 2 - # Wait for children to finish too if this is a daemon that forks - # and if the daemon is only ever run from this initscript. - # If the above conditions are not satisfied then add some other code - # that waits for the process to drop all resources that could be - # needed by services started subsequently. A last resort is to - # sleep for some time. - start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON - [ "$?" = 2 ] && return 2 - # Many daemons don't delete their pidfiles when they exit. - rm -f $PIDFILE - return "$RETVAL" -} - -# -# Function that sends a SIGHUP to the daemon/service -# -do_reload() { - # - # If the daemon can reload its configuration without - # restarting (for example, when it is sent a SIGHUP), - # then implement that here. - # - start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME - return 0 -} - -case "$1" in - start) - [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" - do_start - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - stop) - [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" - do_stop - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - #reload|force-reload) - # - # If do_reload() is not implemented then leave this commented out - # and leave 'force-reload' as an alias for 'restart'. - # - #log_daemon_msg "Reloading $DESC" "$NAME" - #do_reload - #log_end_msg $? - #;; - restart|force-reload) - # - # If the "reload" option is implemented then remove the - # 'force-reload' alias - # - log_daemon_msg "Restarting $DESC" "$NAME" - do_stop - case "$?" in - 0|1) - do_start - case "$?" in - 0) log_end_msg 0 ;; - 1) log_end_msg 1 ;; # Old process is still running - *) log_end_msg 1 ;; # Failed to start - esac - ;; - *) - # Failed to stop - log_end_msg 1 - ;; - esac - ;; - status) - status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $? - ;; - *) - #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 - echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 - exit 3 - ;; -esac - -: diff --git a/templates/alert_manager.launchd.erb b/templates/alert_manager.launchd.erb deleted file mode 100644 index 11879d7af..000000000 --- a/templates/alert_manager.launchd.erb +++ /dev/null @@ -1,29 +0,0 @@ - - - - - Label io.alert_manager.daemon - UserName <%= scope.lookupvar('prometheus::alert_manager::user') %> - GroupName <%= scope.lookupvar('prometheus::alert_manager::group') %> -<% if scope.lookupvar('prometheus::alert_manager::service_enable') %> - Disabled -<% else %> - Disabled> -<% end %> - RunAtLoad - KeepAlive - ProgramArguments - - <%= scope.lookupvar('prometheus::alert_manager::bin_dir') %>/prometheus - agent - -config.file= - <%= scope.lookupvar('prometheus::alert_manager::config_file') %> - -storage.path= - <%= scope.lookupvar('prometheus::alert_manager::storage_path') %> -<% require 'shellwords' %> -<% for extra_option in Shellwords.split(scope.lookupvar('prometheus::alert_manager::extra_options')) %> - <%= extra_option %> -<% end %> - - - diff --git a/templates/alert_manager.sles.erb b/templates/alert_manager.sles.erb deleted file mode 100644 index 1bd079c43..000000000 --- a/templates/alert_manager.sles.erb +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/bash -# -# /etc/rc.d/init.d/alert_manager -# -# Daemonize the prometheus alert manager. -# -### BEGIN INIT INFO -# Provides: alert_manager -# Required-Start: network -# Should-Start: $null -# Required-Stop: $null -# Should-Stop: $null -# Default-Start: 3 5 -# Default-Stop: 0 1 2 6 -# Short-Description: The Alertmanager handles alerts sent by client applications such as the Prometheus server. -# Description: The Alertmanager handles alerts sent by client applications such as the Prometheus server.It takes care of deduplicating, grouping, and routing them to the correct receiver integration such as email, PagerDuty, or OpsGenie. It also takes care of silencing and inhibition of alerts. -### END INIT INFO - -. /etc/rc.status - -rc_reset - -ALERT_MANAGER_BIN=<%= scope.lookupvar('prometheus::alert_manager::bin_dir') %>/alert_manager -LOG_FILE=/var/log/alert_manager - - -# read settings like GOMAXPROCS from "/etc/sysconfig/prometheus" -[ -e /etc/sysconfig/alert_manager ] && . /etc/sysconfig/alert_manager - -export GOMAXPROCS=${GOMAXPROCS:-2} - - -case "$1" in - start) - echo -n "Starting Prometheus alert manager" - ## Start daemon with startproc(8). If this fails - ## the return value is set appropriately by startproc. - startproc $ALERT_MANAGER_BIN -config.file=<%= scope.lookupvar('prometheus::alert_manager::config_file') %> -storage.path=<%= scope.lookupvar('prometheus::alert_manager::storage_path') %> <%= scope.lookupvar('prometheus::alert_manager::extra_options') %> >> "$LOG_FILE" - - # Remember status and be verbose - rc_status -v - ;; - stop) - echo -n "Shutting down prometheus " - ## Stop daemon with killproc(8) and if this fails - ## killproc sets the return value according to LSB. - - killproc -TERM $ALERT_MANAGER_BIN - - # Remember status and be verbose - rc_status -v - ;; - restart) - ## Stop the service and regardless of whether it was - ## running or not, start it again. - $0 stop - $0 start - - # Remember status and be quiet - rc_status - ;; - reload) - # If it supports signaling: - echo -n "Reload service prometheus " - killproc -HUP $ALERT_MANAGER_BIN - #touch /var/run/prometheus.pid - rc_status -v - - ## Otherwise if it does not support reload: - #rc_failed 3 - #rc_status -v - ;; - status) - echo -n "Checking for service prometheus " - ## Check status with checkproc(8), if process is running - ## checkproc will return with exit status 0. - - # Return value is slightly different for the status command: - # 0 - service up and running - # 1 - service dead, but /var/run/ pid file exists - # 2 - service dead, but /var/lock/ lock file exists - # 3 - service not running (unused) - # 4 - service status unknown :-( - # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) - - # NOTE: checkproc returns LSB compliant status values. - checkproc $ALERT_MANAGER_BIN - # NOTE: rc_status knows that we called this init script with - # "status" option and adapts its messages accordingly. - rc_status -v - ;; - *) - ## If no parameters are given, print which are avaiable. - echo "Usage: $0 {start|stop|status|restart|reload}" - exit 1 - ;; -esac - -rc_exit diff --git a/templates/alert_manager.systemd.erb b/templates/alert_manager.systemd.erb deleted file mode 100644 index dfe916f2e..000000000 --- a/templates/alert_manager.systemd.erb +++ /dev/null @@ -1,18 +0,0 @@ -[Unit] -Description=The Alertmanager handles alerts sent by client applications such as the Prometheus server. -Wants=basic.target -After=basic.target network.target - -[Service] -User=<%= scope.lookupvar('prometheus::alert_manager::user') %> -Group=<%= scope.lookupvar('prometheus::alert_manager::group') %> -ExecStart=<%= scope.lookupvar('prometheus::alert_manager::bin_dir') %>/alert_manager \ - -config.file=<%= scope.lookupvar('prometheus::alert_manager::config_file') %> \ - -storage.path=<%= scope.lookupvar('prometheus::alert_manager::storage_path') %> <%= scope.lookupvar('prometheus::alert_manager::extra_options') %> -ExecReload=/bin/kill -HUP $MAINPID -KillMode=process -Restart=always -RestartSec=42s - -[Install] -WantedBy=multi-user.target diff --git a/templates/alert_manager.sysv.erb b/templates/alert_manager.sysv.erb deleted file mode 100644 index d6e80540c..000000000 --- a/templates/alert_manager.sysv.erb +++ /dev/null @@ -1,125 +0,0 @@ -#!/bin/bash -# -# /etc/rc.d/init.d/alert_manager -# -# Daemonize the prometheus alert manager -# -# chkconfig: 2345 95 20 -# description: The Alertmanager handles alerts sent by client applications such as the Prometheus server. -# processname: alert_manager -# pidfile: /var/run/alert_manager/pidfile - -# Source function library. -. /etc/init.d/functions - -DAEMON=<%= scope.lookupvar('prometheus::alert_manager::bin_dir') %>/alert_manager -PID_FILE=/var/run/alert_manager/alert_manager.pid -LOG_FILE=/var/log/alert_manager - -[ -e /etc/sysconfig/alert_manager ] && . /etc/sysconfig/alert_manager - -export GOMAXPROCS=${GOMAXPROCS:-2} - -# -# Create the /var/run/alert_manager directory, which can live on a tmpfs -# filesystem and be destroyed between reboots. -# -mkrundir() { - [ ! -d /var/run/alert_manager ] && mkdir -p /var/run/alert_manager - chown <%= scope.lookupvar('prometheus::alert_manager::user') %> /var/run/alert_manager -} - -# -# Create a PID file if it doesn't already exist, for clean upgrades -# from previous init-script controlled daemons. -# -KILLPROC_OPT="-p ${PID_FILE}" -mkpidfile() { - # Create PID file if it didn't exist - mkrundir - [ ! -f $PID_FILE ] && pidofproc $DAEMON > $PID_FILE - chown <%= scope.lookupvar('prometheus::alert_manager::user') %> /var/run/alert_manager - if [ $? -ne 0 ] ; then - rm $PID_FILE - KILLPROC_OPT="" - fi -} - -start() { - echo -n "Starting prometheus alert manager: " - mkrundir - [ -f $PID_FILE ] && rm $PID_FILE - daemon --user=<%= scope.lookupvar('prometheus::alert_manager::user') %> \ - --pidfile="$PID_FILE" \ - "$DAEMON" -config.file=<%= scope.lookupvar('prometheus::alert_manager::config_file') %> -storage.path=<%= scope.lookupvar('prometheus::alert_manager::storage_path') %> <%= scope.lookupvar('prometheus::alert_manager::extra_options') %> >> "$LOG_FILE" & - retcode=$? - mkpidfile - touch /var/lock/subsys/alert_manager - return $retcode -} - -stop() { - DELAY=5 # seconds maximum to wait for a leave - - echo -n "Shutting down prometheus alert_manager: " - mkpidfile - - alert_manager_pid=$(cat $PID_FILE) - killproc $KILLPROC_OPT $DAEMON -INT - retcode=$? - - # We'll wait if necessary to make sure the leave works, and return - # early if we can. If not, escalate to harsher signals. - try=0 - while [ $try -lt $DELAY ]; do - if ! checkpid $alert_manager_pid ; then - rm -f /var/lock/subsys/alert_manager - return $retcode - fi - sleep 1 - let try+=1 - done - - # If acting as a server, use a SIGTERM to avoid a leave. - # This behavior is also configurable. Avoid doing a "leave" because - # having servers missing is a bad thing that we want to notice. - # - # A SIGTERM will mark the node as "failed" until it rejoins. - # killproc with no arguments uses TERM, then escalates to KILL. - killproc $KILLPROC_OPT $DAEMON - retcode=$? - - rm -f /var/lock/subsys/alert_manager $PID_FILE - return $retcode -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - status) - status -p ${PID_FILE} $DAEMON - ;; - restart) - stop - start - ;; - reload) - mkpidfile - killproc $KILLPROC_OPT $DAEMON -HUP - ;; - condrestart) - [ -f /var/lock/subsys/alert_manager ] && restart || : - ;; - *) - echo "Usage: alert_manager {start|stop|status|reload|restart}" - exit 1 - ;; -esac -retcode=$? -# Don't let the [OK] get stomped on. -echo -exit $retcode diff --git a/templates/alert_manager.upstart.erb b/templates/alert_manager.upstart.erb deleted file mode 100644 index ec62218ca..000000000 --- a/templates/alert_manager.upstart.erb +++ /dev/null @@ -1,31 +0,0 @@ -# Prometheus Alert Manager (Upstart unit) -description "The Alertmanager handles alerts sent by client applications such as the Prometheus server." -start on runlevel [2345] -stop on runlevel [06] - -env ALERT_MANAGER=<%= scope.lookupvar('prometheus::alert_manager::bin_dir') %>/alert_manager -env CONFIG=<%= scope.lookupvar('prometheus::alert_manager::config_file') %> -env USER=<%= scope.lookupvar('prometheus::alert_manager::user') %> -env GROUP=<%= scope.lookupvar('prometheus::alert_manager::group') %> -env DEFAULTS=/etc/default/alert_manager -env RUNDIR=/var/run/alert_manager -env PID_FILE=/var/run/alert_manager/alert_manager.pid -pre-start script - [ -e $DEFAULTS ] && . $DEFAULTS - - mkdir -p $RUNDIR || true - chmod 0750 $RUNDIR || true - chown $USER:$GROUP $RUNDIR || true -end script - -script - # read settings like GOMAXPROCS from "/etc/default/alert_manager", if available. - [ -e $DEFAULTS ] && . $DEFAULTS - - export GOMAXPROCS=${GOMAXPROCS:-2} - exec start-stop-daemon -c $USER -g $GROUP -p $PID_FILE -x $ALERT_MANAGER -S -- -config.file=$CONFIG -storage.path=<%= scope.lookupvar('prometheus::alert_manager::storage_path') %> <%= scope.lookupvar('prometheus::alert_manager::extra_options') %> -end script - -respawn -respawn limit 10 10 -kill timeout 10 diff --git a/templates/alert_manager.yaml.erb b/templates/alert_manager.yaml.erb deleted file mode 100644 index c5159144e..000000000 --- a/templates/alert_manager.yaml.erb +++ /dev/null @@ -1,8 +0,0 @@ -<% require 'yaml' -%> -<% global = scope.lookupvar('::prometheus::alert_manager::global') -%> -<% templates = scope.lookupvar('::prometheus::alert_manager::templates') -%> -<% route = scope.lookupvar('::prometheus::alert_manager::route') -%> -<% receivers = scope.lookupvar('::prometheus::alert_manager::receivers') -%> -<% inhibit_rules = scope.lookupvar('::prometheus::alert_manager::inhibit_rules') -%> -<% full_config = { 'global'=>global, 'templates'=>templates, 'route'=>route, 'receivers'=>receivers, 'inhibit_rules'=>inhibit_rules } -%> -<%= full_config.to_yaml -%> diff --git a/templates/alertmanager.yaml.erb b/templates/alertmanager.yaml.erb new file mode 100644 index 000000000..6fc50246a --- /dev/null +++ b/templates/alertmanager.yaml.erb @@ -0,0 +1,8 @@ +<% require 'yaml' -%> +<% global = scope.lookupvar('::prometheus::alertmanager::global') -%> +<% templates = scope.lookupvar('::prometheus::alertmanager::templates') -%> +<% route = scope.lookupvar('::prometheus::alertmanager::route') -%> +<% receivers = scope.lookupvar('::prometheus::alertmanager::receivers') -%> +<% inhibit_rules = scope.lookupvar('::prometheus::alertmanager::inhibit_rules') -%> +<% full_config = { 'global'=>global, 'templates'=>templates, 'route'=>route, 'receivers'=>receivers, 'inhibit_rules'=>inhibit_rules } -%> +<%= full_config.to_yaml -%> diff --git a/templates/node_exporter.debian.erb b/templates/daemon.debian.erb similarity index 84% rename from templates/node_exporter.debian.erb rename to templates/daemon.debian.erb index 96711487a..3e187b640 100644 --- a/templates/node_exporter.debian.erb +++ b/templates/daemon.debian.erb @@ -1,25 +1,26 @@ #! /bin/sh ### BEGIN INIT INFO -# Provides: node_exporter +# Provides: <%= @name %> # Required-Start: $local_fs $remote_fs # Required-Stop: $local_fs $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: S 0 1 6 -# Short-Description: Prometheus node exporter -# Description: Prometheus exporter for machine metrics, written in Go with pluggable metric collectors. -# +# Short-Description: Prometheus <%= @name %> +# Description: Prometheus <%= @name %> +# ### END INIT INFO # Do NOT "set -e" # PATH should only include /usr/* if it runs after the mountnfs.sh script -PATH=/usr/sbin:/usr/bin:/sbin:/bin:<%= scope.lookupvar('prometheus::node_exporter::bin_dir') %> -DESC="Prometheus node exporter" -NAME=node_exporter -DAEMON=<%= scope.lookupvar('prometheus::node_exporter::bin_dir') %>/$NAME +PATH=/usr/sbin:/usr/bin:/sbin:/bin:<%= @bin_dir %> +DESC="Prometheus <%= @name %>" +NAME=<%= @name %> +DAEMON=<%= @bin_dir %>/$NAME PIDFILE=/var/run/$NAME/$NAME.pid -DAEMON_ARGS=" -collectors.enabled=<%= scope.lookupvar('prometheus::node_exporter::collectors').join(',') %> <%= scope.lookupvar('prometheus::node_exporter::extra_options') %>" -USER=<%= scope.lookupvar('prometheus::node_exporter::user') %> +<%- require 'shellwords' -%> +DAEMON_ARGS=<%= Shellwords.escape(@options) %> +USER=<%= @user %> SCRIPTNAME=/etc/init.d/$NAME # Exit if the package is not installed @@ -39,8 +40,8 @@ SCRIPTNAME=/etc/init.d/$NAME # Function to create run directory # mkrundir() { - [ ! -d /var/run/prometheus ] && mkdir -p /var/run/prometheus - chown $USER /var/run/prometheus + [ ! -d /var/run/<%= @name %> ] && mkdir -p /var/run/<%= @name %> + chown $USER /var/run/<%= @name %> } # diff --git a/templates/daemon.launchd.erb b/templates/daemon.launchd.erb new file mode 100644 index 000000000..bfae936cc --- /dev/null +++ b/templates/daemon.launchd.erb @@ -0,0 +1,24 @@ + + + + + Label io.<%= @name %>.daemon + UserName <%= @user %> + GroupName <%= @group %> +<% if @service_enable %> + Disabled +<% else %> + Disabled> +<% end %> + RunAtLoad + KeepAlive + ProgramArguments + + <%= @bin_dir %>/<%= @name %> +<% require 'shellwords' %> +<% for extra_option in Shellwords.split(@options) %> + <%= extra_option %> +<% end %> + + + diff --git a/templates/node_exporter.sles.erb b/templates/daemon.sles.erb similarity index 66% rename from templates/node_exporter.sles.erb rename to templates/daemon.sles.erb index 5ae309007..b5c79055b 100644 --- a/templates/node_exporter.sles.erb +++ b/templates/daemon.sles.erb @@ -1,51 +1,52 @@ #!/bin/bash # -# /etc/rc.d/init.d/node_exporter +# /etc/rc.d/init.d/<%= @name %> # -# Daemonize the prometheus node exporter. +# Daemonize the prometheus <%= @name %>. # ### BEGIN INIT INFO -# Provides: node_exporter +# Provides: <%= @name %> # Required-Start: network # Should-Start: $null # Required-Stop: $null # Should-Stop: $null # Default-Start: 3 5 # Default-Stop: 0 1 2 6 -# Short-Description: Prometheus exporter for machine metrics, written in Go with pluggable metric collectors. -# Description: Prometheus exporter for machine metrics, written in Go with pluggable metric collectors. +# Short-Description: Prometheus <%= @name %> +# Description: Prometheus <%= @name %> ### END INIT INFO . /etc/rc.status rc_reset -NODE_EXPORTER_BIN=<%= scope.lookupvar('prometheus::node_exporter::bin_dir') %>/node_exporter -LOG_FILE=/var/log/node_exporter +<%= @name %>_BIN=<%= @bin_dir %>/<%= @name %> +LOG_FILE=/var/log/<%= @name %> # read settings like GOMAXPROCS from "/etc/sysconfig/prometheus" -[ -e /etc/sysconfig/node_exporter ] && . /etc/sysconfig/node_exporter +[ -e /etc/sysconfig/<%= @name %> ] && . /etc/sysconfig/<%= @name %> export GOMAXPROCS=${GOMAXPROCS:-2} case "$1" in start) - echo -n "Starting Prometheus node exporter" + echo -n "Starting Prometheus <%= @name %>" ## Start daemon with startproc(8). If this fails ## the return value is set appropriately by startproc. - startproc $NODE_EXPORTER_BIN -collectors.enabled=<%= scope.lookupvar('prometheus::node_exporter::collectors').join(',') %> <%= scope.lookupvar('prometheus::node_exporter::extra_options') %> >> "$LOG_FILE" + <%- require 'shellwords' -%> + startproc $<%= @name %>_BIN <%= Shellwords.escape(@options) %> >> "$LOG_FILE" # Remember status and be verbose rc_status -v ;; stop) - echo -n "Shutting down prometheus " + echo -n "Shutting down <%= @name %> " ## Stop daemon with killproc(8) and if this fails ## killproc sets the return value according to LSB. - killproc -TERM $NODE_EXPORTER_BIN + killproc -TERM $<%= @name %>_BIN # Remember status and be verbose rc_status -v @@ -61,8 +62,8 @@ case "$1" in ;; reload) # If it supports signaling: - echo -n "Reload service prometheus " - killproc -HUP $NODE_EXPORTER_BIN + echo -n "Reload service <%= @name %> " + killproc -HUP $<%= @name %>_BIN #touch /var/run/prometheus.pid rc_status -v @@ -71,7 +72,7 @@ case "$1" in #rc_status -v ;; status) - echo -n "Checking for service prometheus " + echo -n "Checking for service <%= @name %> " ## Check status with checkproc(8), if process is running ## checkproc will return with exit status 0. @@ -84,7 +85,7 @@ case "$1" in # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) # NOTE: checkproc returns LSB compliant status values. - checkproc $NODE_EXPORTER_BIN + checkproc $<%= @name %>_BIN # NOTE: rc_status knows that we called this init script with # "status" option and adapts its messages accordingly. rc_status -v diff --git a/templates/daemon.systemd.erb b/templates/daemon.systemd.erb new file mode 100644 index 000000000..9a1f1456d --- /dev/null +++ b/templates/daemon.systemd.erb @@ -0,0 +1,20 @@ +[Unit] +Description=Prometheus <%= @name %> +Wants=basic.target +After=basic.target network.target + +[Service] +User=<%= @user %> +Group=<%= @group %> +<%- require 'shellwords' -%> +ExecStart=<%= @bin_dir %>/<%= @name %><% for option in Shellwords.split(@options) %> \ +<%= option -%> +<% end %> + +ExecReload=/bin/kill -HUP $MAINPID +KillMode=process +Restart=always +RestartSec=42s + +[Install] +WantedBy=multi-user.target diff --git a/templates/node_exporter.sysv.erb b/templates/daemon.sysv.erb similarity index 56% rename from templates/node_exporter.sysv.erb rename to templates/daemon.sysv.erb index 1d7c4e712..dc65b6cbc 100644 --- a/templates/node_exporter.sysv.erb +++ b/templates/daemon.sysv.erb @@ -1,32 +1,32 @@ #!/bin/bash # -# /etc/rc.d/init.d/node_exporter +# /etc/rc.d/init.d/<%= @name %> # -# Daemonize the prometheus node exporter +# Daemonize the prometheus <%= @name %>. # # chkconfig: 2345 95 20 -# description: Prometheus exporter for machine metrics, written in Go with pluggable metric collectors. -# processname: node_exporter -# pidfile: /var/run/node_exporter/pidfile +# description: Prometheus <%= @name %> +# processname: <%= @name %> +# pidfile: /var/run/<%= @name %>/pidfile # Source function library. . /etc/init.d/functions -DAEMON=<%= scope.lookupvar('prometheus::node_exporter::bin_dir') %>/node_exporter -PID_FILE=/var/run/node_exporter/node_exporter.pid -LOG_FILE=/var/log/node_exporter +DAEMON=<%= @bin_dir %>/<%= @name %> +PID_FILE=/var/run/<%= @name %>/<%= @name %>.pid +LOG_FILE=/var/log/<%= @name %> -[ -e /etc/sysconfig/node_exporter ] && . /etc/sysconfig/node_exporter +[ -e /etc/sysconfig/<%= @name %> ] && . /etc/sysconfig/<%= @name %> export GOMAXPROCS=${GOMAXPROCS:-2} # -# Create the /var/run/node_exporter directory, which can live on a tmpfs +# Create the /var/run/<%= @name %> directory, which can live on a tmpfs # filesystem and be destroyed between reboots. # mkrundir() { - [ ! -d /var/run/node_exporter ] && mkdir -p /var/run/node_exporter - chown <%= scope.lookupvar('prometheus::node_exporter::user') %> /var/run/node_exporter + [ ! -d /var/run/<%= @name %> ] && mkdir -p /var/run/<%= @name %> + chown <%= @user %> /var/run/<%= @name %> } # @@ -38,7 +38,7 @@ mkpidfile() { # Create PID file if it didn't exist mkrundir [ ! -f $PID_FILE ] && pidofproc $DAEMON > $PID_FILE - chown <%= scope.lookupvar('prometheus::node_exporter::user') %> /var/run/node_exporter + chown <%= @user %> /var/run/<%= @name %> if [ $? -ne 0 ] ; then rm $PID_FILE KILLPROC_OPT="" @@ -46,25 +46,26 @@ mkpidfile() { } start() { - echo -n "Starting prometheus node exporter: " + echo -n "Starting prometheus <%= @name %>: " mkrundir [ -f $PID_FILE ] && rm $PID_FILE - daemon --user=<%= scope.lookupvar('prometheus::node_exporter::user') %> \ + daemon --user=<%= @user %> \ --pidfile="$PID_FILE" \ - "$DAEMON" -collectors.enabled=<%= scope.lookupvar('prometheus::node_exporter::collectors').join(',') %> <%= scope.lookupvar('prometheus::node_exporter::extra_options') %> >> "$LOG_FILE" & + <%- require 'shellwords' -%> + "$DAEMON" <%= Shellwords.escape(@options) %> >> "$LOG_FILE" & retcode=$? mkpidfile - touch /var/lock/subsys/node_exporter + touch /var/lock/subsys/<%= @name %> return $retcode } stop() { DELAY=5 # seconds maximum to wait for a leave - echo -n "Shutting down prometheus node_exporter: " + echo -n "Shutting down prometheus <%= @name %>: " mkpidfile - node_exporter_pid=$(cat $PID_FILE) + <%= @name %>_pid=$(cat $PID_FILE) killproc $KILLPROC_OPT $DAEMON -INT retcode=$? @@ -72,8 +73,8 @@ stop() { # early if we can. If not, escalate to harsher signals. try=0 while [ $try -lt $DELAY ]; do - if ! checkpid $node_exporter_pid ; then - rm -f /var/lock/subsys/node_exporter + if ! checkpid $<%= @name %>_pid ; then + rm -f /var/lock/subsys/<%= @name %> return $retcode fi sleep 1 @@ -89,7 +90,7 @@ stop() { killproc $KILLPROC_OPT $DAEMON retcode=$? - rm -f /var/lock/subsys/node_exporter $PID_FILE + rm -f /var/lock/subsys/<%= @name %> $PID_FILE return $retcode } @@ -112,10 +113,10 @@ case "$1" in killproc $KILLPROC_OPT $DAEMON -HUP ;; condrestart) - [ -f /var/lock/subsys/node_exporter ] && restart || : + [ -f /var/lock/subsys/<%= @name %> ] && restart || : ;; *) - echo "Usage: node_exporter {start|stop|status|reload|restart}" + echo "Usage: <%= @name %> {start|stop|status|reload|restart}" exit 1 ;; esac diff --git a/templates/daemon.upstart.erb b/templates/daemon.upstart.erb new file mode 100644 index 000000000..15b0f6256 --- /dev/null +++ b/templates/daemon.upstart.erb @@ -0,0 +1,34 @@ +# Prometheus <%= @name %> (Upstart unit) +description "Prometheus <%= @name %>" +start on runlevel [2345] +stop on runlevel [06] + +env DAEMON=<%= @bin_dir %>/<%= @name %> +env USER=<%= @user %> +env GROUP=<%= @group %> +env DEFAULTS=/etc/default/<%= @name %> +env RUNDIR=/var/run/<%= @name %> +env PID_FILE=/var/run/<%= @name %>/<%= @name %>.pid +pre-start script + [ -e $DEFAULTS ] && . $DEFAULTS + + mkdir -p $RUNDIR || true + chmod 0750 $RUNDIR || true + chown $USER:$GROUP $RUNDIR || true +end script + +script + # read settings like GOMAXPROCS from "/etc/default/<%= @name %>", if available. + [ -e $DEFAULTS ] && . $DEFAULTS + + export GOMAXPROCS=${GOMAXPROCS:-2} + <%- require 'shellwords' -%> + exec start-stop-daemon -c $USER -g $GROUP -p $PID_FILE -x $DAEMON -S -- <% for option in Shellwords.split(@options) %> \ + <%= option -%> + <% end %> + +end script + +respawn +respawn limit 10 10 +kill timeout 10 diff --git a/templates/my.cnf.erb b/templates/my.cnf.erb new file mode 100644 index 000000000..d539a0bb2 --- /dev/null +++ b/templates/my.cnf.erb @@ -0,0 +1,9 @@ +[client] +user = <%= @cnf_user %> +password = <%= @cnf_password %> +<% if @cnf_socket -%> +socket = <%= @cnf_socket %> +<%- else -%> +host = <%= @cnf_host %> +port = <%= @cnf_port %> +<% end -%> diff --git a/templates/node_exporter.launchd.erb b/templates/node_exporter.launchd.erb deleted file mode 100644 index 24c0d1687..000000000 --- a/templates/node_exporter.launchd.erb +++ /dev/null @@ -1,27 +0,0 @@ - - - - - Label io.node_exporter.daemon - UserName <%= scope.lookupvar('prometheus::node_exporter::user') %> - GroupName <%= scope.lookupvar('prometheus::node_exporter::group') %> -<% if scope.lookupvar('prometheus::node_exporter::service_enable') %> - Disabled -<% else %> - Disabled> -<% end %> - RunAtLoad - KeepAlive - ProgramArguments - - <%= scope.lookupvar('prometheus::node_exporter::bin_dir') %>/prometheus - agent - -collectors.enabled= - <%= scope.lookupvar('prometheus::node_exporter::collectors').join(',') %> -<% require 'shellwords' %> -<% for extra_option in Shellwords.split(scope.lookupvar('prometheus::node_exporter::extra_options')) %> - <%= extra_option %> -<% end %> - - - diff --git a/templates/node_exporter.systemd.erb b/templates/node_exporter.systemd.erb deleted file mode 100644 index 47970e7dd..000000000 --- a/templates/node_exporter.systemd.erb +++ /dev/null @@ -1,17 +0,0 @@ -[Unit] -Description=Prometheus exporter for machine metrics, written in Go with pluggable metric collectors. -Wants=basic.target -After=basic.target network.target - -[Service] -User=<%= scope.lookupvar('prometheus::node_exporter::user') %> -Group=<%= scope.lookupvar('prometheus::node_exporter::group') %> -ExecStart=<%= scope.lookupvar('prometheus::node_exporter::bin_dir') %>/node_exporter \ - -collectors.enabled=<%= scope.lookupvar('prometheus::node_exporter::collectors').join(',') %> <%= scope.lookupvar('prometheus::node_exporter::extra_options') %> -ExecReload=/bin/kill -HUP $MAINPID -KillMode=process -Restart=always -RestartSec=42s - -[Install] -WantedBy=multi-user.target diff --git a/templates/node_exporter.upstart.erb b/templates/node_exporter.upstart.erb deleted file mode 100644 index 664d3ca8e..000000000 --- a/templates/node_exporter.upstart.erb +++ /dev/null @@ -1,31 +0,0 @@ -# Prometheus Node Exporter (Upstart unit) -description "Prometheus exporter for machine metrics, written in Go with pluggable metric collectors" -start on runlevel [2345] -stop on runlevel [06] - -env NODE_EXPORTER=<%= scope.lookupvar('prometheus::node_exporter::bin_dir') %>/node_exporter -env COLLECTORS=<%= scope.lookupvar('prometheus::node_exporter::collectors').join(',') %> -env USER=<%= scope.lookupvar('prometheus::node_exporter::user') %> -env GROUP=<%= scope.lookupvar('prometheus::node_exporter::group') %> -env DEFAULTS=/etc/default/node_exporter -env RUNDIR=/var/run/node_exporter -env PID_FILE=/var/run/node_exporter/node_exporter.pid -pre-start script - [ -e $DEFAULTS ] && . $DEFAULTS - - mkdir -p $RUNDIR || true - chmod 0750 $RUNDIR || true - chown $USER:$GROUP $RUNDIR || true -end script - -script - # read settings like GOMAXPROCS from "/etc/default/node_exporter", if available. - [ -e $DEFAULTS ] && . $DEFAULTS - - export GOMAXPROCS=${GOMAXPROCS:-2} - exec start-stop-daemon -c $USER -g $GROUP -p $PID_FILE -x $NODE_EXPORTER -S -- -collectors.enabled=$COLLECTORS <%= scope.lookupvar('prometheus::node_exporter::extra_options') %> -end script - -respawn -respawn limit 10 10 -kill timeout 10 diff --git a/templates/statsd_mapping.conf.erb b/templates/statsd_mapping.conf.erb new file mode 100644 index 000000000..97e500951 --- /dev/null +++ b/templates/statsd_mapping.conf.erb @@ -0,0 +1,7 @@ +<%- @real_statsd_maps.sort!{ |a,b| b[:name] <=> a[:name] }.each do |metric| -%> +<%= metric['map'] %> +name="<%= metric['name'] %>" +<% metric['labels'].sort.each do |key, value| -%> +<%= key %>="<%= value %>" +<% end %> +<%- end -%> diff --git a/tests/init.pp b/tests/init.pp index 4ab89c60e..22e0869b8 100644 --- a/tests/init.pp +++ b/tests/init.pp @@ -1,4 +1,5 @@ include prometheus include prometheus::node_exporter -include prometheus::alert_manager +include prometheus::alertmanager include prometheus::alerts +include prometheus::statsd_exporter