From 57911011587fbf24b9e68b2a67fc3f6d1bef967e Mon Sep 17 00:00:00 2001 From: Michael Polenchuk Date: Thu, 14 Jan 2016 17:57:57 +0300 Subject: [PATCH] Disable accounting procacct mode Turn off process accounting ('no procacct' mode). But atop still has an ability to collect valuable stats. Bring in internal "custom_acct_file" option: * false - use atop default accounting file * /path_to/atop.acct - custom one * undef - disable accounting procacct mode DocImpact: 'custom_accounting_file' is system wide process accounting file (valid values is above). Change-Id: Ida00dc663dd8c6494c479de2ae2f0f7ab6014a84 Closes-Bug: #1530167 --- .../puppet/osnailyfacter/manifests/atop.pp | 95 +++++++++++++----- .../osnailyfacter/modular/tools/tools.pp | 6 +- .../spec/classes/osnailyfacter_atop_spec.rb | 96 +++++++++++++++++++ .../puppet/osnailyfacter/spec/spec_helper.rb | 1 + .../puppet/osnailyfacter/templates/atop.erb | 4 + 5 files changed, 178 insertions(+), 24 deletions(-) create mode 100644 deployment/puppet/osnailyfacter/spec/classes/osnailyfacter_atop_spec.rb diff --git a/deployment/puppet/osnailyfacter/manifests/atop.pp b/deployment/puppet/osnailyfacter/manifests/atop.pp index 70776b700c..02e27cfd61 100644 --- a/deployment/puppet/osnailyfacter/manifests/atop.pp +++ b/deployment/puppet/osnailyfacter/manifests/atop.pp @@ -20,46 +20,95 @@ # [*rotate*] # How many days keep binary logs. # Default is 7. +# +# [*custom_acct_file*] +# Location of the custom accounting file. (e.g. '/tmp/atop.d/atop.acct') +# Set 'undef' to disable accounting, 'false' to use atop default settings. +# Default is undef. +# class osnailyfacter::atop ( - $service_enabled = true, - $service_state = 'running', - $interval = '20', - $logpath = '/var/log/atop', - $rotate = '7', - ) { - $conf_file = $::osfamily ? { - 'Debian' => '/etc/default/atop', - 'RedHat' => '/etc/sysconfig/atop', - default => fail('Unsupported Operating System.'), + $service_enabled = true, + $service_state = 'running', + $interval = '20', + $logpath = '/var/log/atop', + $rotate = '7', + $custom_acct_file = undef, +) { + + case $::osfamily { + 'Debian': { + $conf_file = '/etc/default/atop' + $acct_package = 'acct' + } + 'RedHat': { + $conf_file = '/etc/sysconfig/atop' + $acct_package = 'psacct' + } + default: { + fail("Unsupported platform: ${::osfamily}/${::operatingsystem}") + } } - package { 'atop': + $atop_retention = '/etc/cron.daily/atop_retention' + + File { + ensure => file, + owner => 'root', + group => 'root', + mode => '0600' + } + + if $custom_acct_file { + validate_absolute_path($custom_acct_file) + $acct_file_dir = dirname($custom_acct_file) + + # Manage the parent directory + file { $acct_file_dir: + ensure => directory, + } -> + + file { $custom_acct_file: + } ~> + + exec { 'turns process accounting on': + path => ['/sbin', '/usr/sbin'], + command => "accton ${custom_acct_file}", + refreshonly => true, + } + + Package[$acct_package] -> Exec['turns process accounting on'] -> Service['atop'] + } + + package { ['atop', $acct_package]: ensure => 'installed', } -> + # Template uses: + # - $interval + # - $logpath + # - $custom_acct_file file { $conf_file: - ensure => present, + mode => '0644', content => template('osnailyfacter/atop.erb'), } ~> service { 'atop': ensure => $service_state, enable => $service_enabled, - } ~> - - exec { "ln -s ${logpath}/atop_current": - command => "ln -s ${logpath}/atop_$(date +%Y%m%d) ${logpath}/atop_current", - path => ['/bin', '/usr/bin'], - unless => "test -L ${logpath}/atop_current", - require => Service['atop']; - } + } -> # This file is used for atop binary log rotations by (ana)cron - file { '/etc/cron.daily/atop_retention': - owner => 'root', - group => 'root', + # Template uses: + # - $rotate + # - $logpath + file { $atop_retention: mode => '0755', content => template('osnailyfacter/atop_retention.erb'), + } ~> + + exec { 'initialize atop_current': + command => $atop_retention, + refreshonly => true, } } diff --git a/deployment/puppet/osnailyfacter/modular/tools/tools.pp b/deployment/puppet/osnailyfacter/modular/tools/tools.pp index 6b049b9c2a..0a3a63209c 100644 --- a/deployment/puppet/osnailyfacter/modular/tools/tools.pp +++ b/deployment/puppet/osnailyfacter/modular/tools/tools.pp @@ -1,6 +1,10 @@ notice('MODULAR: tools.pp') -class { 'osnailyfacter::atop': } +$custom_acct_file = hiera('custom_accounting_file', undef) +class { 'osnailyfacter::atop': + custom_acct_file => $custom_acct_file, +} + class { 'osnailyfacter::ssh': } if $::virtual != 'physical' { diff --git a/deployment/puppet/osnailyfacter/spec/classes/osnailyfacter_atop_spec.rb b/deployment/puppet/osnailyfacter/spec/classes/osnailyfacter_atop_spec.rb new file mode 100644 index 0000000000..ed57325ef8 --- /dev/null +++ b/deployment/puppet/osnailyfacter/spec/classes/osnailyfacter_atop_spec.rb @@ -0,0 +1,96 @@ +require 'spec_helper' + +describe 'osnailyfacter::atop' do + + shared_examples_for 'atop install and configure' do + + let :file_default_opts do + { + :ensure => 'file', + :owner => 'root', + :group => 'root', + :mode => '0600', + } + end + + context "with default params" do + it 'should setup with platform specific' do + case facts[:osfamily] + when 'Debian' + conf_file = '/etc/default/atop' + acct_package = 'acct' + when 'RedHat' + conf_file = '/etc/sysconfig/atop' + acct_package = 'psacct' + end + + is_expected.to contain_package(acct_package) + + is_expected.to contain_file(conf_file).with( + file_default_opts.merge(:mode => '0644') + ) + end + + it { is_expected.to contain_package('atop') } + it { is_expected.to contain_service('atop') } + + it { is_expected.to contain_file('/etc/cron.daily/atop_retention').with( + file_default_opts.merge(:mode => '0755') + ) } + + it { is_expected.to contain_exec('initialize atop_current').with( + :command => '/etc/cron.daily/atop_retention', + :refreshonly => true, + ) } + end + + context "with custom params" do + let :params do + { + :custom_acct_file => '/tmp/atop.d/atop.acct', + } + end + + it { is_expected.to contain_file(File.dirname(params[:custom_acct_file])).with( + file_default_opts.merge(:ensure => 'directory') + ) } + + it { is_expected.to contain_file(params[:custom_acct_file]).with( + file_default_opts + ) } + + it { is_expected.to contain_exec('turns process accounting on').with( + :command => "accton #{params[:custom_acct_file]}", + :refreshonly => true, + ) } + end + + end + + context 'on Debian platforms' do + let :facts do + { + :osfamily => 'Debian', + :operatingsystem => 'Debian', + :processorcount => 2, + :memorysize_mb => 4096, + } + end + + it_configures 'atop install and configure' + end + + context 'on RedHat platforms' do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :processorcount => 2, + :memorysize_mb => 4096, + } + end + + it_configures 'atop install and configure' + end + +end diff --git a/deployment/puppet/osnailyfacter/spec/spec_helper.rb b/deployment/puppet/osnailyfacter/spec/spec_helper.rb index 766fc98272..edc5252dfc 100644 --- a/deployment/puppet/osnailyfacter/spec/spec_helper.rb +++ b/deployment/puppet/osnailyfacter/spec/spec_helper.rb @@ -17,6 +17,7 @@ RSpec.configure do |c| c.module_path = File.join(fixture_path, 'modules') c.manifest_dir = File.join(fixture_path, 'manifests') c.mock_with(:mocha) + c.alias_it_should_behave_like_to :it_configures, 'configures' end def puppet_debug_override diff --git a/deployment/puppet/osnailyfacter/templates/atop.erb b/deployment/puppet/osnailyfacter/templates/atop.erb index 5a9a896cf3..b52bde05c4 100644 --- a/deployment/puppet/osnailyfacter/templates/atop.erb +++ b/deployment/puppet/osnailyfacter/templates/atop.erb @@ -17,3 +17,7 @@ INTERVAL=<%= @interval %> LOGPATH="<%= @logpath %>" OUTFILE="$LOGPATH/daily.log" <% end -%> +<% if @custom_acct_file or @custom_acct_file.nil? -%> +# empty value to disable process accounting +ATOPACCT=<%= @custom_acct_file %> +<% end -%>