Commit 76596cde authored by Kollosos's avatar Kollosos
Browse files

Moving servermonitor standalone application to archive file, updating requirements files

parent e5e80320
......@@ -22,9 +22,13 @@ Flask-Compress==1.10.1
Flask-HTTPAuth==4.4.0
Flask-Session==0.4.0
Flask-Sessions==0.1.5
flask-sock==0.4.0
Flask-SQLAlchemy==2.5.1
flower==1.0.0
future==0.18.2
greenlet==1.1.2
gunicorn==20.1.0
h11==0.12.0
humanize==3.11.0
idna==3.2
itsdangerous==2.0.1
......@@ -45,13 +49,16 @@ pytz==2021.1
redis==3.5.3
requests==2.26.0
scipy==1.7.1
simple-websocket==0.4.0
six==1.16.0
SQLAlchemy==1.4.27
style==1.1.0
tenacity==8.0.1
tornado==6.1
Turbo-Flask==0.7.0
update==0.0.1
urllib3==1.26.6
vine==5.0.0
wcwidth==0.2.5
Werkzeug==2.0.1
wsproto==1.0.0
# -*- coding: utf-8 -*-
#
# ..####....####...##..##...####...######..######..##......##.......####...######..######...####...##..##.
# .##..##..##..##..###.##..##........##....##......##......##......##..##....##......##....##..##..###.##.
# .##......##..##..##.###...####.....##....####....##......##......######....##......##....##..##..##.###.
# .##..##..##..##..##..##......##....##....##......##......##......##..##....##......##....##..##..##..##.
# ..####....####...##..##...####.....##....######..######..######..##..##....##....######...####...##..##.
#
# An open-source web application for unsupervised systematic trend detection in high-resolution mass spectrometry data
# Copyright (C) 2021 Dane Letourneau
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
# version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details. You should have received a copy of the GNU General Public License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
"""
MONITORING APPLICATION FOR CONSTELLATION SERVERAPP (BACKEND)
@author: Dane Letourneau (letournd@hu-berlin.de)
Version: 18.11.2021 v4.69
"""
# Import the global functions and variables
import globals_serverapp as gv
# Import basic python functions we need
import requests
import pandas as pd
import time
import json
import string
from json.decoder import JSONDecodeError
# Import the dash and flask functionalities
import dash
import dash_bootstrap_components as dbc
from dash import dcc, html, Input, Output, State, no_update
from dash.exceptions import PreventUpdate
from flask import Flask
# Define the Flask app
servermonitor = Flask(__name__)
servermonitor.secret_key = gv.superpass
backserver = '141.20.75.41'
# DASH APP CONFIGURATION
app = dash.Dash(__name__, update_title=None, external_stylesheets=[dbc.themes.CERULEAN], server=servermonitor)
app.title = 'Constellation'
# Here the graphical user interface (GUI) of the web application is defined
gui = html.Div([
# BANNER
html.Div([
# Logo, title and version
html.Img(src='assets/logo7.jpg', style=gv.styles['logo']),
html.H3(children=html.B('Constellation Server Status'),
style={'display': 'inline-block', 'padding': '0px 0px 0px 10px'}),
html.P([
html.I('Server status: '),
html.B(id='ping', children=[]),
html.I('. Server running at ' + backserver),
], style={'fontSize': '14px'}),
html.P([
html.I('Version: '),
html.I(id='version', children=[]),
html.I(', last updated '),
html.I(id='date', children=[]),
], style={'fontSize': '14px'}),
], style={'width': '100%', 'padding': '10px 10px 10px 20px'}),
# MONITORING PANEL
html.Div([
dcc.Interval(id='updateme', interval=5000),
html.B('Active users'),
html.P([
html.I('Currently accessed by: '),
html.P(id='activeusers', children=[]),
]),
html.Hr(style=gv.styles['hline']),
html.B('CPU load averages'),
html.P([
html.I('1 min: '),
html.B(id='load1', children=[]),
]),
html.P([
html.I('5 min: '),
html.B(id='load5', children=[]),
]),
html.P([
html.I('15 min: '),
html.B(id='load15', children=[]),
]),
], style=gv.styles['subpanel']),
# END OF DASH APP LAYOUT
], style=gv.styles['mainpanel'])
app.layout = gui
app.validation_layout = gui
# APP CALLBACKS
@app.callback(
[Output('ping', 'children'),
Output('version', 'children'),
Output('date', 'children'),
Output('activeusers', 'children'),
Output('load1', 'children'),
Output('load5', 'children'),
Output('load15', 'children')],
Input('updateme', 'n_intervals'))
def serverupdates(n_intervals):
r = requests.get(url='http://' + backserver + '/serverupdates', auth=('servermonitor', 'T1k$LQn37'), timeout=5)
if gv.ping():
status = 'ACTIVE'
else:
status = 'INACTIVE'
try:
data = r.json()
version = data['version']
date = data['date']
activeusers = data['activeusers']
load1 = data['load1']
load5 = data['load5']
load15 = data['load15']
except JSONDecodeError:
return status, no_update, no_update, no_update, 0, 0, 0
activeusersout = ''
x = 1
while x <= len(activeusers):
activeusersout += 'User ' + str(x) + ' (' + str(activeusers[x-1])
if x == len(activeusers):
activeusersout += ')'
else:
activeusersout += '), '
x += 1
return status, version, date, activeusersout, load1, load5, load15
# RUN THE APP
if __name__ == '__main__':
app.run_server(debug=False, host='0.0.0.0', port=8050)
from servermonitor import servermonitor
if __name__ == "__main__":
servermonitor.run()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment