From 2a8e165efdc9e44738b881ef705fae1bd92c5f6e Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 31 Aug 2017 18:10:08 +0300 Subject: [PATCH] upd --- rbmd/conf.json | 3 +- rbmd/templates/rbmd/index.html | 174 ++++++++++++++------------------- rbmd/test.data | 49 ++++++++++ rbmd/urls.py | 6 ++ rbmd/views.py | 53 ++++++---- 5 files changed, 166 insertions(+), 119 deletions(-) create mode 100644 rbmd/test.data diff --git a/rbmd/conf.json b/rbmd/conf.json index 09026a0..7f9e81b 100644 --- a/rbmd/conf.json +++ b/rbmd/conf.json @@ -1,7 +1,6 @@ { -"mount":"http://127.0.0.1:9076/mount", -"api": "http://127.0.0.1:9076/v1/", +"api": "http://10.8.0.34:9076/v1/", "ws": "ws://php.difrex.ru/ws" } diff --git a/rbmd/templates/rbmd/index.html b/rbmd/templates/rbmd/index.html index 879b3a1..9ff1615 100644 --- a/rbmd/templates/rbmd/index.html +++ b/rbmd/templates/rbmd/index.html @@ -1,115 +1,91 @@ {% load staticfiles %} - + - RBMD - - - - - - + RBMD + + + + - -
-Mount - -
+
+ Mount + +
-
-
-
- × +
+
+
+

Leader:

+

Nodes:

+ +

Metrics:

+ +{% for k,v in metrics.items %} {{k}} {{v}}
{% endfor %} +
+
+
+
Status...
+ +
+ + +
+
+
+
+
+ ×

Mount

-
-
{% csrf_token %} -
- -
-
-
-
-
- +
+ +
+ +
+
+
+
+
+ -
-
-
-
- -
-
-
-
-

Leader:

-

Nodes:

- {% for node in nodes %} - - {% endfor %} -

Metrics:

- {{ metrics }} -
-
- -
-
-
Status...
- -
- - -{% if node %} -
- × -
-
-
-{% endif %} - -
-
-
- -{% if node %} +
+
+
+ + console.log('{{status|escapejs}}') + var res = '{{status|escapejs}}'; + message = "

" + res["state"] + "

"+ res["message"] +"

"; + $("#rspContainer").css("display", "block"); + $("#rsp").html(message) + if (res["state"] == 'OK'){$("#rspContainer").css("background-color", "#4CAF50" );} + else {$("#rspContainer").css("background-color", "#f44336" )} + -{% endif %} - - - + + diff --git a/rbmd/test.data b/rbmd/test.data new file mode 100644 index 0000000..3acd4ce --- /dev/null +++ b/rbmd/test.data @@ -0,0 +1,49 @@ +{ +"status" : + { + "quorum": { + "node.example.com": { + "node": "node.example.com", + "ip": { + "v4": [ + "10.0.3.1" + ], + "v6": [ + "fe80::f869:d0ff:fea3:3c0a" + ] + }, + "updated": 1483428452, + "mounts": null + } + }, + "health": "alive.", + "leader": "node.example.com" + }, +"node" : +{ + "node": "difrex-mac.wargaming.net", + "ip": { + "v4": [ + "169.254.156.1" + ], + "v6": [ + "fe80::108d:fcff:fe77:3df6" + ] + }, + "updated": 1483095493, + "mounts": null +}, +"health": ".alive", +"mount" : +{ + "state": "OK", + "message": "OK" +}, +"metrics": { + "goroutines": 9, + "nodes": 2, + "mountstotal": 0, + "cgocall": 1 + } + +} diff --git a/rbmd/urls.py b/rbmd/urls.py index 4f79a34..4a5f3a4 100644 --- a/rbmd/urls.py +++ b/rbmd/urls.py @@ -21,4 +21,10 @@ urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^$', views.panel), url(r'^status$', views.get_status), + url(r'^node$', views.node), + url(r'^health$', views.health), + url(r'^mount$', views.mount), + url(r'^unmount$', views.get_status), + url(r'^resolve$', views.resolve), + url(r'^metrics$', views.get_metrics), ] diff --git a/rbmd/views.py b/rbmd/views.py index 6329bae..4a516b9 100644 --- a/rbmd/views.py +++ b/rbmd/views.py @@ -6,25 +6,18 @@ from django.shortcuts import render import json import requests -def get_metrics(): - with open('conf.json') as conf: - api = json.load(conf)["api"] - print api - #try: res = requests.get(api + metrics) - return api - -def panel(request): - with open('conf.json') as conf: - ws = json.load(conf)["ws"] - metrics = get_metrics() - return render(request, 'rbmd/index.html', {'ws' : ws, 'metrics' : metrics}) - - -def get_status(request): +def get_status(): with open('conf.json') as conf: - status = json.load(conf)["status"] - #try: res = requests.get(status) - return HttpResponse(status) + status = json.load(conf)["api"] + '/status' + try: res = requests.get(status) + except: res = 'connection can\'t be established' + return res.content + +def node(): + pass + +def health(): + pass def mount(): pass @@ -32,3 +25,27 @@ def mount(): def unmount(): pass +def resolve(): + pass + +def get_metrics(): + #with open('conf.json') as conf: + # api = json.load(conf)["api"] + #try: res = requests.get(api + metrics) + #return api + with open('conf.json') as conf: + metrics = json.load(conf)["api"] + '/metrics' + res = requests.get(metrics) + print res + #except: res = 'connection can\'t be established' + return res.content + +def panel(request): + with open('conf.json') as conf: + ws = json.load(conf)["ws"] + metrics = json.loads(get_metrics()) + status = get_status() + return render(request, 'rbmd/index.html', {'ws' : ws, 'metrics' : metrics, 'status' : status}) + + +