forked from mtusi2026/mtusi2026lab6
Собрать наблюдаемый стенд, чтобы причину деградации API и worker было видно по метрикам, логам и трассам.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
"""Print a short, secret-free snapshot of metrics, one log, and recent traces."""
|
||||
|
||||
import json
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
|
||||
def get(url):
|
||||
with urllib.request.urlopen(url, timeout=10) as response:
|
||||
return json.load(response)
|
||||
|
||||
|
||||
def query(expr):
|
||||
return get("http://127.0.0.1:9090/api/v1/query?query=" + urllib.parse.quote(expr))["data"]["result"]
|
||||
|
||||
|
||||
names = get("http://127.0.0.1:9090/api/v1/label/__name__/values")["data"]
|
||||
app = [name for name in names if name.startswith("http_") or name.startswith("messenger_")]
|
||||
print("NAMES")
|
||||
print("\n".join(app))
|
||||
for expr in (
|
||||
"messenger_jobs_total",
|
||||
"messenger_queue_depth",
|
||||
"messenger_db_up",
|
||||
"messenger_worker_busy",
|
||||
"messenger_worker_consumers",
|
||||
):
|
||||
print(expr, query(expr))
|
||||
|
||||
log_query = '{service_name="messenger-worker"}'
|
||||
logs = get(
|
||||
"http://127.0.0.1:3100/loki/api/v1/query_range?query="
|
||||
+ urllib.parse.quote(log_query)
|
||||
+ "&limit=2"
|
||||
)
|
||||
streams = logs["data"]["result"]
|
||||
print("LOG_STREAMS", len(streams))
|
||||
if streams:
|
||||
print(streams[0]["values"][-1][1][:600])
|
||||
|
||||
tempo_query = '{resource.service.name="messenger-api"}'
|
||||
traces = get(
|
||||
"http://127.0.0.1:3200/api/search?q=" + urllib.parse.quote(tempo_query) + "&limit=5"
|
||||
)
|
||||
print("TRACES")
|
||||
for item in traces.get("traces", []):
|
||||
print(item.get("rootServiceName"), item.get("rootTraceName"), item.get("traceID"), item.get("durationMs"))
|
||||
Reference in New Issue
Block a user