From db955ee5728d7061e26bf7ee75aa927a8908d5e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sun, 12 Feb 2017 19:10:38 +0100 Subject: [PATCH] Plugin turbostat --- manifests/plugin/turbostat.pp | 17 +++ .../classes/collectd_plugin_turbostat_spec.rb | 115 ++++++++++++++++++ templates/plugin/turbostat.conf.erb | 20 +++ 3 files changed, 152 insertions(+) create mode 100644 manifests/plugin/turbostat.pp create mode 100644 spec/classes/collectd_plugin_turbostat_spec.rb create mode 100644 templates/plugin/turbostat.conf.erb diff --git a/manifests/plugin/turbostat.pp b/manifests/plugin/turbostat.pp new file mode 100644 index 000000000..8c68d9c2c --- /dev/null +++ b/manifests/plugin/turbostat.pp @@ -0,0 +1,17 @@ +# https://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_turbostat +class collectd::plugin::turbostat ( + Enum['present', 'absent'] $ensure = 'present', + Optional[Integer] $core_c_states = undef, + Optional[Integer] $package_c_states = undef, + Optional[Boolean] $system_management_interrupt = undef, + Optional[Boolean] $digital_temperature_sensor = undef, + Optional[Integer] $tcc_activation_temp = undef, + Optional[Integer] $running_average_power_limit = undef, +) { + include ::collectd + + collectd::plugin { 'turbostat': + ensure => $ensure, + content => template('collectd/plugin/turbostat.conf.erb'), + } +} diff --git a/spec/classes/collectd_plugin_turbostat_spec.rb b/spec/classes/collectd_plugin_turbostat_spec.rb new file mode 100644 index 000000000..bbded6349 --- /dev/null +++ b/spec/classes/collectd_plugin_turbostat_spec.rb @@ -0,0 +1,115 @@ +require 'spec_helper' + +describe 'collectd::plugin::turbostat', type: :class do + let :facts do + { + osfamily: 'RedHat', + collectd_version: '4.8.0', + operatingsystemmajrelease: '7', + python_dir: '/usr/local/lib/python2.7/dist-packages' + } + end + context ':ensure => present, default params' do + let :facts do + { + osfamily: 'RedHat', + collectd_version: '4.8.0', + operatingsystemmajrelease: '7', + python_dir: '/usr/local/lib/python2.7/dist-packages' + } + end + it 'Will create /etc/collectd.d/10-turbostat.conf' do + is_expected.to contain_file('turbostat.load'). + with(ensure: 'present', + path: '/etc/collectd.d/10-turbostat.conf', + content: %r{# Generated by Puppet\nLoadPlugin turbostat\n\n\n\n}) + end + end + + context ':ensure => present and :core_c_states => 392' do + let :params do + { core_c_states: 392 } + end + it 'Will create /etc/collectd.d/10-turbostat.conf' do + is_expected.to contain_file('turbostat.load').with(ensure: 'present', + path: '/etc/collectd.d/10-turbostat.conf', + content: %r{CoreCstates "392"}m) + end + end + + context ':ensure => present and :package_c_states => 396' do + let :params do + { package_c_states: 396 } + end + it 'Will create /etc/collectd.d/10-turbostat.conf' do + is_expected.to contain_file('turbostat.load').with(ensure: 'present', + path: '/etc/collectd.d/10-turbostat.conf', + content: %r{PackageCstates "396"}m) + end + end + + context ':ensure => present and :system_management_interrupt => false' do + let :params do + { system_management_interrupt: false } + end + it 'Will create /etc/collectd.d/10-turbostat.conf' do + is_expected.to contain_file('turbostat.load').with(ensure: 'present', + path: '/etc/collectd.d/10-turbostat.conf', + content: %r{SystemManagementInterrupt "false"}m) + end + end + + context ':ensure => present and :digital_temperature_sensor => false' do + let :params do + { digital_temperature_sensor: false } + end + it 'Will create /etc/collectd.d/10-turbostat.conf' do + is_expected.to contain_file('turbostat.load').with(ensure: 'present', + path: '/etc/collectd.d/10-turbostat.conf', + content: %r{DigitalTemperatureSensor "false"}m) + end + end + + context ':ensure => present and :tcc_activation_temp => 40' do + let :params do + { tcc_activation_temp: 40 } + end + it 'Will create /etc/collectd.d/10-turbostat.conf' do + is_expected.to contain_file('turbostat.load').with(ensure: 'present', + path: '/etc/collectd.d/10-turbostat.conf', + content: %r{TCCActivationTemp "40"}m) + end + end + + context ':ensure => present and :running_average_power_limit => 8' do + let :params do + { running_average_power_limit: 8 } + end + it 'Will create /etc/collectd.d/10-turbostat.conf' do + is_expected.to contain_file('turbostat.load').with(ensure: 'present', + path: '/etc/collectd.d/10-turbostat.conf', + content: %r{RunningAveragePowerLimit "8"}m) + end + end + + context ':ensure => absent' do + let :facts do + { + osfamily: 'RedHat', + collectd_version: '4.8.0', + operatingsystemmajrelease: '7', + python_dir: '/usr/local/lib/python2.7/dist-packages' + } + end + + let :params do + { ensure: 'absent' } + end + + it 'Will not create /etc/collectd.d/10-turbostat.conf' do + is_expected.to contain_file('turbostat.load'). + with(ensure: 'absent', + path: '/etc/collectd.d/10-turbostat.conf') + end + end +end diff --git a/templates/plugin/turbostat.conf.erb b/templates/plugin/turbostat.conf.erb new file mode 100644 index 000000000..f6e631335 --- /dev/null +++ b/templates/plugin/turbostat.conf.erb @@ -0,0 +1,20 @@ + +<% if @core_c_states -%> + CoreCstates "<%= @core_c_states %>" +<% end -%> +<% if @package_c_states -%> + PackageCstates "<%= @package_c_states %>" +<% end -%> +<% unless @system_management_interrupt.nil? -%> + SystemManagementInterrupt "<%= @system_management_interrupt %>" +<% end -%> +<% unless @digital_temperature_sensor.nil? -%> + DigitalTemperatureSensor "<%= @digital_temperature_sensor %>" +<% end -%> +<% if @tcc_activation_temp -%> + TCCActivationTemp "<%= @tcc_activation_temp %>" +<% end -%> +<% if @running_average_power_limit -%> + RunningAveragePowerLimit "<%= @running_average_power_limit %>" +<% end -%> + \ No newline at end of file