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

Add apache exporter support #284

Merged
merged 1 commit into from
Jan 16, 2019
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
9 changes: 9 additions & 0 deletions data/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,12 @@ prometheus::collectd_exporter::manage_group: true
prometheus::collectd_exporter::manage_service: true
prometheus::collectd_exporter::manage_user: true
prometheus::collectd_exporter::options: ''
prometheus::apache_exporter::scrape_uri: 'http://localhost/server-status?auto'
prometheus::apache_exporter::download_extension: 'tar.gz'
prometheus::apache_exporter::download_url_base: 'https://github.com/Lusitaniae/apache_exporter/releases'
prometheus::apache_exporter::extra_groups: []
prometheus::apache_exporter::group: 'apache-exporter'
prometheus::apache_exporter::package_ensure: 'latest'
prometheus::apache_exporter::package_name: 'apache_exporter'
prometheus::apache_exporter::user: 'apache-exporter'
prometheus::apache_exporter::version: '0.5.0'
137 changes: 137 additions & 0 deletions manifests/apache_exporter.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Class: prometheus::apache_exporter
#
# This module manages prometheus apache_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)
#
# [*scrape_uri*]
# The URI for the Apache status page
#
# [*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::apache_exporter (
String[1] $scrape_uri,
String[1] $download_extension,
Variant[Stdlib::HTTPSUrl, Stdlib::HTTPUrl] $download_url_base,
Array[String[1]] $extra_groups,
String[1] $group,
String[1] $package_ensure,
String[1] $package_name,
String[1] $user,
String[1] $version,
Boolean $purge_config_dir = true,
Boolean $restart_on_change = true,
Boolean $service_enable = true,
String[1] $service_ensure = 'running',
String[1] $init_style = $prometheus::init_style,
String[1] $install_method = $prometheus::install_method,
Boolean $manage_group = true,
Boolean $manage_service = true,
Boolean $manage_user = true,
String[1] $os = $prometheus::os,
String $extra_options = '',
Optional[Variant[Stdlib::HTTPSUrl, Stdlib::HTTPUrl]] $download_url = undef,
String[1] $config_mode = $prometheus::config_mode,
String[1] $arch = $prometheus::real_arch,
Stdlib::Absolutepath $bin_dir = $prometheus::bin_dir,
) inherits prometheus {

#Please provide the download_url for versions < 0.9.0
$real_download_url = pick($download_url,"${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}")
$notify_service = $restart_on_change ? {
true => Service['apache_exporter'],
default => undef,
}

$options = "-scrape_uri \"${scrape_uri}\" ${extra_options}"

prometheus::daemon { 'apache_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,
}
}
69 changes: 69 additions & 0 deletions spec/acceptance/apache_exporter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require 'spec_helper_acceptance'

describe 'prometheus apache exporter' do
it 'apache_exporter works idempotently with no errors' do
if default[:platform] =~ %r{ubuntu-18.04-amd64}
pp = "package{'iproute2': ensure => present}"
apply_manifest(pp, catch_failures: true)
end
pp = 'include prometheus::apache_exporter'
# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe 'default install' do
describe service('apache_exporter') do
it { is_expected.to be_running }
it { is_expected.to be_enabled }
end
# the class installs an the apache_exporter that listens on port 9104
describe port(9117) do
it { is_expected.to be_listening.with('tcp6') }
end
describe process('apache_exporter') do
its(:args) { is_expected.to match %r{\ -scrape_uri http://localhost/server-status\?auto} }
end
end

describe 'apache_exporter update from 0.4.0 to 0.5.0' do
it 'is idempotent' do
pp = "class{'prometheus::apache_exporter': version => '0.4.0'}"
# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe service('apache_exporter') do
it { is_expected.to be_running }
it { is_expected.to be_enabled }
end

describe process('apache_exporter') do
its(:args) { is_expected.to match %r{\ -scrape_uri http://localhost/server-status\?auto} }
end

describe port(9117) do
it { is_expected.to be_listening.with('tcp6') }
end
it 'is idempotent' do
pp = "class{'prometheus::apache_exporter': version => '0.5.0'}"
# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe service('apache_exporter') do
it { is_expected.to be_running }
it { is_expected.to be_enabled }
end

describe process('apache_exporter') do
its(:args) { is_expected.to match %r{\ -scrape_uri http://localhost/server-status\?auto} }
end

describe port(9117) do
it { is_expected.to be_listening.with('tcp6') }
end
end
end
63 changes: 63 additions & 0 deletions spec/classes/apache_exporter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require 'spec_helper'

describe 'prometheus::apache_exporter' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts.merge(os_specific_facts(facts))
end

context 'with all defaults' do
let(:params) do
{
version: '0.5.0',
arch: 'amd64',
os: 'linux',
bin_dir: '/usr/local/bin',
install_method: 'url'
}
end

describe 'with specific params' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_archive('/tmp/apache_exporter-0.5.0.tar.gz') }
it { is_expected.to contain_class('prometheus') }
it { is_expected.to contain_group('apache-exporter') }
it { is_expected.to contain_user('apache-exporter') }
it { is_expected.to contain_prometheus__daemon('apache_exporter').with('options' => '-scrape_uri "http://localhost/server-status?auto" ') }
it { is_expected.to contain_service('apache_exporter') }
end
describe 'install correct binary' do
it { is_expected.to contain_file('/usr/local/bin/apache_exporter').with('target' => '/opt/apache_exporter-0.5.0.linux-amd64/apache_exporter') }
end
end

context 'with version, scrape_uri and extra options specified' do
let(:params) do
{
scrape_uri: 'http://127.0.0.1/server-status?auto',
extra_options: '-test',
version: '0.4.0',
arch: 'amd64',
os: 'linux',
bin_dir: '/usr/local/bin',
install_method: 'url'
}
end

describe 'with specific params' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_archive('/tmp/apache_exporter-0.4.0.tar.gz') }
it { is_expected.to contain_class('prometheus') }
it { is_expected.to contain_group('apache-exporter') }
it { is_expected.to contain_user('apache-exporter') }
it { is_expected.to contain_prometheus__daemon('apache_exporter').with('options' => '-scrape_uri "http://127.0.0.1/server-status?auto" -test') }
it { is_expected.to contain_service('apache_exporter') }
end
describe 'install correct binary' do
it { is_expected.to contain_file('/usr/local/bin/apache_exporter').with('target' => '/opt/apache_exporter-0.4.0.linux-amd64/apache_exporter') }
end
end
end
end
end