class FGmonitorWeb: def __init__(self): self.fgmongodb = FGMongodb() self.fgmongodb.connect() self.chart = FGCharts() def count_floatingIPs(self): res = [] found = self.fgmongodb.find("floatingip", {}) for record in found: total = len(record["data"]) avail = 0 for data in record['data']: if data['instanceid'] == 'None': avail += 1 res.append({ "service": record["service"],\ "hostname": record["hostname"], \ "total": total,\ "avail": avail,\ "time": str(record["time"])}) return res def series_floatingIPs(self): res = {} found = self.fgmongodb.find("floatingip", {}) for record in found: total = len(record["data"]) avail = total for data in record['data']: if data['instanceid'] == 'None': avail += 1 res[record["time"]] = avail new_res = { "name" : "floatingip",\ "data" : res } return [new_res] def count_computenodes(self): res = [] found = self.fgmongodb.find("computenodes", {}) for record in found: total = len(record["data"]) avail = total for data in record['data']: if data['state'] != ':-)': avail -= 1 res.append({ "service": record["service"],\ "hostname": record["hostname"], \ "total": total,\ "avail": avail,\ "time": str(record["time"])}) return res def series_computenodes(self): res = {} found = self.fgmongodb.find("computenodes", {}) for record in found: total = len(record["data"]) avail = total for data in record['data']: if data['state'] != ':-)': avail -= 1 res[record["time"]] = avail new_res = { "name" : "computenodes",\ "data" : res } return [new_res] @cherrypy.expose def chart_computenodes(self): self.chart.set_chart_api("highcharts") self.chart.set_type("line-time-series") res = self.series_computenodes() self.chart.set_series(res) self.chart.load_script_path("global") res = {"stdout":None} self.chart.display(res) return res["stdout"] @cherrypy.expose def chart_floatingips(self): self.chart.set_chart_api("highcharts") self.chart.set_type("line-time-series") res = self.series_floatingIPs() self.chart.set_series(res) self.chart.load_script_path("global") res = {"stdout":None} self.chart.display(res) return res["stdout"] @cherrypy.expose @cherrypy.tools.json_out() def list(self): return self.count_floatingIPs() @cherrypy.expose @cherrypy.tools.json_out() def listips(self): return self.count_floatingIPs() @cherrypy.expose @cherrypy.tools.json_out() def listnodes(self): return self.count_computenodes() listips.exposed = True listnodes.exposed = True list.exposed = True
clusters = list(self.get_clusters()) # copy new list for cluster in clusters: ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.WarningPolicy()) ssh.connect(hostname=cluster["hostname"], username="******", key_filename="/home/hyungro/.ssh/.i") ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command("ssh i50 sudo nova-manage service list|grep nova-compute") for line in ssh_stdout.readlines(): column = line.split() try: res.append({"node":column[1], "status":column[3], "state": column[4]}) except: res = [{"node":column[1], "status":column[3], "state": column[4]}] cluster["data"] = res cluster["time"] = datetime.now() self.data['computenodes'] = clusters return clusters if __name__ == "__main__": fgmonitor = FGMonitor() fgmongodb = FGMongodb() fgmongodb.connect() res = fgmonitor.get_floatingIPs() fgmongodb.insert("floatingip", res) res = fgmonitor.get_computenodes() fgmongodb.insert("computenodes", res)