diff options
author | Jesse Luehrs <doy@tozt.net> | 2020-07-05 19:31:02 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2020-07-05 19:41:36 -0400 |
commit | bc3c5a1ffdecf02061933df4fb00ed11be06ce37 (patch) | |
tree | 7bd3b9c9a5ce38f7f8cfa0da631d798546933ded | |
parent | 0cf629c60d7fb5a6c41ca29fe5b9fd29183f7361 (diff) | |
download | puppet-tozt-bc3c5a1ffdecf02061933df4fb00ed11be06ce37.tar.gz puppet-tozt-bc3c5a1ffdecf02061933df4fb00ed11be06ce37.zip |
add tarsnap metrics
-rw-r--r-- | modules/mail/manifests/monitoring.pp | 2 | ||||
-rw-r--r-- | modules/tick/files/plugins/tarsnap | 64 | ||||
-rw-r--r-- | modules/tick/files/plugins/tarsnap.conf | 4 | ||||
-rw-r--r-- | modules/tick/files/plugins/tarsnap.sudoers | 3 | ||||
-rw-r--r-- | modules/tick/manifests/client/plugin/tarsnap.pp | 18 | ||||
-rw-r--r-- | modules/tozt/manifests/monitoring.pp | 2 |
6 files changed, 93 insertions, 0 deletions
diff --git a/modules/mail/manifests/monitoring.pp b/modules/mail/manifests/monitoring.pp index d726bbd..f7f0afd 100644 --- a/modules/mail/manifests/monitoring.pp +++ b/modules/mail/manifests/monitoring.pp @@ -80,4 +80,6 @@ class mail::monitoring { } include tick::client::base_plugins + + class { "tick::client::plugin::tarsnap": } } diff --git a/modules/tick/files/plugins/tarsnap b/modules/tick/files/plugins/tarsnap new file mode 100644 index 0000000..0352cdb --- /dev/null +++ b/modules/tick/files/plugins/tarsnap @@ -0,0 +1,64 @@ +#!/usr/bin/env ruby + +require 'date' + +def parse_archive(archive) + # tozt-daily-2018-12-31_03:34:13-homedoypass + m = archive.match(/ + \A + (?<host>[a-z]+) # tozt + - + (?<period>[a-z]+) # daily + - + (?<year>[0-9]+) # 2018 + - + (?<month>[0-9]+) # 12 + - + (?<day>[0-9]+) # 31 + _ + (?<hour>[0-9]+) # 03 + : + (?<minute>[0-9]+) # 34 + : + (?<second>[0-9]+) # 13 + - + (?<name>[a-z_]+) # homedoypass + \z + /x) + raise "failed to parse archive name '#{archive}'" if m.nil? + + parsed = m.names.zip(m.captures).to_h + parsed["time"] = Time.new( + m["year"], + m["month"], + m["day"], + m["hour"], + m["minute"], + m["second"] + ) + parsed +end + +archives = %x(sudo tarsnap --list-archives) + .lines + .map(&:chomp) + .map{|s| parse_archive(s)} + +now = Time.now +most_recent_since = {} +archives.each do |archive| + name = archive["name"] + since = now - archive["time"] + + if most_recent_since[name].nil? || since < most_recent_since[name] + most_recent_since[name] = since + end +end + +stats = %x(sudo tarsnap --print-stats) +bytes = stats.chomp.match(/(\d+)\z/).to_s.to_i + +most_recent_since.sort.each do |name, since| + puts "tarsnap,name=#{name} days_since_last_run=#{since.to_f / 60.0 / 60.0 / 24.0}" +end +puts "tarsnap file_size=#{bytes}i" diff --git a/modules/tick/files/plugins/tarsnap.conf b/modules/tick/files/plugins/tarsnap.conf new file mode 100644 index 0000000..6a68c1e --- /dev/null +++ b/modules/tick/files/plugins/tarsnap.conf @@ -0,0 +1,4 @@ +[[inputs.exec]] +commands = ["/etc/telegraf/plugins/tarsnap"] +data_format = "influx" +timeout = "30s" diff --git a/modules/tick/files/plugins/tarsnap.sudoers b/modules/tick/files/plugins/tarsnap.sudoers new file mode 100644 index 0000000..d915bf8 --- /dev/null +++ b/modules/tick/files/plugins/tarsnap.sudoers @@ -0,0 +1,3 @@ +Cmnd_Alias TARSNAP = /usr/bin/tarsnap +telegraf ALL=(ALL) NOPASSWD: TARSNAP +Defaults!TARSNAP !logfile, !syslog, !pam_session diff --git a/modules/tick/manifests/client/plugin/tarsnap.pp b/modules/tick/manifests/client/plugin/tarsnap.pp new file mode 100644 index 0000000..e7b0a5b --- /dev/null +++ b/modules/tick/manifests/client/plugin/tarsnap.pp @@ -0,0 +1,18 @@ +class tick::client::plugin::tarsnap { + file { + "/etc/telegraf/telegraf.d/tarsnap.conf": + source => 'puppet:///modules/tick/plugins/tarsnap.conf', + require => [ + File["/etc/telegraf/telegraf.d"], + File["/etc/telegraf/plugins/tarsnap"], + ], + notify => Service["telegraf"]; + "/etc/telegraf/plugins/tarsnap": + source => 'puppet:///modules/tick/plugins/tarsnap', + mode => '0755', + require => File['/etc/telegraf/plugins']; + "/etc/sudoers.d/telegraf-tarsnap": + source => 'puppet:///modules/tick/plugins/tarsnap.sudoers', + require => Package['sudo']; + } +} diff --git a/modules/tozt/manifests/monitoring.pp b/modules/tozt/manifests/monitoring.pp index 0162969..16a5c0a 100644 --- a/modules/tozt/manifests/monitoring.pp +++ b/modules/tozt/manifests/monitoring.pp @@ -82,4 +82,6 @@ class tozt::monitoring { } include tick::client::base_plugins + + class { "tick::client::plugin::tarsnap": } } |