1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
|