54 lines
1.9 KiB
Python
Executable File
54 lines
1.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import argparse
|
|
import sys
|
|
import config
|
|
import cluster_aggregator
|
|
import output_formatter
|
|
import nomad_client
|
|
|
|
def parse_args():
|
|
parser = argparse.ArgumentParser(description="Monitor Navidrome LiteFS/Consul cluster status.")
|
|
parser.add_argument("--consul-url", help="Override Consul API URL (default from env or hardcoded)")
|
|
parser.add_argument("--no-color", action="store_true", help="Disable colorized output")
|
|
parser.add_argument("--restart", help="Restart the allocation on the specified node")
|
|
return parser.parse_args()
|
|
|
|
def main():
|
|
args = parse_args()
|
|
|
|
# Resolve Consul URL
|
|
consul_url = config.get_consul_url(args.consul_url)
|
|
|
|
# Handle restart if requested
|
|
if args.restart:
|
|
print(f"Attempting to restart allocation on node: {args.restart}...")
|
|
alloc_id = nomad_client.get_allocation_id(args.restart, "navidrome-litefs")
|
|
if alloc_id:
|
|
if nomad_client.restart_allocation(alloc_id):
|
|
print(f"Successfully sent restart signal to allocation {alloc_id}")
|
|
else:
|
|
print(f"Failed to restart allocation {alloc_id}")
|
|
else:
|
|
print(f"Could not find allocation for node {args.restart}")
|
|
print("-" * 30)
|
|
|
|
try:
|
|
# Fetch and aggregate data
|
|
cluster_data = cluster_aggregator.get_cluster_status(consul_url)
|
|
|
|
# Format and print output
|
|
print(output_formatter.format_summary(cluster_data, use_color=not args.no_color))
|
|
print("\n" + output_formatter.format_node_table(cluster_data["nodes"], use_color=not args.no_color))
|
|
|
|
# Diagnostics
|
|
diagnostics = output_formatter.format_diagnostics(cluster_data["nodes"], use_color=not args.no_color)
|
|
if diagnostics:
|
|
print(diagnostics)
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|