forked from Lexxie9952/fcw.org-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebugging.py
executable file
·68 lines (54 loc) · 2.15 KB
/
debugging.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
'''
Freeciv - Copyright (C) 2009-2017 - Andreas Røsdal [email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
'''
import sys
from time import gmtime, strftime
import os
import platform
import threading
import time
from tornado import version as tornado_version
import gc
startTime = time.time()
def get_debug_info(civcoms):
code = "<html><head><meta http-equiv=\"refresh\" content=\"20\">" \
+ "<link href='/css/bootstrap.min.css' rel='stylesheet'></head>" \
+ "<body><div class='container'>" \
+ "<h2>Freeciv WebSocket Proxy Status</h2>" \
+ "<font color=\"green\">Process status: OK</font><br>"
code += "<b>Process Uptime: " + \
str(int(time.time() - startTime)) + " s.</b><br>"
code += ("Python version: %s %s (%s)<br>" % (
platform.python_implementation(),
platform.python_version(),
platform.python_build()[0],
))
cpu = ' '.join(platform.processor().split())
code += ("Platform: %s %s on '%s' <br>" % (
platform.machine(),
platform.system(),
cpu))
code += ("Tornado version %s <br>" % (tornado_version))
code += ("Number of threads: %i <br>" % (threading.activeCount()))
try:
code += ("<h3>Logged in users (count %i) :</h3>" % len(civcoms))
for key in list(civcoms.keys()):
code += (
"username: <b>%s</b> <br>Civserver: %d<br>Connect time: %d<br><br>" %
(civcoms[key].username,
civcoms[key].civserverport,
time.time() - civcoms[key].connect_time))
except:
print(("Unexpected error:" + str(sys.exc_info()[0])))
raise
code += "</div></body></html>"
return code