Fix munin replication plugin to work with osmium based state
authorTom Hughes <tom@compton.nu>
Wed, 12 Dec 2018 20:22:57 +0000 (20:22 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 12 Dec 2018 20:22:57 +0000 (20:22 +0000)
cookbooks/munin/files/default/plugins/replication_delay
cookbooks/tile/recipes/default.rb
cookbooks/tile/templates/default/munin.erb [deleted file]

index f1761e8..f6cd317 100755 (executable)
@@ -1,31 +1,30 @@
-#!/bin/sh 
-# 
-# Plugin to monitor the age of the imported data in the rendering db 
-# 
-# Parameters:  
-# 
-#       config   (required) 
-#       autoconf (optional - used by munin-config) 
-# 
-if [ "$1" = "config" ]; then 
-        echo 'graph_title Data import lag' 
-        echo 'graph_args --base 1000 -l 0' 
-        echo 'graph_vlabel minutes' 
-        echo 'graph_category renderd' 
-        echo 'age.label DB import age' 
-        echo 'age.type GAUGE' 
-       echo 'age.cdef age,60,/'
-       echo 'age.warning :600'
-       echo 'age.critical :3600'
-        exit 0 
-fi 
+#!/bin/sh
+#
+# Plugin to monitor the age of the imported data in the rendering db
+#
+# Parameters:
+#
+#       config   (required)
+#       autoconf (optional - used by munin-config)
+#
+
+if [ "$1" = "config" ]; then
+
+        echo 'graph_title Data import lag'
+        echo 'graph_args --base 1000 -l 0'
+        echo 'graph_vlabel minutes'
+        echo 'graph_category renderd'
+        echo 'age.label DB import age'
+        echo 'age.type GAUGE'
+        echo 'age.cdef age,60,/'
+        echo 'age.warning :600'
+        echo 'age.critical :3600'
+        exit 0
+fi
+
+latest_changes=$(ls /var/lib/replicate/changes-*.osc.gz | sort --version-sort | tail -1)
+tstamp=$(osmium fileinfo --extended --get=data.timestamp.last ${latest_changes})
+tstampsec=$(date --date=${tstamp} +%s)
+nowsec=$(date +%s)
 
-state=${state:-/home/jburgess/replicate/state.txt}
-tstamp=`sed -e '/^timestamp=/!d' -e 's/.*=//' -e 's/Z//' -e 's/T/Z/' -e 's/\\\\//' -e 's/\\\\//' -e q ${state}` 
-tstampsec=`date --date=$tstamp +%s` 
-nowsec=`date +%s` 
 echo "age.value " `expr $nowsec - $tstampsec`
index f87bac6..22a6426 100644 (file)
@@ -434,6 +434,7 @@ end
 package %w[
   osm2pgsql
   ruby
+  osmium-tool
   pyosmium
   python-pyproj
 ]
@@ -571,6 +572,4 @@ munin_plugin "renderd_queue_time"
 munin_plugin "renderd_zoom"
 munin_plugin "renderd_zoom_time"
 
-munin_plugin "replication_delay" do
-  conf "munin.erb"
-end
+munin_plugin "replication_delay"
diff --git a/cookbooks/tile/templates/default/munin.erb b/cookbooks/tile/templates/default/munin.erb
deleted file mode 100644 (file)
index b789827..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-# DO NOT EDIT - This file is being maintained by Chef
-
-[<%= @name %>]
-env.state /var/lib/replicate/state.txt