summaryrefslogtreecommitdiffstats
path: root/modules/tick
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-07-05 19:31:02 -0400
committerJesse Luehrs <doy@tozt.net>2020-07-05 19:41:36 -0400
commitbc3c5a1ffdecf02061933df4fb00ed11be06ce37 (patch)
tree7bd3b9c9a5ce38f7f8cfa0da631d798546933ded /modules/tick
parent0cf629c60d7fb5a6c41ca29fe5b9fd29183f7361 (diff)
downloadpuppet-tozt-bc3c5a1ffdecf02061933df4fb00ed11be06ce37.tar.gz
puppet-tozt-bc3c5a1ffdecf02061933df4fb00ed11be06ce37.zip
add tarsnap metrics
Diffstat (limited to 'modules/tick')
-rw-r--r--modules/tick/files/plugins/tarsnap64
-rw-r--r--modules/tick/files/plugins/tarsnap.conf4
-rw-r--r--modules/tick/files/plugins/tarsnap.sudoers3
-rw-r--r--modules/tick/manifests/client/plugin/tarsnap.pp18
4 files changed, 89 insertions, 0 deletions
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'];
+ }
+}