Skip to content

Commit

Permalink
Create lxc_autoscale_ui.py
Browse files Browse the repository at this point in the history
minimal simple ui to see scaling actions and full log
  • Loading branch information
fabriziosalmi authored Aug 23, 2024
1 parent 7101e5b commit 684f7cb
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lxc_autoscale/ui/lxc_autoscale_ui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from flask import Flask, render_template, jsonify
from flask_socketio import SocketIO, emit
import json
import os

app = Flask(__name__)
socketio = SocketIO(app)

json_log_file_path = '/var/log/lxc_autoscale.json'
log_file_path = '/var/log/lxc_autoscale.log'

@app.route('/')
def index():
"""Render the main dashboard page."""
return render_template('index.html')

@app.route('/get_scaling_log')
def get_scaling_log():
"""Return the scaling actions log as JSON."""
if os.path.exists(json_log_file_path):
with open(json_log_file_path, 'r') as f:
scaling_logs = [json.loads(line) for line in f if line.strip()]
return jsonify(scaling_logs)
return jsonify([]) # Return empty list if the file does not exist

@app.route('/get_full_log')
def get_full_log():
"""Return the full log content as a JSON response."""
if os.path.exists(log_file_path):
with open(log_file_path, 'r') as f:
full_log = f.read()
return jsonify({"log": full_log})
return jsonify({"log": ""}) # Return empty log if file does not exist

if __name__ == "__main__":
socketio.run(app, host='0.0.0.0', port=5000, debug=True)

0 comments on commit 684f7cb

Please sign in to comment.