new options

This commit is contained in:
Mateusz Gruszczyński
2025-11-03 10:18:10 +01:00
parent acef7eb610
commit df70118653
5 changed files with 355 additions and 139 deletions

View File

@@ -13,8 +13,7 @@ def fetch_haproxy_stats():
def parse_haproxy_stats(stats_data):
data = []
# Skip empty lines and get header
lines = [line for line in stats_data.splitlines() if line.strip()]
if not lines:
return data
@@ -23,17 +22,14 @@ def parse_haproxy_stats(stats_data):
# Parse CSV
reader = csv.DictReader(lines, fieldnames=header_row.split(','))
next(reader) # Skip header
next(reader)
for row in reader:
# Only process servers, skip BACKEND summary rows
if row.get('svname') == 'BACKEND':
continue
# Strip whitespace from values
row = {k: v.strip() if isinstance(v, str) else v for k, v in row.items()}
# Safe conversion to int/float
try:
conn_tot = int(row.get('conn_tot', 0) or 0)
except (ValueError, TypeError):
@@ -51,13 +47,13 @@ def parse_haproxy_stats(stats_data):
try:
bin_bytes = float(row.get('bin', 0) or 0)
bytes_in_mb = bin_bytes / (1024 * 1024) # ✅ FLOAT, nie string!
bytes_in_mb = bin_bytes / (1024 * 1024)
except (ValueError, TypeError):
bytes_in_mb = 0.0
try:
bout_bytes = float(row.get('bout', 0) or 0)
bytes_out_mb = bout_bytes / (1024 * 1024) # ✅ FLOAT, nie string!
bytes_out_mb = bout_bytes / (1024 * 1024)
except (ValueError, TypeError):
bytes_out_mb = 0.0
@@ -66,9 +62,9 @@ def parse_haproxy_stats(stats_data):
'server_name': row.get('svname', 'Unknown'),
'4xx_errors': hrsp_4xx,
'5xx_errors': hrsp_5xx,
'bytes_in_mb': bytes_in_mb, # ✅ Float
'bytes_out_mb': bytes_out_mb, # ✅ Float
'conn_tot': conn_tot, # ✅ Int
'bytes_in_mb': bytes_in_mb,
'bytes_out_mb': bytes_out_mb,
'conn_tot': conn_tot,
})
return data