summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--files/munin/puppetresources.mysql39
-rw-r--r--files/munin/puppetresources.postgres37
-rw-r--r--manifests/puppetmaster.pp5
3 files changed, 81 insertions, 0 deletions
diff --git a/files/munin/puppetresources.mysql b/files/munin/puppetresources.mysql
new file mode 100644
index 0000000..29c1104
--- /dev/null
+++ b/files/munin/puppetresources.mysql
@@ -0,0 +1,39 @@
+#!/bin/sh
+#
+# Plugin to monitor resource count as managed by puppet
+# Written by David Schmitts
+# Adapted by Marcel Haerry, Puzzle ITC <haerry(at)puzzle.ch
+#
+# Parameters:
+#
+# config (required)
+#
+# Config variables:
+#
+# mysqlopts: options for mysql
+
+MYSQL_OPTS=${mysqlopts:-}
+MYSQL_DB=${puppetdb:-puppet}
+
+function select_resources() {
+ echo "select count(*) as count, hosts.name from resources join hosts on (host_id = hosts.id) group by hosts.name order by count(*) DESC" | mysql $MYSQL_OPTS -N $MYSQL_DB
+}
+
+if [ "$1" = "config" ]; then
+
+ echo 'graph_title Puppet Resources'
+ echo 'graph_args -l 0 --base 1000'
+ echo 'graph_vlabel configured resources'
+ echo 'graph_category other'
+ select_resources | while read count hostname; do
+ graphname="$(echo "$hostname" | tr '.-' _)"
+ echo "$graphname.label $hostname"
+ echo "$graphname.type GAUGE"
+ done
+ exit 0
+fi
+
+select_resources | while read count hostname; do
+ graphname="$(echo "$hostname" | tr '.-' _)"
+ echo "$graphname.value $count"
+done
diff --git a/files/munin/puppetresources.postgres b/files/munin/puppetresources.postgres
new file mode 100644
index 0000000..89fd6ba
--- /dev/null
+++ b/files/munin/puppetresources.postgres
@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# Plugin to monitor resource count as managed by puppet
+#
+# Parameters:
+#
+# config (required)
+
+function select_resources() {
+ psql -c "select count(*) as count, hosts.name from resources join hosts on (host_id = hosts.id) group by hosts.name order by count(*) DESC" -A -F " " -t puppet
+}
+
+if [ "$1" = "config" ]; then
+
+ echo 'graph_title Puppet Resources'
+ echo 'graph_args -l 0 --base 1000'
+ echo 'graph_vlabel configured resources'
+ echo 'graph_category other'
+ select_resources | while read count hostname; do
+ graphname="$(echo "$hostname" | tr '.-' _)"
+ echo "$graphname.label $hostname"
+ echo "$graphname.type GAUGE"
+ done
+ exit 0
+fi
+
+select_resources | while read count hostname; do
+ graphname="$(echo "$hostname" | tr '.-' _)"
+ echo "$graphname.value $count"
+done
+
+if [ -f /proc/vmstat ]; then
+ awk '/pswpin/ { print "swap_in.value " $2 } /pswpout/ { print "swap_out.value " $2 }' < /proc/vmstat
+else
+ awk '/swap/ { print "swap_in.value " $2 "\nswap_out.value " $3 }' < /proc/stat
+fi
+
diff --git a/manifests/puppetmaster.pp b/manifests/puppetmaster.pp
index 4470a84..fa975ad 100644
--- a/manifests/puppetmaster.pp
+++ b/manifests/puppetmaster.pp
@@ -89,4 +89,9 @@ define puppet::puppetmaster::hasdb::mysql(
require => Mysql_user["${dbuser}@${dbconnectinghost}"],
tag => "mysql_${dbhostfqdn}",
}
+
+ munin::plugin::deploy{'puppetresources':
+ source => "puppet/munin/puppetresources.mysql",
+ config => "env.mysqlopts --user=$dbuser --password=$dbpwd -h $dbhost\nenv.puppetdb $dbname",
+ }
}