8 def uris_from_status(server)
 
   9   file = open("http://#{server}/server-status").read
 
  10   doc = Hpricot.parse(file)
 
  11   tables = doc / "table"
 
  12   rows = (tables[1] / "tr")[1..-1]
 
  13   data = rows.collect { |r| (r / "td").collect(&:inner_html) }
 
  14   # filter where the PID is numeric, status is 'W' and host matches the server
 
  15   matching_data = data.select { |r| r[1].to_i.positive? && r[3].match(/W/) && r[12].match(server) }
 
  16   # return only the URI part
 
  17   matching_data.collect { |r| r[13] }
 
  21   :map => "Map API calls",
 
  22   :upload => "Changeset diff uploads",
 
  23   :amf => "AMF API calls",
 
  24   :history => "Element history fetches",
 
  25   :full => "Full element fetches",
 
  26   :trkpts => "GPX trackpoints calls",
 
  27   :web => "Web site traffic",
 
  28   :other => "Other API calls"
 
  31 def categorise_uri(line)
 
  32   uri = line.split(" ")[1]
 
  35   when %r{api/0\.6/map} then :map
 
  36   when %r{api/0\.6/changeset/[0-9]*/upload} then :upload
 
  37   when %r{api/0\.6/amf} then :amf
 
  38   when %r{api/0\.6/(node|way|relation)/[0-9]*/history} then :history
 
  39   when %r{api/0\.6/(node|way|relation)/[0-9]*/full} then :full
 
  40   when %r{api/0\.6/trackpoints} then :trkpts
 
  41   when %r{api/0\.6/} then :other
 
  46 server = $PROGRAM_NAME.match("api_calls_(.*)")[1]
 
  48 if ARGV[0] == "config"
 
  49   puts "graph_title Active requests"
 
  50   puts "graph_vlabel Number of requests"
 
  51   puts "graph_category api"
 
  52   CALL_TYPES.each { |k, v| puts "#{k}.label #{v}" }
 
  55   counts = uris_from_status(server)
 
  56            .collect { |x| categorise_uri(x) }
 
  57            .each_with_object({}) do |e, h|
 
  65   CALL_TYPES.each_key do |type|
 
  66     count = counts[type] || 0
 
  67     puts "#{type}.value #{count}"