3 require "apache_log_regex"
7 def categorise_uri(line)
8 uri = line.split(" ")[1]
11 when %r{api/0\.6/map} then :map
12 when %r{api/0\.6/changeset/[0-9]*/upload} then :upload
13 when %r{api/0\.6/amf} then :amf
14 when %r{api/0\.6/(node|way|relation)/[0-9]*/history} then :history
15 when %r{api/0\.6/(node|way|relation)/[0-9]*/full} then :full
16 when %r{api/0\.6/trackpoints} then :trkpts
17 when %r{api/0\.6/} then :other
22 parser = ApacheLogRegex.new('%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\" %Ts')
24 statistics = { :status => Hash.new(0), :uri => Hash.new(0) }
26 File::Tail::Logfile.tail("/var/log/apache2/access.log") do |line|
28 hash = parser.parse(line)
30 uri = categorise_uri(hash["%r"])
32 statistics[:status][status] += 1
33 statistics[:uri][uri] += 1
34 rescue ApacheLogRegex::ParseError
38 if Time.now - last_write > 10
39 File.write("/srv/www.openstreetmap.org/rails/tmp/statistics.json", statistics.to_json)