Monitoring-Endpunkt hinzugefügt
This commit is contained in:
24
app.py
24
app.py
@@ -1,8 +1,11 @@
|
||||
from flask import Flask, render_template, request, redirect, url_for, session, abort
|
||||
from flask import Flask, render_template, request, redirect, url_for, session, abort, jsonify
|
||||
from datetime import datetime, timedelta
|
||||
import numpy as np
|
||||
from dateutil.relativedelta import relativedelta
|
||||
import os
|
||||
import time
|
||||
|
||||
app_start_time = time.time()
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = os.environ.get('SECRET_KEY', 'dev-key')
|
||||
@@ -183,5 +186,24 @@ def stats():
|
||||
return render_template('stats_dashboard.html', pageviews=pageviews, func_counts=func_counts, impressions_per_day=impressions_per_day)
|
||||
|
||||
|
||||
@app.route('/monitor')
|
||||
def monitor():
|
||||
log_path = os.path.join('log', 'pageviews.log')
|
||||
pageviews = 0
|
||||
if os.path.exists(log_path):
|
||||
with open(log_path, encoding='utf-8') as f:
|
||||
for line in f:
|
||||
if 'PAGEVIEW' in line:
|
||||
pageviews += 1
|
||||
uptime = int(time.time() - app_start_time)
|
||||
return jsonify({
|
||||
"status": "ok",
|
||||
"message": "App running",
|
||||
"time": datetime.now().isoformat(),
|
||||
"uptime_seconds": uptime,
|
||||
"pageviews_last_7_days": pageviews
|
||||
})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host="0.0.0.0")
|
Reference in New Issue
Block a user