This commit is contained in:
Adrià 2020-01-27 00:21:03 +01:00
parent b6d9fc1a28
commit e3707750b4
7 changed files with 108 additions and 100 deletions

View file

@ -27,10 +27,11 @@ output = []
# Functions # Functions
def calculate_count(data): def calculate_count(data):
count = {} count = {}
ls = data.values() ls = data.values()
z, nz = 0,0 z, nz = 0, 0
for v in ls: for v in ls:
if v == 0: if v == 0:
z += 1 z += 1
@ -78,6 +79,7 @@ def getMonit():
# Classes # Classes
class monitDashboard(web.application): class monitDashboard(web.application):
def run(self, port=8080, *middleware): def run(self, port=8080, *middleware):
func = self.wsgifunc(*middleware) func = self.wsgifunc(*middleware)
@ -89,10 +91,12 @@ class index(object):
return render.index(output=getMonit(), return render.index(output=getMonit(),
now=datetime.datetime.now()) now=datetime.datetime.now())
class help(object): class help(object):
def GET(self): def GET(self):
return render.help() return render.help()
class download(object): class download(object):
def GET(self): def GET(self):
filename = 'health_report.xlsx' filename = 'health_report.xlsx'
@ -100,10 +104,11 @@ class download(object):
utils.generate_report_excel(output, filename) utils.generate_report_excel(output, filename)
web.header('Content-Disposition', web.header('Content-Disposition',
'attachment; filename="health_report.xlsx"') 'attachment; filename="health_report.xlsx"')
web.header('Content-type','application/octet-stream') web.header('Content-type', 'application/octet-stream')
web.header('Cache-Control','no-cache') web.header('Cache-Control', 'no-cache')
return open(filename, 'rb').read() return open(filename, 'rb').read()
# Main # Main
if __name__ == "__main__": if __name__ == "__main__":
app = monitDashboard(urls, globals()) app = monitDashboard(urls, globals())

View file

@ -1,6 +1,7 @@
import xlsxwriter import xlsxwriter
import os import os
def generate_report_excel(output, filename): def generate_report_excel(output, filename):
if os.path.exists(filename): if os.path.exists(filename):
os.remove(filename) os.remove(filename)

View file

@ -97,8 +97,8 @@ div.panel.show {
width: 50%; width: 50%;
display: flex; display: flex;
justify-content: center; justify-content: center;
margin-top:200; margin-top: 200;
margin-bottom:100; margin-bottom: 100;
} }
.canvas-graph { .canvas-graph {
@ -108,7 +108,7 @@ div.panel.show {
position: relative; position: relative;
background-color: white; background-color: white;
margin: 20px 0; margin: 20px 0;
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.16),0 2px 10px 0 rgba(0,0,0,0.12) box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12)
} }
.canvas-header { .canvas-header {

View file

@ -11,23 +11,23 @@ for (i = 0; i < acc.length; i++) {
function draw(rate) { function draw(rate) {
var count = [rate['green'], rate['red']]; var count = [rate['green'], rate['red']];
var percentage = [ var percentage = [
(count[0]*100)/(count[0]+count[1]), (count[0] * 100) / (count[0] + count[1]),
(count[1]*100)/(count[0]+count[1]) (count[1] * 100) / (count[0] + count[1])
] ]
var status = ['Ok', 'Error']; var status = ['Ok', 'Error'];
var green = (percentage[0]*2)/100; var green = (percentage[0] * 2) / 100;
var red = (percentage[1]*2)/100; var red = (percentage[1] * 2) / 100;
var canvas = document.getElementById("canvas"); var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d"); var ctx = canvas.getContext("2d");
var colors = ['#00a90e','#ff9a02']; var colors = ['#00a90e', '#ff9a02'];
var angles = [Math.PI * green, Math.PI * red]; 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;
var offsetX, offsetY, medianAngle; var offsetX, offsetY, medianAngle;
ctx.clearRect(0,0,canvas.width, canvas.height); ctx.clearRect(0, 0, canvas.width, canvas.height);
for(var i = 0; i < angles.length; i = i + 1) { for (var i = 0; i < angles.length; i = i + 1) {
beginAngle = endAngle; beginAngle = endAngle;
endAngle = endAngle + angles[i]; endAngle = endAngle + angles[i];
medianAngle = (endAngle + beginAngle) / 2; medianAngle = (endAngle + beginAngle) / 2;
@ -36,7 +36,7 @@ function draw(rate) {
ctx.beginPath(); ctx.beginPath();
if(percentage[i] !== 0) { if (percentage[i] !== 0) {
ctx.fillStyle = colors[i % colors.length]; ctx.fillStyle = colors[i % colors.length];
ctx.moveTo(200 + offsetX, 200 + offsetY); ctx.moveTo(200 + offsetX, 200 + offsetY);
ctx.arc(200 + offsetX, 200 + offsetY, 120, beginAngle, endAngle); ctx.arc(200 + offsetX, 200 + offsetY, 120, beginAngle, endAngle);

View file

@ -1,14 +1,14 @@
$def with (output, now) $def with (output, now)
<body onload="draw($output[0]['s_rate']);"> <body onload="draw($output[0]['s_rate']);">
$ errors = 0 $ errors = 0
$ color = "green" $ color = "green"
<div> <div>
<div class="download-header"> <div class="download-header">
<button class="download-button" onclick="window.location.href = 'download';">Download Report</button> <button class="download-button" onclick="window.location.href = 'download';">Download Report</button>
</div> </div>
<div style="height: 100%;border-right:2px solid #ccc; padding:5px;overflow-x: hidden; float:left; width:48%"> <div style="height: 100%;border-right:2px solid #ccc; padding:5px;overflow-x: hidden; float:left; width:48%">
$for server in range(len(output)): $for server in range(len(output)):
$code: $code:
errors = 0 errors = 0
color = "green" color = "green"
@ -82,21 +82,23 @@ $for server in range(len(output)):
</div> </div>
<div class="canvas-container"> <div class="canvas-container">
<div class="canvas-graph"> <div class="canvas-graph">
<div class="canvas-header"><h2 style="margin: 0">Hosts status</h2></div> <div class="canvas-header">
<canvas id="canvas" width="400" height="400"></canvas> <h2 style="margin: 0">Hosts status</h2>
</div> </div>
</div> <canvas id="canvas" width="400" height="400"></canvas>
</div>
</div>
<div style="height: 10%; float:right"> <div style="height: 10%; float:right">
<br><br><br> <br><br><br>
Latest update: $now.day/$now.month/$now.year, $now.hour:$now.minute:$now.second Latest update: $now.day/$now.month/$now.year, $now.hour:$now.minute:$now.second
<br><br> <br><br>
<a href="/">Home</a> | <a href="/help">Help</a> <a href="/">Home</a> | <a href="/help">Help</a>
</div> </div>
</div> </div>
</body> </body>
<script src="static/monit-dashboard.js" type="text/javascript"></script> <script src="static/monit-dashboard.js" type="text/javascript"></script>