summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Metzger2020-06-25 13:54:07 +0200
committerLukas Metzger2020-06-25 13:54:07 +0200
commitf14e309e8b9cd2e25227df8af95e53162d5ce0b4 (patch)
treebc2d8227f9eb509969f9d8d8e0be94a78261e71d
parentAdded README documentation (diff)
downloadbwlp-statistics-f14e309e8b9cd2e25227df8af95e53162d5ce0b4.tar.gz
bwlp-statistics-f14e309e8b9cd2e25227df8af95e53162d5ce0b4.tar.xz
bwlp-statistics-f14e309e8b9cd2e25227df8af95e53162d5ce0b4.zip
Fixes for sattelites
-rw-r--r--dash/pages/satellites.py34
1 files changed, 30 insertions, 4 deletions
diff --git a/dash/pages/satellites.py b/dash/pages/satellites.py
index 232d8c7..0b02f5e 100644
--- a/dash/pages/satellites.py
+++ b/dash/pages/satellites.py
@@ -20,7 +20,9 @@ def layout():
id='satellites-table',
columns=[
{'id': 'ip', 'name': 'IP', 'type': 'text'},
+ {'id': 'date', 'name': 'Last Report', 'type': 'text'},
{'id': 'version', 'name': 'Version', 'type': 'text'},
+ {'id': 'numReports', 'name': '#Reports'},
{'id': 'cpuCount', 'name': '#CPUs'},
{'id': 'cpuModel', 'name': 'CPU Model'},
{'id': 'uptime', 'name': 'Uptime'},
@@ -33,29 +35,53 @@ def layout():
'textAlign': 'left'
}
],
- data=load_table()
+ sort_action='custom'
)])
])
])
])
-def load_table():
+
+@app.callback(
+ Output('satellites-table', 'data'),
+ [Input('satellites-table', "sort_by")])
+def load_table(sort):
+ print(sort)
dbcon = db.getConnection()
cursor = dbcon.cursor()
+ sortstr = "ORDER BY r.date DESC"
+ if sort != None and len(sort) > 0:
+ mappings = {
+ 'ip': 'r.ip',
+ 'date': 'r.date',
+ 'version': 'r.version',
+ 'numReports': 'n.numReports',
+ 'cpuCount': 's.cpuCount',
+ 'cpuModel': 's.cpuModel',
+ 'uptime': 's.uptime',
+ 'memPercent': 'memPercent',
+ 'swapPercent': 'swapPercent'
+ }
+ sortstr = 'ORDER BY ' + mappings[sort[0]['column_id']] + ' '
+ sortstr += 'ASC' if sort[0]['direction'] == 'asc' else ' DESC'
+ print(sortstr)
+
cursor.execute("""
SELECT
- r.ip, r.version, s.cpuCount, s.cpuModel, s.uptime,
+ r.ip, r.version, r.date, s.cpuCount, s.cpuModel, s.uptime, n.numReports,
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
- """)
+ LEFT OUTER JOIN (SELECT ip, COUNT(date) AS numReports FROM reports GROUP BY ip) n ON r.ip = n.ip
+ """ + sortstr)
data = cursor.fetchall()
for record in data:
record['uptime'] = humanize.naturaldelta(dt.timedelta(seconds=record['uptime']))
+ record['date'] = humanize.naturaldelta(dt.date.today() - record['date'])
db.closeConnection(dbcon)
return data