]> git.openstreetmap.org Git - chef.git/blob - cookbooks/tile/templates/default/debug.erb
998ed7b0e05507c9f6c3012e4ddff56a0deffb37
[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
10 # HTML Debug of errors
11 cgitb.enable()
12
13 # Limit maximum CPU time
14 # The Postscript output format can sometimes take hours
15 resource.setrlimit(resource.RLIMIT_CPU,(180,180))
16
17 # Limit memory usage
18 # Some odd requests can cause extreme memory usage
19 resource.setrlimit(resource.RLIMIT_AS,(4000000000, 4000000000))
20
21 # Routine to output HTTP headers
22 def output_headers(content_type, filename = "", length = 0):
23   print "Cache-Control: no-cache, no-store, must-revalidate')"
24   print "Pragma: no-cache"
25   print "Expires: 0"
26   print "Content-Type: %s" % content_type
27   if filename:
28     print "Content-Disposition: attachment; filename=\"%s\"" % filename
29   if length:
30     print "Content-Length: %d" % length
31   print ""
32
33 # Routine to report an error
34 def output_error(message):
35   output_headers("text/html")
36   print "<html>"
37   print "<head>"
38   print "<title>Error</title>"
39   print "</head>"
40   print "<body>"
41   print "<h1>Error</h1>"
42   print "<p>%s</p>" % message
43   print "</body>"
44   print "</html>"
45
46 # Make sure we have a user agent
47 if not os.environ.has_key('HTTP_USER_AGENT'):
48   os.environ['HTTP_USER_AGENT'] = 'NONE'
49
50 # Get the load average
51 loadavg = float(open("/proc/loadavg").readline().split(" ")[0])
52
53 output_headers("text/html")
54 print "<html>"
55 print "<head>"
56 print "<title>tile.openstreetmap.org debug</title>"
57 print "</head>"
58 print "<body>"
59 print "<h1>tile.openstreetmap.org debug</h1>"
60 print "<h2>Server Stats</h2>"
61 print "<p><b>Load Average:</b>%s</p>" % loadavg
62 print "<h2>Browser Request Headers</h2>"
63 print "<p>"
64 for param in os.environ.keys():
65   print "<b>%20s</b>: %s<br />" % (param, os.environ[param])
66 print "</p>"
67 print "</body>"
68 print "</html>"