File tree 1 file changed +36
-0
lines changed
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments