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

Add logfile rotation variables to the telegraf config file #149

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
87 changes: 51 additions & 36 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
# [*config_file*]
# String. Path to the configuration file.
#
# [*logfile*]
# String. Path to the log file.
#
# [*config_file_owner*]
# String. User to own the telegraf config file.
#
Expand All @@ -32,6 +29,21 @@
# [*config_folder_mode*]
# String. File mode for the telegraf config folder.
#
# [*logfile*]
# String. Path to the log file.
#
# [*logfile_rotation_interval*]
# String. The logfile will be rotated after this time interval. When set
# to 0 no time based rotation is performed. ex: "1d"
#
# [*logfile_rotation_max_size*]
# String. The logfile will be rotated when it becomes larger than this specified
# size. When set to 0 no size based rotation is performed. ex: "10MB"
#
# [*logfile_rotation_max_archives*]
# Integer. Maximum number of rotated archives to keep, any older logs are deleted.
# If set to -1, no archives are removed.
#
# [*hostname*]
# String. Override default hostname used to identify this agent.
#
Expand Down Expand Up @@ -96,39 +108,42 @@
# String. URL for windows telegraf chocolatey repo
#
class telegraf (
String $package_name = $telegraf::params::package_name,
String $ensure = $telegraf::params::ensure,
String $config_file = $telegraf::params::config_file,
String $config_file_owner = $telegraf::params::config_file_owner,
String $config_file_group = $telegraf::params::config_file_group,
Stdlib::Filemode $config_file_mode = $telegraf::params::config_file_mode,
String $config_folder = $telegraf::params::config_folder,
Stdlib::Filemode $config_folder_mode = $telegraf::params::config_folder_mode,
String $hostname = $telegraf::params::hostname,
Boolean $omit_hostname = $telegraf::params::omit_hostname,
String $interval = $telegraf::params::interval,
Boolean $round_interval = $telegraf::params::round_interval,
Integer $metric_batch_size = $telegraf::params::metric_batch_size,
Integer $metric_buffer_limit = $telegraf::params::metric_buffer_limit,
String $collection_jitter = $telegraf::params::collection_jitter,
String $flush_interval = $telegraf::params::flush_interval,
String $flush_jitter = $telegraf::params::flush_jitter,
String $precision = $telegraf::params::precision,
String $logfile = $telegraf::params::logfile,
Boolean $debug = $telegraf::params::debug,
Boolean $quiet = $telegraf::params::quiet,
Hash $inputs = $telegraf::params::inputs,
Hash $outputs = $telegraf::params::outputs,
Hash $global_tags = $telegraf::params::global_tags,
Boolean $manage_service = $telegraf::params::manage_service,
Boolean $manage_repo = $telegraf::params::manage_repo,
Optional[String] $repo_location = $telegraf::params::repo_location,
Boolean $purge_config_fragments = $telegraf::params::purge_config_fragments,
String $repo_type = $telegraf::params::repo_type,
String $windows_package_url = $telegraf::params::windows_package_url,
Boolean $service_enable = $telegraf::params::service_enable,
String $service_ensure = $telegraf::params::service_ensure,
Array $install_options = $telegraf::params::install_options,
String $package_name = $telegraf::params::package_name,
String $ensure = $telegraf::params::ensure,
String $config_file = $telegraf::params::config_file,
String $config_file_owner = $telegraf::params::config_file_owner,
String $config_file_group = $telegraf::params::config_file_group,
Stdlib::Filemode $config_file_mode = $telegraf::params::config_file_mode,
String $config_folder = $telegraf::params::config_folder,
Stdlib::Filemode $config_folder_mode = $telegraf::params::config_folder_mode,
String $hostname = $telegraf::params::hostname,
Boolean $omit_hostname = $telegraf::params::omit_hostname,
String $interval = $telegraf::params::interval,
Boolean $round_interval = $telegraf::params::round_interval,
Integer $metric_batch_size = $telegraf::params::metric_batch_size,
Integer $metric_buffer_limit = $telegraf::params::metric_buffer_limit,
String $collection_jitter = $telegraf::params::collection_jitter,
String $flush_interval = $telegraf::params::flush_interval,
String $flush_jitter = $telegraf::params::flush_jitter,
String $precision = $telegraf::params::precision,
String $logfile = $telegraf::params::logfile,
Optional[String] $logfile_rotation_interval = $telegraf::params::logfile_rotation_interval,
jschoewe marked this conversation as resolved.
Show resolved Hide resolved
Optional[String] $logfile_rotation_max_size = $telegraf::params::logfile_rotation_max_size,
Optional[Integer] $logfile_rotation_max_archives = $telegraf::params::logfile_rotation_max_archives,
Boolean $debug = $telegraf::params::debug,
Boolean $quiet = $telegraf::params::quiet,
Hash $inputs = $telegraf::params::inputs,
Hash $outputs = $telegraf::params::outputs,
Hash $global_tags = $telegraf::params::global_tags,
Boolean $manage_service = $telegraf::params::manage_service,
Boolean $manage_repo = $telegraf::params::manage_repo,
Optional[String] $repo_location = $telegraf::params::repo_location,
Boolean $purge_config_fragments = $telegraf::params::purge_config_fragments,
String $repo_type = $telegraf::params::repo_type,
String $windows_package_url = $telegraf::params::windows_package_url,
Boolean $service_enable = $telegraf::params::service_enable,
String $service_ensure = $telegraf::params::service_ensure,
Array $install_options = $telegraf::params::install_options,
) inherits telegraf::params
{

Expand Down
91 changes: 47 additions & 44 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,55 @@
class telegraf::params {

if $facts['os']['family'] == 'windows' {
$config_file = 'C:/Program Files/telegraf/telegraf.conf'
$config_file_owner = 'Administrator'
$config_file_group = 'Administrators'
$config_folder = 'C:/Program Files/telegraf/telegraf.d'
$logfile = 'C:/Program Files/telegraf/telegraf.log'
$manage_repo = false
$repo_location = undef
$service_enable = true
$service_ensure = running
$service_hasstatus = false
$service_restart = undef
$config_file = 'C:/Program Files/telegraf/telegraf.conf'
$config_file_owner = 'Administrator'
$config_file_group = 'Administrators'
$config_folder = 'C:/Program Files/telegraf/telegraf.d'
$logfile = 'C:/Program Files/telegraf/telegraf.log'
$manage_repo = false
$repo_location = undef
$service_enable = true
$service_ensure = running
$service_hasstatus = false
$service_restart = undef
} else {
$config_file = '/etc/telegraf/telegraf.conf'
$config_file_owner = 'telegraf'
$config_file_group = 'telegraf'
$config_file_mode = '0640'
$config_folder = '/etc/telegraf/telegraf.d'
$config_folder_mode = '0770'
$logfile = ''
$manage_repo = true
$repo_location = 'https://repos.influxdata.com/'
$service_enable = true
$service_ensure = running
$service_hasstatus = true
$service_restart = 'pkill -HUP telegraf'
$config_file = '/etc/telegraf/telegraf.conf'
$config_file_owner = 'telegraf'
$config_file_group = 'telegraf'
$config_file_mode = '0640'
$config_folder = '/etc/telegraf/telegraf.d'
$config_folder_mode = '0770'
$logfile = ''
$manage_repo = true
$repo_location = 'https://repos.influxdata.com/'
$service_enable = true
$service_ensure = running
$service_hasstatus = true
$service_restart = 'pkill -HUP telegraf'
}
$package_name = 'telegraf'
$ensure = 'present'
$install_options = []
$hostname = $trusted['hostname']
$omit_hostname = false
$interval = '10s'
$round_interval = true
$metric_batch_size = 1000
$metric_buffer_limit = 10000
$collection_jitter = '0s'
$flush_interval = '10s'
$flush_jitter = '0s'
$precision = ''
$debug = false
$quiet = false
$global_tags = {}
$manage_service = true
$purge_config_fragments = false
$repo_type = 'stable'
$windows_package_url = 'https://chocolatey.org/api/v2/'
$package_name = 'telegraf'
$ensure = 'present'
$install_options = []
$hostname = $facts['networking']['hostname']
$omit_hostname = false
$interval = '10s'
$round_interval = true
$logfile_rotation_interval = undef
$logfile_rotation_max_size = undef
$logfile_rotation_max_archives = undef
$metric_batch_size = 1000
$metric_buffer_limit = 10000
$collection_jitter = '0s'
$flush_interval = '10s'
$flush_jitter = '0s'
$precision = ''
$debug = false
$quiet = false
$global_tags = {}
$manage_service = true
$purge_config_fragments = false
$repo_type = 'stable'
$windows_package_url = 'https://chocolatey.org/api/v2/'

$outputs = {
'influxdb' => [{
Expand Down
9 changes: 9 additions & 0 deletions templates/telegraf.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
flush_jitter = "<%= @flush_jitter %>"
precision = "<%= @precision %>"
logfile = "<%= @logfile %>"
<% if @logfile_rotation_interval -%>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please implement thats for the options that verify that the content is placed into the template?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I set these to use the default values in the params file instead of checking if they were passed.

logfile_rotation_interval = "<%= @logfile_rotation_interval %>"
<% end -%>
<% if @logfile_rotation_max_size -%>
logfile_rotation_max_size = "<%= @logfile_rotation_max_size %>"
<% end -%>
<% if @logfile_rotation_max_archives -%>
logfile_rotation_max_archives = <%= @logfile_rotation_max_archives %>
<% end -%>
debug = <%= @debug %>
quiet = <%= @quiet %>

Expand Down