mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-20 02:31:02 +02:00
Provide mean to specify -p prometheus server
This commit is contained in:
parent
2e6be5cdce
commit
f921c015a3
1 changed files with 48 additions and 13 deletions
|
|
@ -1,24 +1,59 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
Dump out TrustGraph processor states.
|
||||||
|
"""
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
import argparse
|
||||||
import tabulate
|
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 = [
|
resp = requests.get(url)
|
||||||
[
|
|
||||||
m["metric"]["job"],
|
obj = resp.json()
|
||||||
"running" if int(m["value"][1]) > 0 else "down"
|
|
||||||
|
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(
|
print(tabulate.tabulate(
|
||||||
tbl, tablefmt="pretty", headers=["processor", "state"],
|
tbl, tablefmt="pretty", headers=["processor", "state"],
|
||||||
stralign="left"
|
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()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue