Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

messagebird/beanstalkd_exporter support #105

Merged
merged 2 commits into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
include ::prometheus::statsd_exporter
include ::prometheus::process_exporter
include ::prometheus::blackbox_exporter
include ::prometheus::beanstalkd_exporter
155 changes: 155 additions & 0 deletions manifests/beanstalkd_exporter.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# Class: prometheus::beanstalkd_exporter
#
# This module manages prometheus beanstalkd_exporter
#
# Parameters:
# [*arch*]
# Architecture (amd64 or i386)
#
# [*bin_dir*]
# Directory where binaries are located
#
# [*config*]
# Path to configuration file that stores beanstalkd address
#
# [*mapping_config*]
# Path to configuration file with tubes mappings (not implemented)
#
# [*beanstalkd_address*]
# Address of beanstalkd, defaults to localhost
#
# [*exporter_listen*]
# Address to bind beanstalkd_exporter to. Default is different than upstream (*:9371)
#
# [*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::beanstalkd_exporter (
String $arch = $::prometheus::params::arch,
String $bin_dir = $::prometheus::params::bin_dir,
String $download_extension = $::prometheus::params::beanstalkd_exporter_download_extension,
Variant[Undef,String] $download_url = undef,
String $download_url_base = $::prometheus::params::beanstalkd_exporter_download_url_base,
Array $extra_groups = $::prometheus::params::beanstalkd_exporter_extra_groups,
String $extra_options = '',
String $group = $::prometheus::params::beanstalkd_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::beanstalkd_exporter_package_ensure,
String $package_name = $::prometheus::params::beanstalkd_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::beanstalkd_exporter_user,
String $version = $::prometheus::params::beanstalkd_exporter_version,
String $config = $::prometheus::params::beanstalkd_exporter_config,
String $mapping_config = $::prometheus::params::beanstalkd_exporter_mapping_config,
String $beanstalkd_address = $::prometheus::params::beanstalkd_exporter_beanstalkd_address,
String $exporter_listen = $::prometheus::params::beanstalkd_exporter_listen,
) inherits prometheus::params {
#Please provide the download_url for versions < 0.9.0
$real_download_url = pick($download_url,"${download_url_base}/download/${version}/${package_name}-${version}.${os}-${arch}.${download_extension}")

$notify_service = $restart_on_change ? {
true => Service['beanstalkd_exporter'],
default => undef,
}

$options = "-listen-address ${exporter_listen} -config ${config} -mapping-config ${mapping_config} ${extra_options}"

file { $config:
ensure => file,
content => $beanstalkd_address,
before => Prometheus::Daemon['beanstalkd_exporter'],
}

file { $mapping_config:
ensure => file,
before => Prometheus::Daemon['beanstalkd_exporter'],
}

prometheus::daemon { 'beanstalkd_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,
}
}
12 changes: 12 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@
$node_exporter_package_name = 'node_exporter'
$node_exporter_user = 'node-exporter'
$node_exporter_version = '0.14.0'
$beanstalkd_exporter_listen = ':9371'
$beanstalkd_exporter_beanstalkd_address = '127.0.0.1:11300'
$beanstalkd_exporter_download_extension = 'tar.gz'
$beanstalkd_exporter_download_url_base = 'https://github.com/messagebird/beanstalkd_exporter/releases'
$beanstalkd_exporter_extra_groups = []
$beanstalkd_exporter_group = 'beanstalkd-exporter'
$beanstalkd_exporter_package_ensure = 'latest'
$beanstalkd_exporter_package_name = 'beanstalkd_exporter'
$beanstalkd_exporter_user = 'beanstalkd-exporter'
$beanstalkd_exporter_version = '1.0.0'
$beanstalkd_exporter_mapping_config = '/etc/beanstalkd-exporter-mapping.conf'
$beanstalkd_exporter_config = '/etc/beanstalkd-exporter.conf'
$package_ensure = 'latest'
$package_name = 'prometheus'
$rule_files = [ "${config_dir}/alert.rules" ]
Expand Down
29 changes: 29 additions & 0 deletions spec/classes/beanstalkd_exporter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

describe 'prometheus::beanstalkd_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/beanstalkd_exporter').with('target' => '/opt/beanstalkd_exporter-1.0.0.linux-amd64/beanstalkd_exporter') }
end
end
end
end
end