forked from SebastienReuiller/MariaDBClusterWebUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (34 loc) · 1.25 KB
/
main.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "Sébastien Reuiller"
import pymysql
import configparser
from flask import Flask
from flask import render_template
app = Flask(__name__)
@app.route("/")
def home():
conf = configparser.RawConfigParser()
conf.read('nodes.conf')
nodes_item = conf.items("nodes")
nodes = []
for key, host in nodes_item:
dict_wsrep = {}
try:
cnx = pymysql.connect(host=host, port=int(conf.get('access', 'port')), user=conf.get('access', 'user'), passwd=conf.get('access', 'pass'), db='mysql')
with cnx.cursor() as cursor:
cursor.execute("SELECT @@hostname as hostname;")
dict_wsrep['hostname'] = cursor.fetchone()[0]
cursor.execute("SHOW STATUS LIKE 'wsrep%';")
res = cursor.fetchall()
for row in res:
dict_wsrep[row[0]] = row[1]
cnx.close()
except:
dict_wsrep['hostname'] = host
dict_wsrep['wsrep_local_state'] = 0
dict_wsrep['wsrep_local_state_comment'] = 'Error'
nodes.append(dict_wsrep)
return render_template('home.html', nodes=nodes)
if __name__ == "__main__":
app.run(host='0.0.0.0')