diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6fbc6cf62029d7183d2bfd2560dd583c75aa7af7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +mmpy_bot_settings.py +*.pyc +dist +docs +/*.egg-info +.coverage +lib +bin +lib64 +pyvenv.cfg +share/ +pip-selfcheck.json +.vscode +repl/__pycache__ \ No newline at end of file diff --git a/repl/__pycache__/az.cpython-36.pyc b/repl/__pycache__/az.cpython-36.pyc deleted file mode 100644 index 96deee4ea3f437a04c1fc78c80ad4265009290b5..0000000000000000000000000000000000000000 Binary files a/repl/__pycache__/az.cpython-36.pyc and /dev/null differ diff --git a/repl/__pycache__/az.cpython-37.pyc b/repl/__pycache__/az.cpython-37.pyc deleted file mode 100644 index 2cfdfd3bc7432b03d25c4072d3704df98a8c0c96..0000000000000000000000000000000000000000 Binary files a/repl/__pycache__/az.cpython-37.pyc and /dev/null differ diff --git a/repl/__pycache__/db.cpython-36.pyc b/repl/__pycache__/db.cpython-36.pyc deleted file mode 100644 index 697d1f0169f87200da3828a1a337013c54ef4b05..0000000000000000000000000000000000000000 Binary files a/repl/__pycache__/db.cpython-36.pyc and /dev/null differ diff --git a/repl/__pycache__/db.cpython-37.pyc b/repl/__pycache__/db.cpython-37.pyc deleted file mode 100644 index e787e57ad38008fb1c23f362a468bd9938e09e20..0000000000000000000000000000000000000000 Binary files a/repl/__pycache__/db.cpython-37.pyc and /dev/null differ diff --git a/repl/__pycache__/latex.cpython-36.pyc b/repl/__pycache__/latex.cpython-36.pyc deleted file mode 100644 index 7befe17b46004f1d875c0311815be79390eb5643..0000000000000000000000000000000000000000 Binary files a/repl/__pycache__/latex.cpython-36.pyc and /dev/null differ diff --git a/repl/__pycache__/sections.cpython-36.pyc b/repl/__pycache__/sections.cpython-36.pyc deleted file mode 100644 index 25cdca8b8572749d7e61af867d5a5d9b913e3540..0000000000000000000000000000000000000000 Binary files a/repl/__pycache__/sections.cpython-36.pyc and /dev/null differ diff --git a/repl/__pycache__/trans.cpython-36.pyc b/repl/__pycache__/trans.cpython-36.pyc deleted file mode 100644 index e9c04a0daee6e88c03162b47c24c6aefbbda13ad..0000000000000000000000000000000000000000 Binary files a/repl/__pycache__/trans.cpython-36.pyc and /dev/null differ diff --git a/repl/__pycache__/utils.cpython-36.pyc b/repl/__pycache__/utils.cpython-36.pyc deleted file mode 100644 index 4922f5d0ecb0c2f5f5ed6c19480051db0aae8658..0000000000000000000000000000000000000000 Binary files a/repl/__pycache__/utils.cpython-36.pyc and /dev/null differ diff --git a/repl/__pycache__/utils.cpython-37.pyc b/repl/__pycache__/utils.cpython-37.pyc deleted file mode 100644 index 5b917dcda2026b7cae198c5f8f6a690f89204b12..0000000000000000000000000000000000000000 Binary files a/repl/__pycache__/utils.cpython-37.pyc and /dev/null differ diff --git a/repl/utils.py b/repl/utils.py index 2e86f94d62fe3d724ad4a7804a2020b8d0cd16d6..2ca89c0d487ae1ebe97493d238acd46fa9cfcf18 100644 --- a/repl/utils.py +++ b/repl/utils.py @@ -21,13 +21,14 @@ def get_current_year(short=False): return y def get_current_date(short=False): - return "{}".format(datetime.datetime.today().date()) + return "{}".format(datetime.datetime.today()) -def get_jobs(server, port): +def get_docs(server, port): + url = "http://{}:{}/_scheduler/docs".format(server, port) try: - req = requests.get("http://{}:{}/_scheduler/jobs".format(server, port), verify=False, timeout=0.1) - return req.json().get("jobs", []) + req = requests.get(url, verify=False, timeout=0.2) + return req.json().get("docs", []) except: return [] @@ -44,7 +45,7 @@ def gen_count(): yield i i = i + 1 -def get_info(url, srv): +def gen_ext_name(url, srv): p = urlparse(url) db = p.path.replace("/","") @@ -52,63 +53,47 @@ def get_info(url, srv): host = host.replace("localhost", srv) host = host.split(".")[0] - return db, host + return "{}@{}".format(db, host) -def gen_ext_name(d, h): - return "{}@{}".format(d, h) +def gen_edge_label(doc): + state = doc.get("state", "nil") + err_cnt = doc.get("error_count") + info = doc.get("info") + if type(info) is dict: -def make_label(job): - hist = job.get("history") - l = "" - for h in hist: - s = h.get("type")[0] - l = "{s} {l}".format(l = l, s = s) - return l + wrt_cnt = info.get("docs_written") + else: + wrt_cnt = 0 + d = {"running":"R", + "failed": "F ({})".format(err_cnt), + "completed": "C ({})".format( wrt_cnt)} + return d.get(state) -def get_nodes_and_edges(jobs, gen, hosts, dbs, nodes, edges, srv): - - for job in jobs: - s = job.get("source") - t = job.get("target") +def get_nodes_and_edges(docs, gen, dbs, nodes, edges, srv): + + for doc in docs: + s = doc.get("source") + t = doc.get("target") - e_label = make_label(job) if s and t: - s_db, s_host = get_info(s, srv) - t_db, t_host = get_info(t, srv) - s_db_name = gen_ext_name(s_db, s_host) - t_db_name = gen_ext_name(t_db, t_host) - - if s_host not in hosts: - hosts[s_host] = gen.__next__() - nodes.append({"id": hosts[s_host], - "label": s_host, - "group": "server" }) - - if t_host not in hosts: - hosts[t_host] = gen.__next__() - nodes.append({"id": hosts[t_host], - "label": t_host, - "group": "server"}) + s_db_name = gen_ext_name(s, srv) + t_db_name = gen_ext_name(t, srv) if s_db_name not in dbs: dbs[s_db_name] = gen.__next__() nodes.append({"id": dbs[s_db_name], - "label": s_db, + "label": s_db_name, "group": "db"}) if t_db_name not in dbs: dbs[t_db_name] = gen.__next__() - nodes.append({"id": dbs[t_db_name], "label": t_db, "group": "db"}) + nodes.append({"id": dbs[t_db_name], + "label": t_db_name, + "group": "db"}) edges.append({"from": dbs[s_db_name] , "to":dbs[t_db_name] , "arrow_type": "to" , - "label" : e_label}) - edges.append({"from": hosts[s_host] , - "to":dbs[s_db_name], - "arrow_type":"to"}) - edges.append({"from": hosts[t_host] , - "to":dbs[t_db_name], - "arrow_type":"from"}) - + "label" :gen_edge_label(doc)}) + return nodes, edges diff --git a/server.py b/server.py index 0465c1c58d34cd2171c72f023e9775743a90a7a0..68a188cff176b5416f6aefacf05cd582d8660fcf 100644 --- a/server.py +++ b/server.py @@ -13,17 +13,16 @@ CORS(app) @app.route('/repl/all.html', methods=['GET']) def repl_all(): gen = utils.gen_count() - hosts = {} dbs = {} nodes = [] edges = [] srvs = utils.get_server() for srv in srvs: - jobs = utils.get_jobs(srv.get("name"), srv.get("port")) - nodes, edges = utils.get_nodes_and_edges(jobs, gen, hosts, dbs, nodes, edges, srv.get("name")) + docs = utils.get_docs(srv.get("name"), srv.get("port")) + nodes, edges = utils.get_nodes_and_edges(docs, gen, dbs, nodes, edges, srv.get("name")) template = utils.path_file(path=config['templates']['html'], file='all.html') - return render_template(template, nodes=nodes, edges=edges) + return render_template(template, nodes=nodes, edges=edges, date=utils.get_current_date()) @app.route('/js/<fn>', methods=['get']) def js_folder(fn): diff --git a/templates/html/all.html b/templates/html/all.html index c3437097d51c7575cfcc7a607314c910bf7dc2a7..f983dc9b56b299964e4f83ca9308883e68915eb2 100644 --- a/templates/html/all.html +++ b/templates/html/all.html @@ -40,7 +40,8 @@ <footer class="footer mt-auto py-3"> <div class="container"> - <span class="text-muted"><b>a</b>: added, <b>s</b>: started, <b>c:</b> crasched</span> + <span class="text-muted"><b>R</b>: running, <b>C</b>: complete (number of docs written), <b>F:</b> failed (error count)</span> + <span>last updated on {{date}}</span> </div> </footer> @@ -60,8 +61,8 @@ {from: {{edge.from}}, to: {{edge.to}} , arrows:"{{edge.arrow_type}}" , - label : "{{edge.label|safe}}", - font: { multi: "md" }}, + font: { align: "middle", face: "Monospace" }, + label : "{{edge.label|safe}}"}, {%endfor%} ]); var container = document.getElementById('net'); @@ -71,6 +72,9 @@ }; var options = { + physics: { + enabled: true, + }, edges: { smooth: true }, @@ -80,7 +84,7 @@ color: "#FF9900" }, db: { - shape: "database" + shape: "box" }}} var network = new vis.Network(container, data, options); </script>