Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
730168ab61 | |||
8bef6d676c | |||
813265f8ee | |||
b47070cfc2 | |||
92ef3e6a85 | |||
a63776fb3f | |||
e24a29e94f | |||
b3c2c7794a | |||
7ff1b70098 |
@ -1,27 +1,27 @@
|
|||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
name: pv-stats
|
name: numbers
|
||||||
labels:
|
labels:
|
||||||
app: pv-stats
|
app: numbers
|
||||||
annotations:
|
annotations:
|
||||||
secret.reloader.stakater.com/reload: pv-stats
|
secret.reloader.stakater.com/reload: numbers
|
||||||
spec:
|
spec:
|
||||||
replicas: 1
|
replicas: 1
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app: pv-stats
|
app: numbers
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: pv-stats
|
app: numbers
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: pv-stats
|
- name: numbers
|
||||||
image: %IMAGE%
|
image: %IMAGE%
|
||||||
envFrom:
|
envFrom:
|
||||||
- secretRef:
|
- secretRef:
|
||||||
name: pv-stats
|
name: numbers
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
@ -29,11 +29,11 @@ spec:
|
|||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
metadata:
|
metadata:
|
||||||
name: pv-stats
|
name: numbers
|
||||||
spec:
|
spec:
|
||||||
type: ClusterIP
|
type: ClusterIP
|
||||||
selector:
|
selector:
|
||||||
app: pv-stats
|
app: numbers
|
||||||
ports:
|
ports:
|
||||||
- name: http
|
- name: http
|
||||||
targetPort: 8080
|
targetPort: 8080
|
||||||
@ -42,7 +42,7 @@ spec:
|
|||||||
apiVersion: networking.k8s.io/v1
|
apiVersion: networking.k8s.io/v1
|
||||||
kind: Ingress
|
kind: Ingress
|
||||||
metadata:
|
metadata:
|
||||||
name: pv-stats
|
name: numbers
|
||||||
annotations:
|
annotations:
|
||||||
cert-manager.io/cluster-issuer: letsencrypt-production-http
|
cert-manager.io/cluster-issuer: letsencrypt-production-http
|
||||||
spec:
|
spec:
|
||||||
@ -58,7 +58,7 @@ spec:
|
|||||||
pathType: Prefix
|
pathType: Prefix
|
||||||
backend:
|
backend:
|
||||||
service:
|
service:
|
||||||
name: pv-stats
|
name: numbers
|
||||||
port:
|
port:
|
||||||
number: 80
|
number: 80
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ kubectl create namespace $NAMESPACE \
|
|||||||
# rm $SECRETS_FILE
|
# rm $SECRETS_FILE
|
||||||
eval "`cat secrets.asc | /usr/local/bin/decrypt-secrets.sh`"
|
eval "`cat secrets.asc | /usr/local/bin/decrypt-secrets.sh`"
|
||||||
|
|
||||||
kubectl create secret generic pv-stats \
|
kubectl create secret generic numbers \
|
||||||
--dry-run=client \
|
--dry-run=client \
|
||||||
-o yaml \
|
-o yaml \
|
||||||
--save-config \
|
--save-config \
|
||||||
|
@ -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')
|
||||||
|
|
||||||
|
@ -12,9 +12,9 @@ from app import app
|
|||||||
from app import oidc
|
from app import oidc
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/pvstats')
|
||||||
@oidc.require_login
|
@oidc.require_login
|
||||||
def index():
|
def pvstats():
|
||||||
try:
|
try:
|
||||||
stepX_time = time.time()
|
stepX_time = time.time()
|
||||||
dbh = psycopg.connect()
|
dbh = psycopg.connect()
|
||||||
|
@ -38,3 +38,6 @@ tzdata==2025.1
|
|||||||
urllib3==2.3.0
|
urllib3==2.3.0
|
||||||
Werkzeug==3.1.3
|
Werkzeug==3.1.3
|
||||||
zipp==3.21.0
|
zipp==3.21.0
|
||||||
|
pillow==11.1.0
|
||||||
|
matplotlib==3.10.1
|
||||||
|
|
||||||
|
24
src/routes.py
Normal file
24
src/routes.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
from flask import abort, Response
|
||||||
|
from PIL import Image, ImageDraw
|
||||||
|
import io
|
||||||
|
from app import app
|
||||||
|
from app import oidc
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def index():
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
@app.route('/generate_image')
|
||||||
|
def generate_image():
|
||||||
|
img = Image.new('RGB', (200, 100), color=(255, 255, 255))
|
||||||
|
|
||||||
|
draw = ImageDraw.Draw(img)
|
||||||
|
draw.text((50, 40), "Hello, Flask!", fill=(0, 0, 0)) # Schwarzer Text
|
||||||
|
|
||||||
|
img_io = io.BytesIO()
|
||||||
|
img.save(img_io, 'PNG')
|
||||||
|
img_io.seek(0) # Zeiger zurücksetzen
|
||||||
|
|
||||||
|
return Response(img_io, mimetype='image/png')
|
||||||
|
|
@ -3,6 +3,7 @@ from loguru import logger
|
|||||||
|
|
||||||
from app import app
|
from app import app
|
||||||
|
|
||||||
|
import routes
|
||||||
import debug_routes
|
import debug_routes
|
||||||
import pv_routes
|
import pv_routes
|
||||||
import ntp_routes
|
import ntp_routes
|
||||||
|
Reference in New Issue
Block a user