Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
730168ab61 | |||
8bef6d676c | |||
813265f8ee | |||
b47070cfc2 | |||
92ef3e6a85 |
@ -3,10 +3,12 @@ from loguru import logger
|
|||||||
import json
|
import json
|
||||||
import plotly.express as px
|
import plotly.express as px
|
||||||
import plotly.graph_objects as po
|
import plotly.graph_objects as po
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import psycopg
|
import psycopg
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
import time
|
import time
|
||||||
|
import io
|
||||||
|
|
||||||
from app import app
|
from app import app
|
||||||
from app import oidc
|
from app import oidc
|
||||||
@ -118,3 +120,43 @@ def ntpserver():
|
|||||||
dbh.close()
|
dbh.close()
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/plot.png')
|
||||||
|
def plot_png():
|
||||||
|
dbh = psycopg.connect()
|
||||||
|
engine = sqlalchemy.create_engine("postgresql+psycopg://", creator=lambda: dbh)
|
||||||
|
query = """
|
||||||
|
select time_bucket('5 minutes', time) as bucket,
|
||||||
|
device,
|
||||||
|
avg(cast(values->'rootdisp'->>'value' as float)) as rootdisp,
|
||||||
|
max(cast(values->'stratum'->>'value' as int)) as stratum
|
||||||
|
from measurements
|
||||||
|
where time >= date_trunc('day', now()) AND time < date_trunc('day', now()) + '1 day'::interval and
|
||||||
|
application = 'TSM' and attributes->>'Label' = 'david'
|
||||||
|
group by bucket, device
|
||||||
|
order by bucket, device
|
||||||
|
"""
|
||||||
|
df = pd.read_sql(query, con=engine)
|
||||||
|
|
||||||
|
fig, ax1 = plt.subplots()
|
||||||
|
|
||||||
|
ax1.plot(df['bucket'], df['rootdisp'], 'r-', label='Root Dispersion')
|
||||||
|
ax1.set_xlabel('Time')
|
||||||
|
ax1.set_ylabel('Root Dispersion (ms)', color='r')
|
||||||
|
ax1.tick_params(axis='y', labelcolor='r')
|
||||||
|
|
||||||
|
ax2 = ax1.twinx()
|
||||||
|
ax2.plot(df['bucket'], df['stratum'], 'b-', label='Stratum')
|
||||||
|
ax2.set_ylabel('Stratum', color='b')
|
||||||
|
ax2.tick_params(axis='y', labelcolor='b')
|
||||||
|
ax2.set_yticks(range(int(df['stratum'].min()), int(df['stratum'].max()) + 1))
|
||||||
|
|
||||||
|
fig.suptitle('NTP Server Numbers')
|
||||||
|
fig.tight_layout()
|
||||||
|
|
||||||
|
img_io = io.BytesIO()
|
||||||
|
plt.savefig(img_io, format='png')
|
||||||
|
img_io.seek(0)
|
||||||
|
plt.close(fig)
|
||||||
|
|
||||||
|
return Response(img_io, mimetype='image/png')
|
||||||
|
|
||||||
|
@ -39,3 +39,5 @@ urllib3==2.3.0
|
|||||||
Werkzeug==3.1.3
|
Werkzeug==3.1.3
|
||||||
zipp==3.21.0
|
zipp==3.21.0
|
||||||
pillow==11.1.0
|
pillow==11.1.0
|
||||||
|
matplotlib==3.10.1
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user