Fix/processor state specify prom (#93)

* Provide mean to specify -p prometheus server
* Bump version
This commit is contained in:
cybermaggedon 2024-10-01 22:14:28 +01:00 committed by GitHub
parent 2e6be5cdce
commit 14672f7f0e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 399 additions and 364 deletions

View file

@ -1,24 +1,59 @@
#!/usr/bin/env python3
"""
Dump out TrustGraph processor states.
"""
import requests
import argparse
import tabulate
url = 'http://localhost:9090/api/v1/query?query=processor_state%7Bprocessor_state%3D%22running%22%7D'
default_prometheus_url = "http://localhost:9090"
resp = requests.get(url)
def dump_status(prom):
obj = resp.json()
url = f"{prom}/api/v1/query?query=processor_state%7Bprocessor_state%3D%22running%22%7D"
tbl = [
[
m["metric"]["job"],
"running" if int(m["value"][1]) > 0 else "down"
resp = requests.get(url)
obj = resp.json()
tbl = [
[
m["metric"]["job"],
"running" if int(m["value"][1]) > 0 else "down"
]
for m in obj["data"]["result"]
]
for m in obj["data"]["result"]
]
print(tabulate.tabulate(
tbl, tablefmt="pretty", headers=["processor", "state"],
stralign="left"
))
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(
'-p', '--prometheus-url',
default=default_prometheus_url,
help=f'Prometheus URL (default: {default_prometheus_url})',
)
args = parser.parse_args()
try:
dump_status(args.prometheus_url)
except Exception as e:
print("Exception:", e, flush=True)
main()