]> git.openstreetmap.org Git - chef.git/blob - cookbooks/tile/templates/default/debug.erb
3da30dfebf65274838cd9aeca145e3fa8daa5570
[chef.git] / cookbooks / tile / templates / default / debug.erb
1 #!/usr/bin/python -u
2 # -*- coding: utf-8 -*-
3
4 import cgi
5 import cgitb
6 import os
7 import sys
8 import resource
9 import time
10
11 # HTML Debug of errors
12 cgitb.enable()
13
14 # Limit maximum CPU time
15 # The Postscript output format can sometimes take hours
16 resource.setrlimit(resource.RLIMIT_CPU,(180,180))
17
18 # Limit memory usage
19 # Some odd requests can cause extreme memory usage
20 resource.setrlimit(resource.RLIMIT_AS,(4000000000, 4000000000))
21
22 # Routine to output HTTP headers
23 def output_headers(content_type, filename = "", length = 0):
24   print "Cache-Control: no-cache, no-store, must-revalidate')"
25   print "Pragma: no-cache"
26   print "Expires: 0"
27   print "Content-Type: %s" % content_type
28   if filename:
29     print "Content-Disposition: attachment; filename=\"%s\"" % filename
30   if length:
31     print "Content-Length: %d" % length
32   print ""
33
34 # Routine to report an error
35 def output_error(message):
36   output_headers("text/html")
37   print "<html>"
38   print "<head>"
39   print "<title>Error</title>"
40   print "</head>"
41   print "<body>"
42   print "<h1>Error</h1>"
43   print "<p>%s</p>" % message
44   print "</body>"
45   print "</html>"
46
47 # Make sure we have a user agent
48 if not os.environ.has_key('HTTP_USER_AGENT'):
49   os.environ['HTTP_USER_AGENT'] = 'NONE'
50
51 # Get the load average
52 loadavg = float(open("/proc/loadavg").readline().split(" ")[0])
53
54 output_headers("text/html")
55 print "<html>"
56 print "<head>"
57 print "<title>tile.openstreetmap.org debug</title>"
58 print "</head>"
59 print "<body>"
60 print "<h1>tile.openstreetmap.org debug</h1>"
61 print "<h2>Server Stats</h2>"
62 print "<p>"
63 print "<b>Render Server</b>: <%= node['fqdn'] %><br />"
64 print "<b>Load Average</b>: %s</p>" % loadavg
65 print "<h2>File Status</h2>"
66 print "<p>"
67 <%
68 node[:tile][:data].each do |name,data|
69   url = data[:url]
70   file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
71   file_basename = File.basename(url)
72 -%>
73 print "<b>%s</b> last modified: %s<br />" % ("<%= file_basename %>", time.ctime(os.path.getmtime("<%= file %>")))
74 <%
75 end
76 -%>
77 print "</p>"
78 print "<h2>Browser Request Headers</h2>"
79 print "<p>"
80 for param in os.environ.keys():
81   print "<b>%20s</b>: %s<br />" % (param, os.environ[param])
82 print "</p>"
83 print "</body>"
84 print "</html>"