2 # -*- coding: utf-8 -*-
12 # HTML Debug of errors
15 # Limit maximum CPU time
16 # The Postscript output format can sometimes take hours
17 resource.setrlimit(resource.RLIMIT_CPU,(180,180))
20 # Some odd requests can cause extreme memory usage
21 resource.setrlimit(resource.RLIMIT_AS,(4000000000, 4000000000))
23 # Routine to output HTTP headers
24 def output_headers(content_type, filename = "", length = 0):
25 print "Cache-Control: no-cache, no-store, must-revalidate')"
26 print "Pragma: no-cache"
28 print "Content-Type: %s" % content_type
30 print "Content-Disposition: attachment; filename=\"%s\"" % filename
32 print "Content-Length: %d" % length
35 # Routine to report an error
36 def output_error(message):
37 output_headers("text/html")
40 print "<title>Error</title>"
43 print "<h1>Error</h1>"
44 print "<p>%s</p>" % message
48 # Make sure we have a user agent
49 if not os.environ.has_key('HTTP_USER_AGENT'):
50 os.environ['HTTP_USER_AGENT'] = 'NONE'
52 # Get the cache server name
53 if os.environ.has_key('HTTP_VIA'):
54 cache_server = re.search('[a-z0-9-]+\.openstreetmap\.org', os.environ['HTTP_VIA']).group(0)
58 # Get the load average
59 loadavg = float(open("/proc/loadavg").readline().split(" ")[0])
61 output_headers("text/html")
64 print "<title>tile.openstreetmap.org debug</title>"
67 print "<h1>tile.openstreetmap.org debug</h1>"
68 print "<h2>Server Stats</h2>"
70 print "<p><b>Cache Server</b>: %s</p>" % cache_server
72 print "<b>Render Server</b>: <%= node['fqdn'] %><br />"
73 print "<b>Load Average</b>: %s</p>" % loadavg
74 print "<h2>File Status</h2>"
77 node[:tile][:data].each do |name,data|
79 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
80 file_basename = File.basename(url)
82 print "<b>%s</b> last modified: %s<br />" % ("<%= file_basename %>", time.ctime(os.path.getmtime("<%= file %>")))
87 print "<h2>Browser Request Headers</h2>"
89 for param in os.environ.keys():
90 print "<b>%20s</b>: %s<br />" % (param, os.environ[param])