from ntpserver_added
This commit is contained in:
parent
6af509c2f6
commit
4ec9690981
24
src/run.py
24
src/run.py
@ -1,4 +1,4 @@
|
|||||||
from flask import Flask, session, g, render_template_string, Response
|
from flask import Flask, session, g, render_template_string
|
||||||
from flask_session import Session
|
from flask_session import Session
|
||||||
from flask_oidc import OpenIDConnect
|
from flask_oidc import OpenIDConnect
|
||||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||||
@ -8,8 +8,6 @@ import json
|
|||||||
import os
|
import os
|
||||||
import plotly.express as px
|
import plotly.express as px
|
||||||
import plotly.graph_objects as po
|
import plotly.graph_objects as po
|
||||||
import plotly.io as pio
|
|
||||||
import io
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import psycopg
|
import psycopg
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
@ -161,7 +159,7 @@ def ntpserver():
|
|||||||
select time_bucket('5 minutes', time) as bucket,
|
select time_bucket('5 minutes', time) as bucket,
|
||||||
device,
|
device,
|
||||||
avg(cast(values->'rootdisp'->>'value' as float)) as rootdisp,
|
avg(cast(values->'rootdisp'->>'value' as float)) as rootdisp,
|
||||||
max(cast(values->'stratum'->>'value' as int)) as stratum
|
avg(cast(values->'stratum'->>'value' as int)) as stratum
|
||||||
from measurements
|
from measurements
|
||||||
where time >= date_trunc('day', now()) AND time < date_trunc('day', now()) + '1 day'::interval and
|
where time >= date_trunc('day', now()) AND time < date_trunc('day', now()) + '1 day'::interval and
|
||||||
application = 'TSM' and attributes->>'Label' = 'david'
|
application = 'TSM' and attributes->>'Label' = 'david'
|
||||||
@ -176,6 +174,8 @@ def ntpserver():
|
|||||||
fig.add_trace(po.Scatter(x=df['bucket'], y=df['stratum'], mode='lines', name='Stratum', yaxis='y2', line=dict(color='blue')))
|
fig.add_trace(po.Scatter(x=df['bucket'], y=df['stratum'], mode='lines', name='Stratum', yaxis='y2', line=dict(color='blue')))
|
||||||
|
|
||||||
fig.update_layout(
|
fig.update_layout(
|
||||||
|
title='NTP Server Numbers',
|
||||||
|
|
||||||
# Linke Y-Achse
|
# Linke Y-Achse
|
||||||
yaxis=dict(
|
yaxis=dict(
|
||||||
title='Root Dispersion'
|
title='Root Dispersion'
|
||||||
@ -193,9 +193,19 @@ def ntpserver():
|
|||||||
legend=dict(x=0.05, y=1) # Position der Legende
|
legend=dict(x=0.05, y=1) # Position der Legende
|
||||||
)
|
)
|
||||||
|
|
||||||
img = fig.to_image(format='png')
|
|
||||||
return Response(img, mimetype='image/png')
|
|
||||||
|
|
||||||
|
graph_html = fig.to_html(full_html=False, default_height='30%')
|
||||||
|
|
||||||
|
return render_template_string(f"""
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>NTP Server Numbers</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{graph_html}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
""")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(f"Error when querying NTP server values: {e}")
|
raise Exception(f"Error when querying NTP server values: {e}")
|
||||||
finally:
|
finally:
|
||||||
@ -208,7 +218,7 @@ def ntpserver():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host="0.0.0.0", port=8080)
|
app.run(port=8080)
|
||||||
else:
|
else:
|
||||||
exposed_app = ProxyFix(app, x_for=1, x_host=1)
|
exposed_app = ProxyFix(app, x_for=1, x_host=1)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user