]> git.openstreetmap.org Git - chef.git/commitdiff
Add a munin plugin for API response codes
authorTom Hughes <tom@compton.nu>
Tue, 31 Mar 2015 23:35:36 +0000 (00:35 +0100)
committerTom Hughes <tom@compton.nu>
Tue, 31 Mar 2015 23:36:23 +0000 (00:36 +0100)
cookbooks/munin/files/default/plugins/api_calls_status [new file with mode: 0755]
cookbooks/web/recipes/rails.rb

diff --git a/cookbooks/munin/files/default/plugins/api_calls_status b/cookbooks/munin/files/default/plugins/api_calls_status
new file mode 100755 (executable)
index 0000000..16b0d0e
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/ruby
+
+require "json"
+
+HTTP_STATUSES = {
+  "200" => "OK",
+  "301" => "Moved Permanently",
+  "302" => "Found",
+  "303" => "See Other",
+  "304" => "Not Modified",
+  "400" => "Bad Request",
+  "401" => "Unauthorized",
+  "403" => "Forbidden",
+  "404" => "Not Found",
+  "408" => "Request Timeout",
+  "409" => "Conflict",
+  "410" => "Gone",
+  "500" => "Internal Server Error",
+  "509" => "Bandwidth Limit Exceeded"
+}
+
+if ARGV[0] == "config"
+  puts "graph_title HTTP response codes"
+  puts "graph_args --lower-limit 0 --base 1000 --logarithmic"
+  puts "graph_vlabel Number of requests per ${graph_period}"
+  puts "graph_category api"
+
+  HTTP_STATUSES.each do |code, label|
+    puts "http#{code}.label #{label}"
+    puts "http#{code}.type DERIVE"
+  end
+else
+  statistics = JSON.parse(File.read("/srv/www.openstreetmap.org/rails/tmp/statistics.json"))
+
+  HTTP_STATUSES.keys.each do |code|
+    count = statistics["status"][code] || 0
+    puts "http#{code}.value #{count}"
+  end
+end
index bb7eeef2c87b710a289b55741aaa603b46273445..98b515d428c24a2abb6916528eef0b450d2ef5a3 100644 (file)
@@ -91,6 +91,7 @@ service "api-statistics" do
   subscribes :restart, "template[/etc/init.d/api-statistics]"
 end
 
+munin_plugin "api_calls_status"
 munin_plugin "api_calls_num"
 
 munin_plugin "api_calls_#{node[:hostname]}" do