conductor(checkpoint): Checkpoint end of Phase 3
This commit is contained in:
48
scripts/cluster_status/cluster_aggregator.py
Normal file
48
scripts/cluster_status/cluster_aggregator.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import consul_client
|
||||
import litefs_client
|
||||
|
||||
def get_cluster_status(consul_url):
|
||||
"""
|
||||
Aggregates cluster data from Consul and LiteFS.
|
||||
"""
|
||||
consul_nodes = consul_client.get_cluster_services(consul_url)
|
||||
aggregated_nodes = []
|
||||
|
||||
is_healthy = True
|
||||
primary_count = 0
|
||||
|
||||
for node in consul_nodes:
|
||||
litefs_status = litefs_client.get_node_status(node["address"])
|
||||
|
||||
# Merge data
|
||||
node_data = {
|
||||
**node,
|
||||
"litefs_primary": litefs_status.get("is_primary", False),
|
||||
"uptime": litefs_status.get("uptime", "N/A"),
|
||||
"advertise_url": litefs_status.get("advertise_url", ""),
|
||||
"replication_lag": litefs_status.get("replication_lag", "N/A"),
|
||||
"litefs_error": litefs_status.get("error", None)
|
||||
}
|
||||
|
||||
if node["status"] != "passing":
|
||||
is_healthy = False
|
||||
|
||||
if node_data["litefs_primary"]:
|
||||
primary_count += 1
|
||||
|
||||
aggregated_nodes.append(node_data)
|
||||
|
||||
# Final health check
|
||||
health = "Healthy"
|
||||
if not is_healthy:
|
||||
health = "Unhealthy"
|
||||
elif primary_count == 0:
|
||||
health = "No Primary Detected"
|
||||
elif primary_count > 1:
|
||||
health = "Split Brain Detected (Multiple Primaries)"
|
||||
|
||||
return {
|
||||
"health": health,
|
||||
"nodes": aggregated_nodes,
|
||||
"primary_count": primary_count
|
||||
}
|
||||
Reference in New Issue
Block a user