From 65e2f085ba63741c898da7eb9a5158369f1fe0fc Mon Sep 17 00:00:00 2001 From: Leo Antunes Date: Wed, 31 Jan 2018 11:18:15 +0100 Subject: [PATCH 1/3] fix quoting of env vars --- spec/defines/daemon_spec.rb | 4 ++-- templates/daemon.env.erb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/defines/daemon_spec.rb b/spec/defines/daemon_spec.rb index a4c306a1a..6b85d2b1b 100644 --- a/spec/defines/daemon_spec.rb +++ b/spec/defines/daemon_spec.rb @@ -153,7 +153,7 @@ 'owner' => 'root', 'group' => 'root' ).with_content( - %r{SOMEVAR=42\n} + %r{SOMEVAR="42"\n} ) } elsif ['centos-6-x86_64', 'redhat-6-x86_64', 'centos-7-x86_64', 'redhat-7-x86_64'].include?(os) @@ -163,7 +163,7 @@ 'owner' => 'root', 'group' => 'root' ).with_content( - %r{SOMEVAR=42\n} + %r{SOMEVAR="42"\n} ) } end diff --git a/templates/daemon.env.erb b/templates/daemon.env.erb index 765629503..f15b409bb 100644 --- a/templates/daemon.env.erb +++ b/templates/daemon.env.erb @@ -1,3 +1,3 @@ <% @env_vars.each do |key, value| -%> -<%= key %>=<%= value %> +<%= key %>="<%= value %>" <% end -%> \ No newline at end of file From b72fc0db67b5e40f577ec0a6b968e6cc42cab1fa Mon Sep 17 00:00:00 2001 From: Leo Antunes Date: Wed, 31 Jan 2018 12:38:48 +0100 Subject: [PATCH 2/3] fix upstart env_vars handling upstart's use of exec means we have to export the variables loaded from the defaults file. Since we're using the same default file for multiple init styles, it seems cleaner to make this exporting explicit on upstart's side. refs #150 --- templates/daemon.upstart.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/daemon.upstart.erb b/templates/daemon.upstart.erb index 15b0f6256..d58b32a04 100644 --- a/templates/daemon.upstart.erb +++ b/templates/daemon.upstart.erb @@ -19,7 +19,9 @@ end script script # read settings like GOMAXPROCS from "/etc/default/<%= @name %>", if available. + set -o allexport [ -e $DEFAULTS ] && . $DEFAULTS + set +o allexport export GOMAXPROCS=${GOMAXPROCS:-2} <%- require 'shellwords' -%> From 7541ae011930680487f883aa59e9d9715a8a15cd Mon Sep 17 00:00:00 2001 From: Leo Antunes Date: Tue, 30 Jan 2018 17:45:57 +0100 Subject: [PATCH 3/3] add rabbitmq_exporter support --- manifests/params.pp | 15 +++ manifests/rabbitmq_exporter.pp | 174 +++++++++++++++++++++++++ spec/classes/rabbitmq_exporter_spec.rb | 36 +++++ 3 files changed, 225 insertions(+) create mode 100644 manifests/rabbitmq_exporter.pp create mode 100644 spec/classes/rabbitmq_exporter_spec.rb diff --git a/manifests/params.pp b/manifests/params.pp index 420cc4832..9e15b8b8f 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -99,6 +99,21 @@ $pushgateway_package_name = 'pushgateway' $pushgateway_user = 'pushgateway' $pushgateway_version = '0.4.0' + $rabbitmq_exporter_download_extension = 'tar.gz' + $rabbitmq_exporter_download_url_base = 'https://github.com/kbudde/rabbitmq_exporter/releases' + $rabbitmq_exporter_extra_groups = [] + $rabbitmq_exporter_group = 'rabbitmq-exporter' + $rabbitmq_exporter_package_ensure = 'latest' + $rabbitmq_exporter_package_name = 'rabbitmq_exporter' + $rabbitmq_exporter_user = 'rabbitmq-exporter' + $rabbitmq_exporter_version = '0.25.2' + $rabbitmq_exporter_rabbit_url = 'http://localhost:15672' + $rabbitmq_exporter_rabbit_user = 'guest' + $rabbitmq_exporter_rabbit_password = 'guest' + $rabbitmq_exporter_queues_include_regex = '.*' + $rabbitmq_exporter_queues_exclude_regex = '^$' + $rabbitmq_exporter_rabbit_capabilities = [] + $rabbitmq_exporter_rabbit_exporters = ['exchange', 'node', 'overview', 'queue'] $mysqld_exporter_cnf_config_path = '/etc/.my.cnf' $mysqld_exporter_cnf_host = 'localhost' $mysqld_exporter_cnf_password = 'password' diff --git a/manifests/rabbitmq_exporter.pp b/manifests/rabbitmq_exporter.pp new file mode 100644 index 000000000..60437a049 --- /dev/null +++ b/manifests/rabbitmq_exporter.pp @@ -0,0 +1,174 @@ +# Class: prometheus::rabbitmq_exporter +# +# This module manages prometheus rabbitmq_exporter +# +# Parameters: +# [*arch*] +# Architecture (amd64 or i386) +# +# [*bin_dir*] +# Directory where binaries are located +# +# [*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 +# +# [*rabbit_url*] +# URL of the RabbitMQ management plugin +# +# [*rabbit_user*] +# User to authenticate against RabbitMQ +# +# [*rabbit_password*] +# Password to authenticate against RabbitMQ +# +# [*queues_include_regex*] +# Regular expression used by the exported to chose which queues to export +# +# [*queues_exclude_regex*] +# Regular expression used by the exported to chose which queues NOT to export +# +# [*rabbit_capabilities*] +# Special capabilities supported by the RabbitMQ version. See README for more details. +# (default '') +# +# [*rabbit_exporters*] +# Which exporter modules should be loaded by default +# (default 'exchange,node,overview,queue') +# +# [*extra_env_vars*] +# Additional environment variables that should be supplied to the exporter, as a hash of key:value +# (default {}) +# +class prometheus::rabbitmq_exporter ( + String $arch = $::prometheus::params::arch, + String $bin_dir = $::prometheus::params::bin_dir, + String $download_extension = $::prometheus::params::rabbitmq_exporter_download_extension, + Optional[String] $download_url = undef, + String $download_url_base = $::prometheus::params::rabbitmq_exporter_download_url_base, + Array[String] $extra_groups = $::prometheus::params::rabbitmq_exporter_extra_groups, + String $extra_options = '', + String $group = $::prometheus::params::rabbitmq_exporter_group, + String $init_style = $::prometheus::params::init_style, + String $install_method = $::prometheus::params::install_method, + Boolean $manage_group = true, + Boolean $manage_service = true, + Boolean $manage_user = true, + String $os = $::prometheus::params::os, + String $package_ensure = $::prometheus::params::rabbitmq_exporter_package_ensure, + String $package_name = $::prometheus::params::rabbitmq_exporter_package_name, + Boolean $purge_config_dir = true, + Boolean $restart_on_change = true, + Boolean $service_enable = true, + String $service_ensure = 'running', + String $user = $::prometheus::params::rabbitmq_exporter_user, + String $version = $::prometheus::params::rabbitmq_exporter_version, + String $rabbit_url = $::prometheus::params::rabbitmq_exporter_rabbit_url, + String $rabbit_user = $::prometheus::params::rabbitmq_exporter_rabbit_user, + String $rabbit_password = $::prometheus::params::rabbitmq_exporter_rabbit_password, + String $queues_include_regex = $::prometheus::params::rabbitmq_exporter_queues_include_regex, + String $queues_exclude_regex = $::prometheus::params::rabbitmq_exporter_queues_exclude_regex, + Array[String] $rabbit_capabilities = $::prometheus::params::rabbitmq_exporter_rabbit_capabilities, + Array[String] $rabbit_exporters = $::prometheus::params::rabbitmq_exporter_rabbit_exporters, + Hash[String,String] $extra_env_vars = {}, +) inherits prometheus::params { + + $real_download_url = pick($download_url, "${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}") + $notify_service = $restart_on_change ? { + true => Service['rabbitmq_exporter'], + default => undef, + } + + $env_vars = { + 'RABBIT_URL' => $rabbit_url, + 'RABBIT_USER' => $rabbit_user, + 'RABBIT_PASSWORD' => $rabbit_password, + 'INCLUDE_QUEUES' => $queues_include_regex, + 'SKIP_QUEUES' => $queues_exclude_regex, + 'RABBIT_CAPABILITIES' => join($rabbit_capabilities, ','), + 'RABBIT_EXPORTERS' => join($rabbit_exporters, ','), + } + + $real_env_vars = merge($env_vars, $extra_env_vars) + + prometheus::daemon { 'rabbitmq_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 => $extra_options, + init_style => $init_style, + service_ensure => $service_ensure, + service_enable => $service_enable, + manage_service => $manage_service, + env_vars => $real_env_vars, + } +} diff --git a/spec/classes/rabbitmq_exporter_spec.rb b/spec/classes/rabbitmq_exporter_spec.rb new file mode 100644 index 000000000..baec28d22 --- /dev/null +++ b/spec/classes/rabbitmq_exporter_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe 'prometheus::rabbitmq_exporter' do + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + + context 'with version specified' do + let(:params) do + { + version: '1.0.0', + arch: 'amd64', + os: 'linux' + } + end + + describe 'compile manifest' do + it { is_expected.to compile.with_all_deps } + end + + describe 'install correct binary' do + it { is_expected.to contain_file('/usr/local/bin/rabbitmq_exporter').with('target' => '/opt/rabbitmq_exporter-1.0.0.linux-amd64/rabbitmq_exporter') } + end + + describe 'required resources' do + it { is_expected.to contain_prometheus__daemon('rabbitmq_exporter') } + it { is_expected.to contain_user('rabbitmq-exporter') } + it { is_expected.to contain_group('rabbitmq-exporter') } + it { is_expected.to contain_service('rabbitmq_exporter') } + end + end + end + end +end