From b34fd461a73047031b70a0ca0efbee8aa0f5e425 Mon Sep 17 00:00:00 2001 From: viq Date: Wed, 18 Oct 2017 13:24:00 +0200 Subject: [PATCH 1/4] Add nginx-vts-exporter --- manifests/nginx_vts_exporter.pp | 136 ++++++++++++++++++++++++++++++++ manifests/params.pp | 9 +++ 2 files changed, 145 insertions(+) create mode 100644 manifests/nginx_vts_exporter.pp diff --git a/manifests/nginx_vts_exporter.pp b/manifests/nginx_vts_exporter.pp new file mode 100644 index 000000000..edbf1c186 --- /dev/null +++ b/manifests/nginx_vts_exporter.pp @@ -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( + $arch = $::prometheus::params::arch, + $bin_dir = $::prometheus::params::bin_dir, + $nginx_scrape_uri = $::prometheus::params::nginx_vts_exporter_nginx_scrape_uri, + $download_extension = $::prometheus::params::nginx_vts_exporter_download_extension, + $download_url = undef, + $download_url_base = $::prometheus::params::nginx_vts_exporter_download_url_base, + $extra_groups = $::prometheus::params::nginx_vts_exporter_extra_groups, + $extra_options = '', + $group = $::prometheus::params::nginx_vts_exporter_group, + $init_style = $::prometheus::params::init_style, + $install_method = $::prometheus::params::install_method, + $manage_group = true, + $manage_service = true, + $manage_user = true, + $os = $::prometheus::params::os, + $package_ensure = $::prometheus::params::nginx_vts_exporter_package_ensure, + $package_name = $::prometheus::params::nginx_vts_exporter_package_name, + $purge_config_dir = true, + $restart_on_change = true, + $service_enable = true, + $service_ensure = 'running', + $user = $::prometheus::params::nginx_vts_exporter_user, + $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, + } + +} diff --git a/manifests/params.pp b/manifests/params.pp index e8c081780..142384130 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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 = [] From bb48133c36fe12cdbbca426b434307db155fe742 Mon Sep 17 00:00:00 2001 From: viq Date: Wed, 18 Oct 2017 13:42:48 +0200 Subject: [PATCH 2/4] Add puppet4 datatypes --- manifests/nginx_vts_exporter.pp | 46 ++++++++++++++++----------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/manifests/nginx_vts_exporter.pp b/manifests/nginx_vts_exporter.pp index edbf1c186..eecc79ea0 100644 --- a/manifests/nginx_vts_exporter.pp +++ b/manifests/nginx_vts_exporter.pp @@ -72,29 +72,29 @@ # [*version*] # The binary release version class prometheus::nginx_vts_exporter( - $arch = $::prometheus::params::arch, - $bin_dir = $::prometheus::params::bin_dir, - $nginx_scrape_uri = $::prometheus::params::nginx_vts_exporter_nginx_scrape_uri, - $download_extension = $::prometheus::params::nginx_vts_exporter_download_extension, - $download_url = undef, - $download_url_base = $::prometheus::params::nginx_vts_exporter_download_url_base, - $extra_groups = $::prometheus::params::nginx_vts_exporter_extra_groups, - $extra_options = '', - $group = $::prometheus::params::nginx_vts_exporter_group, - $init_style = $::prometheus::params::init_style, - $install_method = $::prometheus::params::install_method, - $manage_group = true, - $manage_service = true, - $manage_user = true, - $os = $::prometheus::params::os, - $package_ensure = $::prometheus::params::nginx_vts_exporter_package_ensure, - $package_name = $::prometheus::params::nginx_vts_exporter_package_name, - $purge_config_dir = true, - $restart_on_change = true, - $service_enable = true, - $service_ensure = 'running', - $user = $::prometheus::params::nginx_vts_exporter_user, - $version = $::prometheus::params::nginx_vts_exporter_version, + 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}") From 0c8c11be3f2494788c29c2cf07c393ed14f5de7c Mon Sep 17 00:00:00 2001 From: viq Date: Wed, 18 Oct 2017 13:46:24 +0200 Subject: [PATCH 3/4] Basic test for nginx_vts_exporter --- spec/classes/nginx_vts_exporter_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 spec/classes/nginx_vts_exporter_spec.rb diff --git a/spec/classes/nginx_vts_exporter_spec.rb b/spec/classes/nginx_vts_exporter_spec.rb new file mode 100644 index 000000000..3e09446b8 --- /dev/null +++ b/spec/classes/nginx_vts_exporter_spec.rb @@ -0,0 +1,25 @@ +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') } + end + end + end + end +end From 704b660705840e6b7ffd2a64362d2e7716d0690a Mon Sep 17 00:00:00 2001 From: viq Date: Wed, 18 Oct 2017 13:49:50 +0200 Subject: [PATCH 4/4] Further test improvements --- spec/classes/nginx_vts_exporter_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/classes/nginx_vts_exporter_spec.rb b/spec/classes/nginx_vts_exporter_spec.rb index 3e09446b8..09478f517 100644 --- a/spec/classes/nginx_vts_exporter_spec.rb +++ b/spec/classes/nginx_vts_exporter_spec.rb @@ -18,6 +18,7 @@ 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') } + it { is_expected.to compile.with_all_deps } end end end