-
Notifications
You must be signed in to change notification settings - Fork 1
/
supervisor-monitor.py
executable file
·135 lines (101 loc) · 3.76 KB
/
supervisor-monitor.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python2.7
#Jack Dwyer 12-12-2012
import argparse, sys
from urlparse import urlparse
from flask import Flask, abort, redirect, url_for
from flask import render_template
import xmlrpclib
import utils
from client import SupervisorClient
app = Flask(__name__)
@app.route('/group/<selectedGroup>')
def group_list(selectedGroup):
fullDetails = {}
supervisors = {}
fullDetails["totalRunning"] = 0
fullDetails["totalProcesses"] = 0
tables = 0
for group, value in app.clients.items():
if group == selectedGroup:
supervisors[group] = []
for supervisor in value:
details = supervisor.get_details()
supervisors[group].append(details)
fullDetails["totalRunning"] += details["totalClientRunning"]
fullDetails["totalProcesses"] += details["totalClientProcesses"]
tables += 1
if tables == 0:
return redirect(url_for('list_all'))
fullDetails["totalTables"] = tables
fullDetails["supervisors"] = supervisors
fullDetails["groups"] = app.groups
return render_template('list.html', details=fullDetails)
@app.route('/')
def list_all():
fullDetails = {}
fullDetails["totalRunning"] = 0
fullDetails["totalProcesses"] = 0
print app.clients
supervisors = {}
for group, value in app.clients.items():
supervisors[group] = []
for supervisor in value:
details = supervisor.get_details()
supervisors[group].append(details)
fullDetails["totalRunning"] += details["totalClientRunning"]
fullDetails["totalProcesses"] += details["totalClientProcesses"]
fullDetails["totalTables"] = app.totalTables
fullDetails["supervisors"] = supervisors
fullDetails["groups"] = app.groups
return render_template('list.html', details=fullDetails)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--port', action='store', default=5000,
help='Set port to run on')
parser.add_argument('--debug', action='store_true', default=False,
help='Use to start server in debug mode')
results = parser.parse_args()
groups = []
clients = {}
#Generate Supervisor clients
clientID = 0
#for detail in clientDetails:
# uri = urlparse(detail[0])
# try:
# name = detail[1]
# except IndexError:
# name = None
#
# clients.append(SupervisorClient(uri, clientID, name))
supervisors = utils.read_yaml()
for key, value in supervisors.items():
uri = urlparse("%s%s%s%s%s" % (value["scheme"], "://", str(key), ":", str(value["port"])))
client = SupervisorClient(uri, clientID)
#Add extra details if avaliable
try:
client.name = value["name"]
except KeyError:
pass
try:
client.group = value["group"]
if not value["group"] in groups:
groups.append(value["group"])
except KeyError:
value["group"] = "default"
groups.append(value["group"])
try:
client.description = value["description"]
except KeyError:
pass
try:
clients[value["group"]].append(client)
except KeyError:
clients[value["group"]] = []
clients[value["group"]].append(client)
#clients.append(client)
clientID += 1
print clients
app.clients = clients
app.groups = sorted(groups, key=str.lower)
app.totalTables = clientID
app.run(host='0.0.0.0', debug=results.debug, port=results.port)