-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus.py
71 lines (62 loc) · 2.24 KB
/
status.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
67
68
69
70
71
#!/usr/bin/python
#coding=utf-8
import redis
import random
import time
from wsgiref.simple_server import make_server
serverport = 8005
redis_host = 'localhost'
redis_port = '6379'
redis_db = '0'
rs = redis.StrictRedis(host=redis_host,port=redis_port,db=redis_db)
html_HEAD = '<html><head><title>StatUS</title></head><body><table border="1">'
html_END = '</table></body></html>'
#rds = 'SERVER1'
def nvisitor():
visitor = rs.get('visitor')
if visitor != '':
try:
visitor = int(visitor) + 1
except Exception, e:
print repr(e)
rs.set('visitor','0')
rs.set('visitor',str(visitor))
else:
rs.set('visitor','0')
print 'visitor set 0'
return visitor
def getstatus():
try:
sleepTime = round(random.uniform(0,6),2)
print sleepTime
#time.sleep(sleepTime)
urllist = rs.smembers ('Serverlist')
print urllist
uplodaTime = table =tables = ''
for url in urllist:
http_code = rs.get(url)
if http_code != '200':
http_code = '<font color="#FF0000"><strong>'+http_code+'</strong></font>'
else:
http_code = '<font color="#0000FF"><strong>'+http_code+'</strong></font>'
url = '<a href="'+url+'" target="_blank">' +url+ "</a>"
table = '<tr><td>'+str(url)+'</td><td>'+str(http_code)+'</td></tr>'
tables = tables + table
uplodaTime = '<tr><td>uploadTime</td><td>'+str(rs.get('uploadTime'))+'</td></tr>'+'<tr><td>Current time</td><td>'+str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))+'</td></tr>'
pv = 'PV : ' + str(nvisitor())
pv = '<font><strong>'+pv+'</strong></font>'
repo = html_HEAD + tables + uplodaTime + pv + html_END
return repo
except Exception, e:
print repr(e)
return 'Server except'
def app(environ, start_response):
status = "200 OK"
response_headers = [('Content-type', 'text/html')]
start_response(status, response_headers)
# The returned object is going to be printed
return getstatus()
httpd = make_server('', serverport, app)
print 'Serving on port '+ str(serverport) +'...'
# Serve until process is killed
httpd.serve_forever()