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 nginx-vts-exporter #71

Merged
merged 4 commits into from
Oct 18, 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
136 changes: 136 additions & 0 deletions manifests/nginx_vts_exporter.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Class: prometheus::nginx_vts_exporter
#
# This module manages prometheus nginx_vts_exporter
#
# Parameters:
# [*arch*]
# Architecture (amd64 or i386)
#
# [*bin_dir*]
# Directory where binaries are located
#
# [*nginx_scrape_uri*]
# The URI to obtain nginx JSON 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::nginx_vts_exporter(
String $arch = $::prometheus::params::arch,
String $bin_dir = $::prometheus::params::bin_dir,
String $nginx_scrape_uri = $::prometheus::params::nginx_vts_exporter_nginx_scrape_uri,
String $download_extension = $::prometheus::params::nginx_vts_exporter_download_extension,
Variant[Undef,String] $download_url = undef,
String $download_url_base = $::prometheus::params::nginx_vts_exporter_download_url_base,
Array $extra_groups = $::prometheus::params::nginx_vts_exporter_extra_groups,
String $extra_options = '',
String $group = $::prometheus::params::nginx_vts_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::nginx_vts_exporter_package_ensure,
String $package_name = $::prometheus::params::nginx_vts_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::nginx_vts_exporter_user,
String $version = $::prometheus::params::nginx_vts_exporter_version,
) inherits prometheus::params {

$real_download_url = pick($download_url,"${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}")
validate_bool($purge_config_dir)
validate_bool($manage_user)
validate_bool($manage_service)
validate_bool($restart_on_change)
$notify_service = $restart_on_change ? {
true => Service['nginx-vts-exporter'],
default => undef,
}

$options = "-nginx.scrape_uri=\"${nginx_scrape_uri}\" ${extra_options}"

prometheus::daemon { 'nginx-vts-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,
}

}
9 changes: 9 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@
$haproxy_exporter_package_name = 'haproxy_exporter'
$haproxy_exporter_user = 'haproxy-user'
$haproxy_exporter_version = '0.7.1'
$nginx_vts_exporter_nginx_scrape_uri = 'http://localhost/status/format/json'
$nginx_vts_exporter_download_extension = 'tar.gz'
$nginx_vts_exporter_download_url_base = 'https://github.com/hnlq715/nginx-vts-exporter/releases'
$nginx_vts_exporter_extra_groups = []
$nginx_vts_exporter_group = 'nginx-vts-exporter'
$nginx_vts_exporter_package_ensure = 'latest'
$nginx_vts_exporter_package_name = 'nginx-vts-exporter'
$nginx_vts_exporter_user = 'nginx-vts-exporter'
$nginx_vts_exporter_version = '0.6'
$process_exporter_download_extension = 'tar.gz'
$process_exporter_download_url_base = 'https://github.com/ncabatoff/process-exporter/releases'
$process_exporter_extra_groups = []
Expand Down
26 changes: 26 additions & 0 deletions spec/classes/nginx_vts_exporter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'spec_helper'

describe 'prometheus::nginx_vts_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.6',
arch: 'amd64',
os: 'linux'
}
end

describe 'install correct binary' do
it { is_expected.to contain_file('/usr/local/bin/nginx-vts-exporter').with('target' => '/opt/nginx-vts-exporter-0.6.linux-amd64/nginx-vts-exporter') }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add:

it { is_expected.to compile.with_all_deps }

it { is_expected.to compile.with_all_deps }
end
end
end
end
end