trustgraph/trustgraph-cli/scripts/tg-processor-state

63 lines
1.1 KiB
Text
Raw Normal View History

#!/usr/bin/env python3
"""
Dump out TrustGraph processor states.
"""
import requests
import argparse
import tabulate
default_metrics_url = "http://localhost:8088/api/metrics"
def dump_status(url):
url = f"{url}/query?query=processor_state%7Bprocessor_state%3D%22running%22%7D"
resp = requests.get(url)
obj = resp.json()
print(obj)
return
tbl = [
[
m["metric"]["job"],
"running" if int(m["value"][1]) > 0 else "down"
]
for m in obj["data"]["result"]
]
print(tabulate.tabulate(
tbl, tablefmt="pretty", headers=["processor", "state"],
stralign="left"
))
def main():
parser = argparse.ArgumentParser(
prog='tg-processor-state',
description=__doc__,
)
parser.add_argument(
'-m', '--metrics-url',
default=default_metrics_url,
help=f'Metrics URL (default: {default_metrics_url})',
)
args = parser.parse_args()
try:
dump_status(args.metrics_url)
except Exception as e:
print("Exception:", e, flush=True)
main()