Skip to content

Commit

Permalink
Add iperf3 experter
Browse files Browse the repository at this point in the history
Change-Id: I9e4a0166d789bcc553bfb59f621846339fa8ded4
  • Loading branch information
onstring committed Mar 11, 2022
1 parent 6637238 commit 8c81135
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 0 deletions.
113 changes: 113 additions & 0 deletions manifests/iperf3_exporter.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# @summary This module manages prometheus node iperf3_exporter
# @param arch
# Architecture (amd64 or i386)
# @param bin_dir
# Directory where binaries are located
# @param download_extension
# Extension for the release binary archive
# @param download_url
# Complete URL corresponding to the where the release binary archive can be downloaded
# @param download_url_base
# Base URL for the binary archive
# @param options
# Options added to the startup command
# @param extra_groups
# Extra groups to add the binary user to
# @param group
# Group under which the binary is running
# @param init_style
# Service startup scripts style (e.g. rc, upstart or systemd)
# @param install_method
# Installation method: url or package (only url is supported currently)
# @param manage_group
# Whether to create a group for or rely on external code for that
# @param manage_service
# Should puppet manage the service? (default true)
# @param manage_user
# Whether to create user or rely on external code for that
# @param os
# Operating system (linux is the only one supported)
# @param package_ensure
# If package, then use this for package ensure default 'latest'
# @param package_name
# The binary package name - not available yet
# @param purge_config_dir
# Purge config files no longer generated by Puppet
# @param restart_on_change
# Should puppet restart the service on configuration change? (default true)
# @param service_enable
# Whether to enable the service from puppet (default true)
# @param service_ensure
# State ensured for the service (default 'running')
# @param service_name
# Name of the iperf3 exporter service (default 'iperf3_exporter')
# @param user
# User which runs the service
# @param version
# The binary release version
class prometheus::iperf3_exporter (
String[1] $download_extension = 'tar.gz',
Prometheus::Uri $download_url_base = 'https://github.com/edgard/iperf3_exporter/releases',
Array[String[1]] $extra_groups = [],
String[1] $group = 'iperf3-exporter',
String[1] $package_ensure = 'latest',
String[1] $package_name = 'iperf3_exporter',
String[1] $service_name = 'iperf3_exporter',
String[1] $user = 'iperf3-exporter',
String[1] $version = '0.1.3',
String[1] $os = downcase($facts['kernel']),
String $options = '',
Prometheus::Initstyle $init_style = $facts['service_provider'],
Prometheus::Install $install_method = $prometheus::install_method,
Optional[Prometheus::Uri] $download_url = undef,
String[1] $arch = $prometheus::real_arch,
Stdlib::AbsolutePath $bin_dir = $prometheus::bin_dir,
Boolean $export_scrape_job = false,
Optional[Stdlib::Host] $scrape_host = undef,
Stdlib::Port $scrape_port = 9579,
String[1] $scrape_job_name = 'iperf3',
Optional[Hash] $scrape_job_labels = undef,
Boolean $service_enable = true,
Boolean $manage_service = true,
Stdlib::Ensure::Service $service_ensure = 'running',
Boolean $restart_on_change = true,
Boolean $purge_config_dir = true,
Boolean $manage_user = true,
Boolean $manage_group = true,
) inherits prometheus {
$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[$service_name],
default => undef,
}

prometheus::daemon { 'iperf3_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,
export_scrape_job => $export_scrape_job,
scrape_host => $scrape_host,
scrape_port => $scrape_port,
scrape_job_name => $scrape_job_name,
scrape_job_labels => $scrape_job_labels,
}
}
56 changes: 56 additions & 0 deletions spec/acceptance/iperf3_exporter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'prometheus iperf3_exporter' do
it 'iperf3_exporter works idempotently with no errors' do
pp = 'include prometheus::iperf3_exporter'
# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

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

describe port(9579) do
it { is_expected.to be_listening.with('tcp6') }
end

# rubocop:disable RSpec/RepeatedExampleGroupBody,RSpec/RepeatedExampleGroupDescription
describe 'iperf3_exporter update from 0.1.2 to 0.1.3' do
it 'is idempotent' do
pp = "class{'prometheus::iperf3_exporter': version => '0.1.2'}"
# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

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

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

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

describe port(9579) do
it { is_expected.to be_listening.with('tcp6') }
end
end
# rubocop:enable RSpec/RepeatedExampleGroupBody,RSpec/RepeatedExampleGroupDescription
end
34 changes: 34 additions & 0 deletions spec/classes/iperf3_exporter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require 'spec_helper'

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

context 'without parameters' do
it { is_expected.to contain_prometheus__daemon('iperf3_exporter') }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_group('iperf3-exporter') }
it { is_expected.to contain_service('iperf3_exporter') }
it { is_expected.to contain_user('iperf3-exporter') }
it { is_expected.to contain_class('prometheus') }
end

context 'with params' do
let :params do
{
install_method: 'url',
version: '0.1.3'
}
end

it { is_expected.to contain_archive('/tmp/iperf3_exporter-0.1.3.tar.gz') }
it { is_expected.to contain_file('/opt/iperf3_exporter-0.1.3.linux-amd64/iperf3_exporter') }
end
end
end
end

0 comments on commit 8c81135

Please sign in to comment.