Skip to content

Commit

Permalink
Merge pull request #157 from yackushevas/master
Browse files Browse the repository at this point in the history
Added redis_exporter module
  • Loading branch information
bastelfreak authored Feb 12, 2018
2 parents 1d13959 + 29633f7 commit 7c223f8
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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
* The following exporters are currently implemented: node_exporter, statsd_exporter, process_exporter, haproxy_exporter, mysqld_exporter, blackbox_exporter, consul_exporter, redis_exporter

## Usage

Expand Down
9 changes: 9 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@
$blackbox_exporter_modules = {}
$blackbox_exporter_config_file = '/etc/blackbox-exporter.yaml'
$blackbox_exporter_version = '0.7.0'
$redis_exporter_redis_address = ['redis://localhost:6379']
$redis_exporter_download_extension = 'tar.gz'
$redis_exporter_download_url_base = 'https://github.com/oliver006/redis_exporter/releases'
$redis_exporter_extra_groups = []
$redis_exporter_group = 'redis-exporter'
$redis_exporter_package_ensure = 'latest'
$redis_exporter_package_name = 'redis_exporter'
$redis_exporter_user = 'redis-exporter'
$redis_exporter_version = '0.11.2'
$user = 'prometheus'
$version = '1.5.2'
case $::architecture {
Expand Down
176 changes: 176 additions & 0 deletions manifests/redis_exporter.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Class: prometheus::redis_exporter
#
# This module manages prometheus node redis_exporter
#
# Parameters:
# [*arch*]
# Architecture (amd64 or i386)
#

# [*bin_dir*]
# Directory where binaries are located
#
# [*addr*]
# Array of address of one or more redis nodes. Defaults to redis://localhost:6379
#
# [*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
# For a full list of the exporter's supported extra options
# please refer to https://github.com/oliver006/redis_exporter
#
# [*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
#
# [*namespace*]
# Namespace for the metrics, defaults to `redis`.
#
# [*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')
#
# [*service_name*]
# Name of the node exporter service (default 'redis_exporter')
#
# [*user*]
# User which runs the service
#
# [*version*]
# The binary release version
class prometheus::redis_exporter (
Array[String] $addr = $::prometheus::params::redis_exporter_redis_address,
String $arch = $::prometheus::params::arch,
String $bin_dir = $::prometheus::params::bin_dir,
String $download_extension = $::prometheus::params::redis_exporter_download_extension,
Optional[String] $download_url = undef,
String $download_url_base = $::prometheus::params::redis_exporter_download_url_base,
Array[String] $extra_groups = $::prometheus::params::redis_exporter_extra_groups,
String $extra_options = '',
String $group = $::prometheus::params::redis_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 $namespace = 'redis',
String $os = $::prometheus::params::os,
String $package_ensure = $::prometheus::params::redis_exporter_package_ensure,
String $package_name = $::prometheus::params::redis_exporter_package_name,
Boolean $purge_config_dir = true,
Boolean $restart_on_change = true,
Boolean $service_enable = true,
String $service_ensure = 'running',
String $service_name = 'redis_exporter',
String $user = $::prometheus::params::redis_exporter_user,
String $version = $::prometheus::params::redis_exporter_version,
) inherits prometheus::params {

$release = "v${version}"

$real_download_url = pick($download_url, "${download_url_base}/download/${release}/${package_name}-${release}.${os}-${arch}.${download_extension}")
$notify_service = $restart_on_change ? {
true => Service[$service_name],
default => undef,
}

$str_addresses = join($addr, ',')
$options = "-redis.addr=${str_addresses} -namespace=${namespace} ${extra_options}"

if $install_method == 'url' {
# Not a big fan of copypasting but prometheus::daemon takes for granted
# a specific path embedded in the prometheus *_exporter tarball, which
# redis_exporter lacks.
# TODO: patch prometheus::daemon to support custom extract directories
$exporter_install_method = 'none'
file { "/opt/${service_name}-${version}.${os}-${arch}":
ensure => 'directory',
owner => 'root',
group => 0, # 0 instead of root because OS X uses "wheel".
mode => '0555',
}
-> archive { "/tmp/${service_name}-${version}.${download_extension}":
ensure => present,
extract => true,
extract_path => "/opt/${service_name}-${version}.${os}-${arch}",
source => $real_download_url,
checksum_verify => false,
creates => "/opt/${name}-${version}.${os}-${arch}/${name}",
cleanup => true,
}
-> file { "${bin_dir}/${service_name}":
ensure => link,
notify => $notify_service,
target => "/opt/${service_name}-${version}.${os}-${arch}/${service_name}",
before => Prometheus::Daemon[$service_name],
}
} else {
$exporter_install_method = $install_method
}

prometheus::daemon { $service_name:
install_method => $exporter_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,
}
}
25 changes: 25 additions & 0 deletions spec/classes/redis_exporter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'spec_helper'

describe 'prometheus::redis_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: '0.11.2',
arch: 'amd64',
os: 'linux'
}
end

describe 'install correct binary' do
it { is_expected.to contain_file('/usr/local/bin/redis_exporter').with('target' => '/opt/redis_exporter-0.11.2.linux-amd64/redis_exporter') }
end
end
end
end
end

0 comments on commit 7c223f8

Please sign in to comment.