2016-03-31 16:03:38 +08:00
|
|
|
from flask import session
|
|
|
|
from webViews.view import normalView
|
|
|
|
from webViews.dockletrequest import dockletRequest
|
|
|
|
|
|
|
|
|
|
|
|
class statusView(normalView):
|
|
|
|
template_path = "monitor/status.html"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get(self):
|
|
|
|
data = {
|
|
|
|
"user": session['username'],
|
|
|
|
}
|
|
|
|
result = dockletRequest.post('/cluster/list/', data)
|
|
|
|
clusters = result.get('clusters')
|
2016-04-14 15:52:44 +08:00
|
|
|
result = dockletRequest.post('/monitor/user/quotainfo/', data)
|
|
|
|
quotainfo = result.get('quotainfo')
|
2016-04-18 10:35:04 +08:00
|
|
|
quotainfo['cpu'] = int(int(quotainfo['cpu']))
|
2016-04-14 15:52:44 +08:00
|
|
|
print(quotainfo)
|
2016-03-31 16:03:38 +08:00
|
|
|
if (result):
|
|
|
|
containers = {}
|
|
|
|
for cluster in clusters:
|
|
|
|
data["clustername"] = cluster
|
|
|
|
message = dockletRequest.post('/cluster/info/', data)
|
|
|
|
if (message):
|
|
|
|
message = message.get('message')
|
|
|
|
else:
|
|
|
|
self.error()
|
|
|
|
containers[cluster] = message
|
2016-04-14 15:52:44 +08:00
|
|
|
return self.render(self.template_path, clusters = clusters, quotainfo = quotainfo, containers = containers, user = session['username'])
|
2016-03-31 16:03:38 +08:00
|
|
|
else:
|
|
|
|
self.error()
|
|
|
|
|
|
|
|
class statusRealtimeView(normalView):
|
|
|
|
template_path = "monitor/statusRealtime.html"
|
|
|
|
node_name = ""
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get(self):
|
|
|
|
data = {
|
|
|
|
"user": session['username'],
|
|
|
|
}
|
2016-04-27 15:59:33 +08:00
|
|
|
result = dockletRequest.post('/monitor/vnodes/%s/basic_info/'%(self.node_name), data)
|
2016-03-31 16:03:38 +08:00
|
|
|
basic_info = result.get('monitor').get('basic_info')
|
|
|
|
return self.render(self.template_path, node_name = self.node_name, user = session['username'], container = basic_info)
|
|
|
|
|
2016-07-24 13:51:01 +08:00
|
|
|
class historyView(normalView):
|
|
|
|
template_path = "monitor/history.html"
|
|
|
|
vnode_name = ""
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get(self):
|
|
|
|
data = {
|
|
|
|
"user": session['username'],
|
|
|
|
}
|
|
|
|
result = dockletRequest.post('/monitor/vnodes/%s/history/'%(self.vnode_name), data)
|
|
|
|
history = result.get('monitor').get('history')
|
|
|
|
return self.render(self.template_path, vnode_name = self.vnode_name, user = session['username'], history = history)
|
|
|
|
|
2016-03-31 16:03:38 +08:00
|
|
|
class hostsRealtimeView(normalView):
|
|
|
|
template_path = "monitor/hostsRealtime.html"
|
|
|
|
com_ip = ""
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get(self):
|
|
|
|
data = {
|
|
|
|
"user": session['username'],
|
|
|
|
}
|
2016-04-27 15:59:33 +08:00
|
|
|
result = dockletRequest.post('/monitor/hosts/%s/cpuconfig/'%(self.com_ip), data)
|
2016-03-31 16:03:38 +08:00
|
|
|
proc = result.get('monitor').get('cpuconfig')
|
2016-04-27 15:59:33 +08:00
|
|
|
result = dockletRequest.post('/monitor/hosts/%s/osinfo/'%(self.com_ip), data)
|
2016-03-31 16:03:38 +08:00
|
|
|
osinfo = result.get('monitor').get('osinfo')
|
2016-04-27 15:59:33 +08:00
|
|
|
result = dockletRequest.post('/monitor/hosts/%s/diskinfo/'%(self.com_ip), data)
|
2016-03-31 16:03:38 +08:00
|
|
|
diskinfos = result.get('monitor').get('diskinfo')
|
|
|
|
|
|
|
|
return self.render(self.template_path, com_ip = self.com_ip, user = session['username'],processors = proc, OSinfo = osinfo, diskinfos = diskinfos)
|
|
|
|
|
|
|
|
class hostsConAllView(normalView):
|
|
|
|
template_path = "monitor/hostsConAll.html"
|
|
|
|
com_ip = ""
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get(self):
|
|
|
|
data = {
|
|
|
|
"user": session['username'],
|
|
|
|
}
|
2016-04-27 15:59:33 +08:00
|
|
|
result = dockletRequest.post('/monitor/hosts/%s/containerslist/'%(self.com_ip), data)
|
2016-03-31 16:03:38 +08:00
|
|
|
containers = result.get('monitor').get('containerslist')
|
|
|
|
containerslist = []
|
|
|
|
for container in containers:
|
2016-04-27 15:59:33 +08:00
|
|
|
result = dockletRequest.post('/monitor/vnodes/%s/basic_info/'%(container), data)
|
2016-03-31 16:03:38 +08:00
|
|
|
basic_info = result.get('monitor').get('basic_info')
|
2016-04-27 15:59:33 +08:00
|
|
|
result = dockletRequest.post('/monitor/vnodes/%s/owner/'%(container), data)
|
2016-04-25 01:00:06 +08:00
|
|
|
owner = result.get('monitor')
|
2016-04-23 16:37:15 +08:00
|
|
|
basic_info['owner'] = owner
|
2016-03-31 16:03:38 +08:00
|
|
|
containerslist.append(basic_info)
|
|
|
|
return self.render(self.template_path, containerslist = containerslist, com_ip = self.com_ip, user = session['username'])
|
|
|
|
|
|
|
|
class hostsView(normalView):
|
|
|
|
template_path = "monitor/hosts.html"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get(self):
|
|
|
|
data = {
|
|
|
|
"user": session['username'],
|
|
|
|
}
|
2016-04-27 15:59:33 +08:00
|
|
|
result = dockletRequest.post('/monitor/listphynodes/', data)
|
2016-03-31 16:03:38 +08:00
|
|
|
iplist = result.get('monitor').get('allnodes')
|
|
|
|
machines = []
|
|
|
|
for ip in iplist:
|
|
|
|
containers = {}
|
2016-04-27 15:59:33 +08:00
|
|
|
result = dockletRequest.post('/monitor/hosts/%s/containers/'%(ip), data)
|
2016-03-31 16:03:38 +08:00
|
|
|
containers = result.get('monitor').get('containers')
|
2016-04-27 15:59:33 +08:00
|
|
|
result = dockletRequest.post('/monitor/hosts/%s/status/'%(ip), data)
|
2016-03-31 16:03:38 +08:00
|
|
|
status = result.get('monitor').get('status')
|
|
|
|
machines.append({'ip':ip,'containers':containers, 'status':status})
|
|
|
|
#print(machines)
|
|
|
|
return self.render(self.template_path, machines = machines, user = session['username'])
|
|
|
|
|
|
|
|
class monitorUserAllView(normalView):
|
|
|
|
template_path = "monitor/monitorUserAll.html"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get(self):
|
|
|
|
data = {
|
|
|
|
"user": session['username'],
|
|
|
|
}
|
2016-04-27 15:59:33 +08:00
|
|
|
result = dockletRequest.post('/monitor/listphynodes/', data)
|
2016-03-31 16:03:38 +08:00
|
|
|
userslist = [{'name':'root'},{'name':'libao'}]
|
|
|
|
for user in userslist:
|
2016-04-27 15:59:33 +08:00
|
|
|
result = dockletRequest.post('/monitor/user/%s/clustercnt/'%(user['name']), data)
|
2016-03-31 16:03:38 +08:00
|
|
|
user['clustercnt'] = result.get('monitor').get('clustercnt')
|
|
|
|
return self.render(self.template_path, userslist = userslist, user = session['username'])
|