diff options
author | Lukas Metzger | 2020-06-10 20:43:25 +0200 |
---|---|---|
committer | Lukas Metzger | 2020-06-10 20:43:25 +0200 |
commit | 8421aa6a31b8b41a203b4550c0bc01cc3629f68b (patch) | |
tree | fb7953e192d42743677b477af5cecf16e52e6923 /pages/satellites.py | |
parent | Moved import files to subfolder (diff) | |
parent | Added minimal date for locations, machines and vms (diff) | |
download | bwlp-statistics-8421aa6a31b8b41a203b4550c0bc01cc3629f68b.tar.gz bwlp-statistics-8421aa6a31b8b41a203b4550c0bc01cc3629f68b.tar.xz bwlp-statistics-8421aa6a31b8b41a203b4550c0bc01cc3629f68b.zip |
Merge remote-tracking branch 'dash/master'
Diffstat (limited to 'pages/satellites.py')
-rw-r--r-- | pages/satellites.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/pages/satellites.py b/pages/satellites.py new file mode 100644 index 0000000..232d8c7 --- /dev/null +++ b/pages/satellites.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +import dash_core_components as dcc +import dash_html_components as html +import dash_table as dtbl +import dash_bootstrap_components as dbc +from dash.dependencies import Input, Output + +import humanize +import datetime as dt + +import db +from app import app + +def layout(): + return dbc.Container(fluid=True, children=[ + dbc.Row([ + dbc.Col([ + html.Div(className='table-responsive-lg', children=[dtbl.DataTable( + id='satellites-table', + columns=[ + {'id': 'ip', 'name': 'IP', 'type': 'text'}, + {'id': 'version', 'name': 'Version', 'type': 'text'}, + {'id': 'cpuCount', 'name': '#CPUs'}, + {'id': 'cpuModel', 'name': 'CPU Model'}, + {'id': 'uptime', 'name': 'Uptime'}, + {'id': 'memPercent', 'name': 'Mem Usage'}, + {'id': 'swapPercent', 'name': 'Swap Usage'} + ], + style_cell_conditional=[ + { + 'if': {'column_type': 'text'}, + 'textAlign': 'left' + } + ], + data=load_table() + )]) + ]) + ]) + ]) + +def load_table(): + dbcon = db.getConnection() + cursor = dbcon.cursor() + + cursor.execute(""" + SELECT + r.ip, r.version, s.cpuCount, s.cpuModel, s.uptime, + ROUND(100 - s.memFree / s.memTotal * 100, 1) as memPercent, + ROUND(s.swapUsed / s.swapTotal * 100, 1) as swapPercent + FROM reports_newest r + LEFT OUTER JOIN server s ON r.id = s.report + """) + + data = cursor.fetchall() + + for record in data: + record['uptime'] = humanize.naturaldelta(dt.timedelta(seconds=record['uptime'])) + + db.closeConnection(dbcon) + return data |