Add a new Squid graph to count the IPs being delayed due to no-referer, and restrict...
[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 }.freeze
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     puts "http#{code}.min 0"
38   end
39 else
40   statistics = JSON.parse(File.read("/srv/www.openstreetmap.org/rails/tmp/statistics.json"))
41
42   HTTP_STATUSES.keys.each do |code|
43     count = statistics["status"][code] || 0
44     puts "http#{code}.value #{count}"
45   end
46 end