From a5d3b136291933808449ba58211107105ff87bb7 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Wed, 12 Mar 2025 20:49:44 +0100 Subject: [PATCH] changes --- debug-build-run.sh | 17 +---------------- load-debug-env | 15 +++++++++++++++ src/ntp_routes.py | 14 +++++++++++--- src/run.py | 2 +- 4 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 load-debug-env diff --git a/debug-build-run.sh b/debug-build-run.sh index 10aabb1..57b0643 100755 --- a/debug-build-run.sh +++ b/debug-build-run.sh @@ -7,22 +7,7 @@ IMAGE_NAME=numberimage docker build --progress=plain -t $IMAGE_NAME . -SECRETS=`mktemp` -gpg --decrypt --passphrase $GPG_PASSPHRASE --yes --batch --output $SECRETS ./deployment/secrets.asc -. $SECRETS -rm $SECRETS - -DB_NAMESPACE=database1 -DB_DEPLOYNAME=database - -REDIS_NAMESPACE=redis -REDIS_SERVICE_NAME=redis - -PGHOST=`kubectl get services $DB_DEPLOYNAME -n $DB_NAMESPACE -o jsonpath="{.status.loadBalancer.ingress[0].ip}"` -REDISHOST=`kubectl get services $REDIS_SERVICE_NAME -n $REDIS_NAMESPACE -o jsonpath="{.status.loadBalancer.ingress[0].ip}"` - -REDIS_URL=redis://$REDISHOST:6379/4 - +. load-debug-env docker run \ -it \ diff --git a/load-debug-env b/load-debug-env new file mode 100644 index 0000000..b4f4f5d --- /dev/null +++ b/load-debug-env @@ -0,0 +1,15 @@ +SECRETS=`mktemp` +gpg --decrypt --passphrase $GPG_PASSPHRASE --yes --batch --output $SECRETS ./deployment/secrets.asc +. $SECRETS +rm $SECRETS + +DB_NAMESPACE=database1 +DB_DEPLOYNAME=database + +REDIS_NAMESPACE=redis +REDIS_SERVICE_NAME=redis + +PGHOST=`kubectl get services $DB_DEPLOYNAME -n $DB_NAMESPACE -o jsonpath="{.status.loadBalancer.ingress[0].ip}"` +REDISHOST=`kubectl get services $REDIS_SERVICE_NAME -n $REDIS_NAMESPACE -o jsonpath="{.status.loadBalancer.ingress[0].ip}"` + +REDIS_URL=redis://$REDISHOST:6379/4 diff --git a/src/ntp_routes.py b/src/ntp_routes.py index b4310a7..8858510 100644 --- a/src/ntp_routes.py +++ b/src/ntp_routes.py @@ -4,6 +4,8 @@ import json import plotly.express as px import plotly.graph_objects as po import matplotlib.pyplot as plt +import matplotlib.dates as mdates +from matplotlib.ticker import ScalarFormatter import pandas as pd import psycopg import sqlalchemy @@ -131,13 +133,16 @@ def plot_png(): 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' + application = 'SNMP' and attributes->>'Label' = 'harrison' group by bucket, device order by bucket, device """ df = pd.read_sql(query, con=engine) + df['rootdisp'] = df['rootdisp'] / 1e6 - fig, ax1 = plt.subplots() + plot_date = df['bucket'].dt.date.iloc[0] if not df.empty else "Unknown Date" + + fig, ax1 = plt.subplots(figsize=(10,5)) ax1.plot(df['bucket'], df['rootdisp'], 'r-', label='Root Dispersion') ax1.set_xlabel('Time') @@ -150,9 +155,12 @@ def plot_png(): 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.suptitle(f"harrison - {plot_date}") fig.tight_layout() + ax1.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M')) + fig.autofmt_xdate(rotation=45) + img_io = io.BytesIO() plt.savefig(img_io, format='png') img_io.seek(0) diff --git a/src/run.py b/src/run.py index 6c3dfe1..270a45e 100644 --- a/src/run.py +++ b/src/run.py @@ -10,7 +10,7 @@ import ntp_routes if __name__ == '__main__': - app.run(port=8080) + app.run(host='0.0.0.0', port=8080) else: exposed_app = ProxyFix(app, x_for=1, x_host=1)