Puppet Class: simp_logstash::optimize
- Defined in:
- manifests/optimize.pp
Overview
Sets up a cron job to optimize your ElasticSearch indices on a regular basis using elasticsearch-curator.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'manifests/optimize.pp', line 48
class simp_logstash::optimize (
$ensure = 'present',
$host = '127.0.0.1',
$optimize_days = '2',
$optimize_hours = '',
$prefix = 'logstash-',
$port = '9199',
$separator = '.',
$es_timeout = '21600',
$max_num_segments = '2',
$log_file = '/var/log/logstash/curator_optimize.log',
$cron_hour = '3',
$cron_minute = '15',
$cron_month = '*',
$cron_monthday = '*',
$cron_weekday = '*'
) {
validate_array_member($ensure, ['present','absent'])
if defined('$::simp_logstash::auto_optimize') and getvar('::simp_logstash::auto_optimize') {
validate_net_list($host)
validate_port($port)
validate_string($separator)
validate_integer($es_timeout)
validate_integer($max_num_segments)
validate_absolute_path($log_file)
if ($cron_hour != '*') { validate_integer($cron_hour) }
if ($cron_minute != '*') { validate_integer($cron_minute) }
if ($cron_month != '*') { validate_integer($cron_month) }
if ($cron_monthday != '*') { validate_integer($cron_monthday) }
if ($cron_weekday != '*') { validate_integer($cron_weekday) }
if size(reject([$optimize_days, $optimize_hours],'^\s*$')) > 1 {
fail('You may only specify one of $optimize_days or $optimize_hours')
}
if !empty($optimize_hours) {
validate_integer($optimize_hours)
$_limit = "-T hours --older-than ${optimize_hours}"
}
elsif !empty($optimize_days) {
validate_integer($optimize_days)
$_limit = "-T days --older-than ${optimize_days}"
}
else {
fail('You must specify one of $optimize_days or $optimize_hours')
}
cron { 'logstash_index_optimize':
ensure => $ensure,
command => "/usr/bin/curator --host ${host} --port ${port} -t ${es_timeout} optimize -p '${prefix}' -s '${separator}' ${_limit} --max_num_segments ${max_num_segments} >> ${log_file} 2>&1",
hour => $cron_hour,
minute => $cron_minute,
month => $cron_month,
monthday => $cron_monthday,
weekday => $cron_weekday,
require => Class['simp_logstash::curator']
}
}
else {
cron { 'logstash_index_optimize': ensure => 'absent' }
}
}
|