]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/files/default/plugins/api_calls_status
8167f21d6ff05e0a1a783b605c47bfb79a5955dd
[chef.git] / cookbooks / munin / files / default / plugins / api_calls_status
1 #!/usr/bin/ruby
2
3 require "json"
4
5 HTTP_STATUSES = {
6   "200" => "OK",
7   "206" => "Partial Content",
8   "301" => "Moved Permanently",
9   "302" => "Found",
10   "303" => "See Other",
11   "304" => "Not Modified",
12   "400" => "Bad Request",
13   "401" => "Unauthorized",
14   "403" => "Forbidden",
15   "404" => "Not Found",
16   "405" => "Method Not Allowed",
17   "408" => "Request Timeout",
18   "409" => "Conflict",
19   "410" => "Gone",
20   "412" => "Precondition Failed",
21   "416" => "Requested Range Not Satisfiable",
22   "500" => "Internal Server Error",
23   "502" => "Bad Gateway",
24   "503" => "Service Unavailable",
25   "509" => "Bandwidth Limit Exceeded"
26 }
27
28 if ARGV[0] == "config"
29   puts "graph_title HTTP response codes"
30   puts "graph_args --base 1000"
31   puts "graph_vlabel Number of requests per ${graph_period}"
32   puts "graph_category api"
33
34   HTTP_STATUSES.each do |code, label|
35     puts "http#{code}.label #{code} #{label}"
36     puts "http#{code}.type DERIVE"
37   end
38 else
39   statistics = JSON.parse(File.read("/srv/www.openstreetmap.org/rails/tmp/statistics.json"))
40
41   HTTP_STATUSES.keys.each do |code|
42     count = statistics["status"][code] || 0
43     puts "http#{code}.value #{count}"
44   end
45 end