Skip to content

Commit 684f7cb

Browse files
Create lxc_autoscale_ui.py
minimal simple ui to see scaling actions and full log
1 parent 7101e5b commit 684f7cb

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

lxc_autoscale/ui/lxc_autoscale_ui.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from flask import Flask, render_template, jsonify
2+
from flask_socketio import SocketIO, emit
3+
import json
4+
import os
5+
6+
app = Flask(__name__)
7+
socketio = SocketIO(app)
8+
9+
json_log_file_path = '/var/log/lxc_autoscale.json'
10+
log_file_path = '/var/log/lxc_autoscale.log'
11+
12+
@app.route('/')
13+
def index():
14+
"""Render the main dashboard page."""
15+
return render_template('index.html')
16+
17+
@app.route('/get_scaling_log')
18+
def get_scaling_log():
19+
"""Return the scaling actions log as JSON."""
20+
if os.path.exists(json_log_file_path):
21+
with open(json_log_file_path, 'r') as f:
22+
scaling_logs = [json.loads(line) for line in f if line.strip()]
23+
return jsonify(scaling_logs)
24+
return jsonify([]) # Return empty list if the file does not exist
25+
26+
@app.route('/get_full_log')
27+
def get_full_log():
28+
"""Return the full log content as a JSON response."""
29+
if os.path.exists(log_file_path):
30+
with open(log_file_path, 'r') as f:
31+
full_log = f.read()
32+
return jsonify({"log": full_log})
33+
return jsonify({"log": ""}) # Return empty log if file does not exist
34+
35+
if __name__ == "__main__":
36+
socketio.run(app, host='0.0.0.0', port=5000, debug=True)

0 commit comments

Comments
 (0)