calculate success & failure rate perc
This commit is contained in:
parent
ff76401ecd
commit
cb00899ec8
|
@ -25,6 +25,20 @@ output = []
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
|
|
||||||
|
def calculate_percentage(data):
|
||||||
|
perc = {}
|
||||||
|
ls = data.values()
|
||||||
|
z, nz = 0,0
|
||||||
|
for v in ls:
|
||||||
|
if v == 0:
|
||||||
|
z += 1
|
||||||
|
else:
|
||||||
|
nz += 1
|
||||||
|
perc['green'] = (float(z)*100)/len(ls)
|
||||||
|
perc['red'] = (float(nz)*100)/len(ls)
|
||||||
|
return perc
|
||||||
|
|
||||||
|
|
||||||
def getMonit():
|
def getMonit():
|
||||||
output = []
|
output = []
|
||||||
xmlQuery = "/_status?format=xml"
|
xmlQuery = "/_status?format=xml"
|
||||||
|
@ -51,7 +65,9 @@ def getMonit():
|
||||||
|
|
||||||
sorted_checks = OrderedDict()
|
sorted_checks = OrderedDict()
|
||||||
sorted_checks = OrderedDict(sorted(checks.iteritems(), key=itemgetter(1), reverse=True))
|
sorted_checks = OrderedDict(sorted(checks.iteritems(), key=itemgetter(1), reverse=True))
|
||||||
server = dict(name=site, url=s['url'], result=sorted_checks)
|
perc = calculate_percentage(sorted_checks)
|
||||||
|
print perc
|
||||||
|
server = dict(name=site, url=s['url'], result=sorted_checks, s_rate=perc)
|
||||||
|
|
||||||
output.append(server)
|
output.append(server)
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,15 @@ for (i = 0; i < acc.length; i++) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw(data) {
|
function draw(rate) {
|
||||||
|
console.log(rate)
|
||||||
|
var green = (rate['green']*2)/100;
|
||||||
|
var red = (rate['red']*2)/100;
|
||||||
var canvas = document.getElementById("canvas");
|
var canvas = document.getElementById("canvas");
|
||||||
var ctx = canvas.getContext("2d");
|
var ctx = canvas.getContext("2d");
|
||||||
|
|
||||||
var colors = ['#40ff00', '#ff0000'];
|
var colors = ['#40ff00', '#ff0000'];
|
||||||
var angles = [Math.PI * 1.5, Math.PI * data];
|
var angles = [Math.PI * green, Math.PI * red];
|
||||||
var offset = 0;
|
var offset = 0;
|
||||||
var beginAngle = 0;
|
var beginAngle = 0;
|
||||||
var endAngle = 0;
|
var endAngle = 0;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
$def with (output, now)
|
$def with (output, now)
|
||||||
$ data = 0.4
|
|
||||||
|
|
||||||
<body onload="draw($data);">
|
<body onload="draw($output[0]['s_rate']);">
|
||||||
$ errors = 0
|
$ errors = 0
|
||||||
$ color = "green"
|
$ color = "green"
|
||||||
$for server in range(len(output)):
|
$for server in range(len(output)):
|
||||||
|
|
Loading…
Reference in a new issue