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
This commit is contained in:
parent
07abee63a7
commit
5791101158
@ -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,
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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' {
|
||||
|
@ -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
|
@ -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
|
||||
|
@ -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 -%>
|
||||
|
Loading…
Reference in New Issue
Block a user