From 36be2db418e909d2f19b133a96b90d048a57e033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Sat, 1 Nov 2025 21:17:21 +0100 Subject: [PATCH] supervisord --- app.py | 80 +----------- templates/edit.html | 13 +- templates/home.html | 14 +- templates/index.html | 11 +- templates/logs.html | 12 +- templates/statistics.html | 265 ++++++++++++++++++++++++++++++++++++++ utils/stats_utils.py | 3 +- 7 files changed, 294 insertions(+), 104 deletions(-) create mode 100644 templates/statistics.html diff --git a/app.py b/app.py index a4b7f49..9bcb2f9 100644 --- a/app.py +++ b/app.py @@ -103,85 +103,7 @@ except Exception as e: def display_haproxy_stats(): haproxy_stats = fetch_haproxy_stats() parsed_stats = parse_haproxy_stats(haproxy_stats) - return render_template_string(''' - -
- - - - Home - Add Frontend&Backend - Edit HAProxy Config - Security Events - Statistics - HAProxy Stats -
- -
-

HAProxy Stats

-
- - - - - - - - - - - - - - {% for stat in stats %} - - - - - - - - - - {% endfor %} - -
Frontend NameServer Name4xx Errors5xx ErrorsBytes In (MB)Bytes Out (MB)Total Connections
{{ stat.frontend_name }}{{ stat.server_name }}{{ stat['4xx_errors'] }}{{ stat['5xx_errors'] }}{{ stat.bytes_in_mb }}{{ stat.bytes_out_mb }}{{ stat.conn_tot }}
-
-
- ''', stats=parsed_stats) - + return render_template('statistics.html', stats=parsed_stats) # Logs Route @app.route('/logs') diff --git a/templates/edit.html b/templates/edit.html index 3d8187f..3d86493 100644 --- a/templates/edit.html +++ b/templates/edit.html @@ -1,10 +1,11 @@ - + - Edit HAProxy Config - - - + + + HAProxy Edit/add + + + + + +
+ + + + Home + Add Frontend&Backend + Edit HAProxy Config + Security Events + Statistics + HAProxy Stats +
+ + +
+

+ HAProxy Statistics +

+ + {% if stats %} + +
+
+
+
+
Total Frontends
+

{{ stats|length }}

+
+
+
+
+
+
+
Total Connections
+

{{ stats|map(attribute='conn_tot')|sum }}

+
+
+
+
+
+
+
4xx Errors
+

{{ stats|map(attribute='4xx_errors')|sum }}

+
+
+
+
+
+
+
5xx Errors
+

{{ stats|map(attribute='5xx_errors')|sum }}

+
+
+
+
+ + +
+ + + + + + + + + + + + + + {% for stat in stats %} + + + + + + + + + + {% endfor %} + +
Frontend Name Server Name4xx Errors5xx ErrorsBytes In (MB)Bytes Out (MB)Total Connections
+ {{ stat.frontend_name }} + + {{ stat.server_name }} + + {% if stat['4xx_errors'] > 0 %} + {{ stat['4xx_errors'] }} + {% else %} + {{ stat['4xx_errors'] }} + {% endif %} + + {% if stat['5xx_errors'] > 0 %} + {{ stat['5xx_errors'] }} + {% else %} + {{ stat['5xx_errors'] }} + {% endif %} + {{ "%.2f"|format(stat.bytes_in_mb) }}{{ "%.2f"|format(stat.bytes_out_mb) }} + {{ stat.conn_tot }} +
+
+ {% else %} +
+ No statistics available +
+ {% endif %} +
+ + + + + + + diff --git a/utils/stats_utils.py b/utils/stats_utils.py index cac9f88..4d2ddb6 100644 --- a/utils/stats_utils.py +++ b/utils/stats_utils.py @@ -13,10 +13,9 @@ def fetch_haproxy_stats(): def parse_haproxy_stats(stats_data): data = [] - # Remove the '#' character from the header row header_row = stats_data.splitlines()[0].replace('# ', '') reader = csv.DictReader(stats_data.splitlines(), fieldnames=header_row.split(',')) - next(reader) # Skip the header row + next(reader) for row in reader: if row['svname'] != 'BACKEND': data.append({