Skip to content

Commit

Permalink
Merge pull request voxpupuli#171 from blupman/master
Browse files Browse the repository at this point in the history
add varnish_exporter
  • Loading branch information
bastelfreak authored Apr 5, 2018
2 parents 8b9b7d2 + 130790e commit 89d4517
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ This module automates the install and configuration of Prometheus monitoring too
* 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
* The following exporters are currently implemented: node_exporter, statsd_exporter, process_exporter, haproxy_exporter, mysqld_exporter, blackbox_exporter, consul_exporter, redis_exporter
* The following exporters are currently implemented: node_exporter, statsd_exporter, process_exporter, haproxy_exporter, mysqld_exporter, blackbox_exporter, consul_exporter, redis_exporter, varnish_exporter

## Usage

Expand Down
8 changes: 8 additions & 0 deletions data/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,11 @@ prometheus::redis_exporter::package_name: 'redis_exporter'
prometheus::redis_exporter::user: 'redis-exporter'
prometheus::redis_exporter::version: '0.11.2'
prometheus::user: 'prometheus'
prometheus::varnish_exporter::download_extension: 'tar.gz'
prometheus::varnish_exporter::download_url_base: 'https://github.com/jonnenauha/prometheus_varnish_exporter/releases'
prometheus::varnish_exporter::extra_groups: []
prometheus::varnish_exporter::group: 'varnish'
prometheus::varnish_exporter::package_ensure: 'latest'
prometheus::varnish_exporter::package_name: 'prometheus_varnish_exporter'
prometheus::varnish_exporter::user: 'varnish_exporter'
prometheus::varnish_exporter::version: '1.4'
129 changes: 129 additions & 0 deletions manifests/varnish_exporter.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Class: prometheus::varnish_exporter
#
# This module manages prometheus varnish_exporter
#
# Parameters:
# [*arch*]
# Architecture (amd64 or i386)
#
# [*bin_dir*]
# Directory where binaries are located
#
# [*cnf_scrape_uri*]
# The URI to obtain HAProxy stats from
#
# [*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::varnish_exporter(
String $download_extension,
Array $extra_groups,
String $group,
String $package_ensure,
String $package_name,
String $user,
String $version,
Variant[Stdlib::HTTPUrl, Stdlib::HTTPSUrl] $download_url_base,
Boolean $purge_config_dir = true,
Boolean $restart_on_change = true,
Boolean $service_enable = true,
$service_ensure = 'running',
String $init_style = $prometheus::init_style,
String $install_method = $prometheus::install_method,
Boolean $manage_group = true,
Boolean $manage_service = true,
Boolean $manage_user = true,
String $os = $prometheus::os,
String $extra_options = '',
Optional[String] $download_url = undef,
String $arch = $prometheus::arch,
Stdlib::Absolutepath $bin_dir = $prometheus::bin_dir,
) inherits prometheus {

$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[$package_name],
default => undef,
}

$options = " ${extra_options}"
prometheus::daemon { $package_name:
install_method => $install_method,
version => $version,
download_extension => $download_extension,
os => $os,
arch => $arch,
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,
real_download_url => $real_download_url,
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,
}
}
32 changes: 32 additions & 0 deletions spec/classes/varnish_exporter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'

describe 'prometheus::varnish_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 version specified' do
let(:params) do
{
version: '1.4',
arch: 'amd64',
os: 'linux',
bin_dir: '/usr/local/bin'
}
end

describe 'install correct binary' do
it { is_expected.to contain_file('/usr/local/bin/prometheus_varnish_exporter').with('target' => '/opt/prometheus_varnish_exporter-1.4.linux-amd64/prometheus_varnish_exporter') }
end
describe 'required resources' do
it { is_expected.to contain_group('varnish') }
it { is_expected.to contain_prometheus__daemon('prometheus_varnish_exporter') }
it { is_expected.to contain_service('prometheus_varnish_exporter') }
it { is_expected.to contain_user('varnish_exporter') }
end
end
end
end
end

0 comments on commit 89d4517

Please sign in to comment.