]> git.openstreetmap.org Git - chef.git/blob - cookbooks/tile/templates/default/debug.erb
Add support for systemd timer units
[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 re
8 import sys
9 import resource
10 import time
11
12 # HTML Debug of errors
13 cgitb.enable()
14
15 # Limit maximum CPU time
16 # The Postscript output format can sometimes take hours
17 resource.setrlimit(resource.RLIMIT_CPU,(180,180))
18
19 # Limit memory usage
20 # Some odd requests can cause extreme memory usage
21 resource.setrlimit(resource.RLIMIT_AS,(4000000000, 4000000000))
22
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"
27   print "Expires: 0"
28   print "Content-Type: %s" % content_type
29   if filename:
30     print "Content-Disposition: attachment; filename=\"%s\"" % filename
31   if length:
32     print "Content-Length: %d" % length
33   print ""
34
35 # Routine to report an error
36 def output_error(message):
37   output_headers("text/html")
38   print "<html>"
39   print "<head>"
40   print "<title>Error</title>"
41   print "</head>"
42   print "<body>"
43   print "<h1>Error</h1>"
44   print "<p>%s</p>" % message
45   print "</body>"
46   print "</html>"
47
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'
51
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)
55 else:
56   cache_server = None
57
58 # Get the load average
59 loadavg = float(open("/proc/loadavg").readline().split(" ")[0])
60
61 output_headers("text/html")
62 print "<html>"
63 print "<head>"
64 print "<title>tile.openstreetmap.org debug</title>"
65 print "</head>"
66 print "<body>"
67 print "<h1>tile.openstreetmap.org debug</h1>"
68 print "<h2>Server Stats</h2>"
69 if cache_server:
70   print "<p><b>Cache Server</b>: %s</p>" % cache_server
71 print "<p>"
72 print "<b>Render Server</b>: <%= node['fqdn'] %><br />"
73 print "<b>Load Average</b>: %s</p>" % loadavg
74 print "<h2>File Status</h2>"
75 print "<p>"
76 <%
77 node[:tile][:data].each do |name,data|
78   url = data[:url]
79   file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
80   file_basename = File.basename(url)
81 -%>
82 print "<b>%s</b> last modified: %s<br />" % ("<%= file_basename %>", time.ctime(os.path.getmtime("<%= file %>")))
83 <%
84 end
85 -%>
86 print "</p>"
87 print "<h2>Browser Request Headers</h2>"
88 print "<p>"
89 for param in os.environ.keys():
90   print "<b>%20s</b>: %s<br />" % (param, os.environ[param])
91 print "</p>"
92 print "</body>"
93 print "</html>"