From 90e8109a883d6bbae266acf94a90b54526b3d443 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sat, 30 Oct 2021 14:34:29 +0200 Subject: [PATCH] overpass: add munin scripts --- cookbooks/overpass/recipes/default.rb | 20 ++++++++- .../overpass/templates/default/munin.erb | 4 ++ .../templates/default/munin_db_lag.erb | 23 ++++++++++ .../templates/default/munin_request_count.erb | 44 +++++++++++++++++++ 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 cookbooks/overpass/templates/default/munin.erb create mode 100644 cookbooks/overpass/templates/default/munin_db_lag.erb create mode 100644 cookbooks/overpass/templates/default/munin_request_count.erb diff --git a/cookbooks/overpass/recipes/default.rb b/cookbooks/overpass/recipes/default.rb index 4ec94b895..880420226 100644 --- a/cookbooks/overpass/recipes/default.rb +++ b/cookbooks/overpass/recipes/default.rb @@ -25,7 +25,7 @@ username = "overpass" basedir = data_bag_item("accounts", username)["home"] web_passwords = data_bag_item("web", "passwords") -%w[bin site diffs db src].each do |dirname| +%w[bin site diffs db src munin].each do |dirname| directory "#{basedir}/#{dirname}" do owner username group username @@ -210,3 +210,21 @@ end service "overpass-area-processor" do action [:enable] end + +# Munin scripts + +%w[db_lag request_count].each do |name| + template "#{basedir}/munin/overpass_#{name}" do + source "munin_#{name}.erb" + owner username + group username + mode "755" + variables :basedir => basedir + end + + munin_plugin "overpass_#{name}" do + target "#{basedir}/munin/overpass_#{name}" + conf "munin.erb" + conf_variables :user => username + end +end diff --git a/cookbooks/overpass/templates/default/munin.erb b/cookbooks/overpass/templates/default/munin.erb new file mode 100644 index 000000000..a2f47fa92 --- /dev/null +++ b/cookbooks/overpass/templates/default/munin.erb @@ -0,0 +1,4 @@ +# DO NOT EDIT - This file is being maintained by Chef + +[<%= @name %>] +user <%= @user %> diff --git a/cookbooks/overpass/templates/default/munin_db_lag.erb b/cookbooks/overpass/templates/default/munin_db_lag.erb new file mode 100644 index 000000000..ce8bdfaf7 --- /dev/null +++ b/cookbooks/overpass/templates/default/munin_db_lag.erb @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# DO NOT EDIT - This file is being maintained by Chef +# +# Based on: https://github.com/drolbr/Overpass-API/blob/way_based_areas/munin/osm_replication_lag-api + +if [ "$1" = "config" ]; then + + echo 'graph_title DB Lag' + echo 'graph_args --base 1000' + echo 'graph_vlabel minutes behind main database' + echo 'graph_category overpass' + + echo 'lag.label replication lag' + echo 'lag.draw LINE' + echo 'lag.cdef lag,60,/' + echo 'lag.critical 1000' + + exit 0 +fi + +lag=$(($(date +%s)-$(date +%s --utc -d "$(cat <%= @basedir %>/db/osm_base_version | cut -f2 -d\" | sed s/"\\\\"/""/g | sed s/[ZT]/" "/g)" ))) +echo "lag.value $lag" diff --git a/cookbooks/overpass/templates/default/munin_request_count.erb b/cookbooks/overpass/templates/default/munin_request_count.erb new file mode 100644 index 000000000..c1315225b --- /dev/null +++ b/cookbooks/overpass/templates/default/munin_request_count.erb @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# +# DO NOT EDIT - This file is being maintained by Chef +# +# Based on: https://github.com/drolbr/Overpass-API/blob/way_based_areas/munin/osm_db_request_count + +if [[ "$1" = "config" ]]; then +{ + echo 'graph_title API request count' + echo 'graph_vlabel per minute' + echo 'graph_category overpass' + echo "overpass_request_started.label started" + echo "overpass_request_started.type COUNTER" + echo "overpass_request_started.cdef overpass_request_started,60,*" + echo "overpass_request_started.max 10000" + echo "overpass_request_completed.label completed" + echo "overpass_request_completed.type COUNTER" + echo "overpass_request_completed.cdef overpass_request_completed,60,*" + echo "overpass_request_completed.max 10000" + echo "overpass_area_request_started.label started" + echo "overpass_area_request_started.type COUNTER" + echo "overpass_area_request_started.cdef overpass_request_started,60,*" + echo "overpass_area_request_started.max 10000" + echo "overpass_area_request_completed.label completed" + echo "overpass_area_request_completed.type COUNTER" + echo "overpass_area_request_completed.cdef overpass_request_completed,60,*" + echo "overpass_area_request_completed.max 10000" + exit 0 +}; fi + +BASE_STATUS=`<%= @basedir %>/bin/dispatcher --osm-base --status | tr '\n' '|'` +AREA_STATUS=`<%= @basedir %>/bin/dispatcher --areas --status | tr '\n' '|'` + +STARTED=`echo $BASE_STATUS | sed 's,.*Counter of started requests:,,;s:|.*::'` +echo "overpass_request_started.value $STARTED" + +COMPLETED=`echo $BASE_STATUS | sed 's,.*Counter of finished requests:,,;s:|.*::'` +echo "overpass_request_completed.value $COMPLETED" + +STARTED=`echo $AREA_STATUS | sed 's,.*Counter of started requests:,,;s:|.*::'` +echo "overpass_area_request_started.value $STARTED" + +COMPLETED=`echo $AREA_STATUS | sed 's,.*Counter of finished requests:,,;s:|.*::'` +echo "overpass_area_request_completed.value $COMPLETED" -- 2.43.2