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

(SUP-3881) Add collection for PE console services #174

Merged
merged 2 commits into from
Jan 25, 2023
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
5 changes: 5 additions & 0 deletions files/json2timeseriesdb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ def influx_tag_parser(tag)
tag.delete('orchestrator')
end

if tag.include? 'console'
tag_set = "#{tag_set}service=console,"
tag.delete('console')
end

if tag.include? 'puppetserver'
tag_set = "#{tag_set}service=puppetserver,"
tag.delete('puppetserver')
Expand Down
4 changes: 3 additions & 1 deletion files/metrics_tidy
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

#shellcheck disable=SC2317

fail() {
# Restore stdout by pointing it to fd 3 and send any errors to it
exec >&3
Expand Down Expand Up @@ -43,7 +45,7 @@ done


# Guard against deleting or archiving files outside of a Puppet service metrics directory.
valid_paths=(puppetserver puppetdb orchestrator ace bolt activemq postgres system_processes system_memory system_cpu vmware)
valid_paths=(puppetserver puppetdb orchestrator console ace bolt activemq postgres system_processes system_memory system_cpu vmware)

# Arguments and defaults.
metrics_directory="${metrics_directory:-/opt/puppetlabs/puppet-metrics-collector/puppetserver}"
Expand Down
17 changes: 17 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
# @param orchestrator_port
# Port to connect to orchestrator on. Default: '8143'
#
#
# @param console_metrics_ensure
# Whether to enable or disable the collection of PE Console metrics. Valid values are 'present', and 'absent'. Default : 'present'
#
# @param console_hosts
# The list of console hosts to collect metrics from. Uses the hosts_with_pe_profile function to determine the list of hosts with the console profile.
#
# @param console_port
# Port to connect to console on. Default: '4433'
#
# @param ace_metrics_ensure
# Whether to enable or disable the collection of Ace metrics. Valid values are 'present', and 'absent'. Default : 'present'
#
Expand Down Expand Up @@ -83,6 +93,8 @@
# An Array of metrics to exclude from the puppetdb metrics collection.
# @param orchestrator_excludes
# An Array of metrics to exclude from the orchestrator_excludes metrics collection.
# @param console_excludes
# An Array of metrics to exclude from the console_excludes metrics collection.
# @param ace_excludes
# An Array of metrics to exclude from the ace_excludes metrics collection.
# @param bolt_excludes
Expand Down Expand Up @@ -111,6 +123,9 @@
String $orchestrator_metrics_ensure = 'present',
Array[String] $orchestrator_hosts = puppet_metrics_collector::hosts_with_pe_profile('orchestrator'),
Integer $orchestrator_port = 8143,
String $console_metrics_ensure = 'present',
Array[String] $console_hosts = puppet_metrics_collector::hosts_with_pe_profile('console'),
Integer $console_port = 4433,
String $ace_metrics_ensure = 'present',
Array[String] $ace_hosts = puppet_metrics_collector::hosts_with_pe_profile('ace_server'),
Integer $ace_port = 44633,
Expand All @@ -125,6 +140,7 @@
Optional[Array[String]] $puppetserver_excludes = undef,
Optional[Array[String]] $puppetdb_excludes = undef,
Optional[Array[String]] $orchestrator_excludes = undef,
Optional[Array[String]] $console_excludes = undef,
Optional[Array[String]] $ace_excludes = undef,
Optional[Array[String]] $bolt_excludes = undef,
Optional[Array[String]] $activemq_excludes = undef,
Expand Down Expand Up @@ -194,6 +210,7 @@
include puppet_metrics_collector::service::puppetserver
include puppet_metrics_collector::service::puppetdb
include puppet_metrics_collector::service::orchestrator
include puppet_metrics_collector::service::console
include puppet_metrics_collector::service::ace
include puppet_metrics_collector::service::bolt

Expand Down
33 changes: 33 additions & 0 deletions manifests/service/console.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# @summary Collects console metrics
#
# @api private
#
class puppet_metrics_collector::service::console (
String $metrics_ensure = $puppet_metrics_collector::console_metrics_ensure,
Integer $collection_frequency = $puppet_metrics_collector::collection_frequency,
Integer $retention_days = $puppet_metrics_collector::retention_days,
Array[String] $hosts = $puppet_metrics_collector::console_hosts,
Integer $port = $puppet_metrics_collector::console_port,
Array[Hash] $extra_metrics = [],
Optional[String] $override_metrics_command = $puppet_metrics_collector::override_metrics_command,
Optional[Array[String]] $excludes = $puppet_metrics_collector::console_excludes,
Optional[Enum['influxdb', 'graphite', 'splunk_hec']] $metrics_server_type = $puppet_metrics_collector::metrics_server_type,
Optional[String] $metrics_server_hostname = $puppet_metrics_collector::metrics_server_hostname,
Optional[Integer] $metrics_server_port = $puppet_metrics_collector::metrics_server_port,
Optional[String] $metrics_server_db_name = $puppet_metrics_collector::metrics_server_db_name,
) {
puppet_metrics_collector::pe_metric { 'console' :
metric_ensure => $metrics_ensure,
cron_minute => "0/${collection_frequency}",
retention_days => $retention_days,
hosts => $hosts,
metrics_port => $port,
additional_metrics => $extra_metrics,
override_metrics_command => $override_metrics_command,
excludes => $excludes,
metrics_server_type => $metrics_server_type,
metrics_server_hostname => $metrics_server_hostname,
metrics_server_port => $metrics_server_port,
metrics_server_db_name => $metrics_server_db_name,
}
}
16 changes: 14 additions & 2 deletions spec/acceptance/pe_metric_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
it { expect(service('puppet_bolt-tidy.timer')).to be_running }
it { expect(service('puppet_orchestrator-metrics.timer')).to be_running }
it { expect(service('puppet_orchestrator-tidy.timer')).to be_running }
it { expect(service('puppet_console-metrics.timer')).to be_running }
it { expect(service('puppet_console-tidy.timer')).to be_running }
it { expect(service('puppet_puppetdb-metrics.timer')).to be_running }
it { expect(service('puppet_puppetdb-tidy.timer')).to be_running }
it { expect(service('puppet_puppetserver-metrics.timer')).to be_running }
Expand All @@ -24,12 +26,12 @@

it 'creates tidy services files' do
files = run_shell('ls /etc/systemd/system/puppet_*-tidy.service').stdout
expect(files.split("\n").count).to eq(5)
expect(files.split("\n").count).to eq(6)
end

it 'creates the timer files' do
files = run_shell('ls /etc/systemd/system/puppet_*-tidy.timer').stdout
expect(files.split("\n").count).to eq(5)
expect(files.split("\n").count).to eq(6)
end

describe file("/opt/puppetlabs/puppet-metrics-collector/puppetserver/#{certname}") do
Expand Down Expand Up @@ -62,6 +64,16 @@
end
end

describe file("/opt/puppetlabs/puppet-metrics-collector/console/#{certname}") do
before(:each) { run_shell('systemctl start puppet_console-metrics.service') }

it { is_expected.to be_directory }
it 'contains metric files' do
files = run_shell("ls /opt/puppetlabs/puppet-metrics-collector/console/#{certname}/*").stdout
expect(files.split('\n')).not_to be_empty
end
end

describe file("/opt/puppetlabs/puppet-metrics-collector/ace/#{certname}") do
before(:each) { run_shell('systemctl start puppet_ace-metrics.service') }

Expand Down
2 changes: 1 addition & 1 deletion spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
context 'when customizing the collection frequency' do
let(:params) { { collection_frequency: 10 } }

['ace', 'bolt', 'orchestrator', 'puppetdb', 'puppetserver'].each do |service|
['ace', 'bolt', 'orchestrator', 'console', 'puppetdb', 'puppetserver'].each do |service|
it { is_expected.to contain_file("/etc/systemd/system/puppet_#{service}-metrics.timer").with_content(%r{OnCalendar=.*0\/10}) }
end
end
Expand Down