atlasbot: load metrics index and answer in rooms
This commit is contained in:
parent
33b5e2b678
commit
0ac0f920ca
@ -188,7 +188,7 @@ def _load_json_file(path: str) -> Any | None:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def load_kb():
|
def load_kb():
|
||||||
global KB, _HOST_INDEX, _NAME_INDEX
|
global KB, _HOST_INDEX, _NAME_INDEX, _METRIC_INDEX
|
||||||
global _NODE_CLASS_INDEX, _NODE_CLASS_RPI4, _NODE_CLASS_RPI5, _NODE_CLASS_AMD64, _NODE_CLASS_JETSON
|
global _NODE_CLASS_INDEX, _NODE_CLASS_RPI4, _NODE_CLASS_RPI5, _NODE_CLASS_AMD64, _NODE_CLASS_JETSON
|
||||||
global _NODE_CLASS_EXTERNAL, _NODE_CLASS_NON_RPI
|
global _NODE_CLASS_EXTERNAL, _NODE_CLASS_NON_RPI
|
||||||
if not KB_DIR:
|
if not KB_DIR:
|
||||||
@ -414,6 +414,8 @@ def metrics_query_context(prompt: str, *, allow_tools: bool) -> tuple[str, str]:
|
|||||||
if not matches:
|
if not matches:
|
||||||
return "", ""
|
return "", ""
|
||||||
entry = matches[0]
|
entry = matches[0]
|
||||||
|
dashboard = entry.get("dashboard") or "dashboard"
|
||||||
|
panel = entry.get("panel_title") or "panel"
|
||||||
exprs = entry.get("exprs") if isinstance(entry.get("exprs"), list) else []
|
exprs = entry.get("exprs") if isinstance(entry.get("exprs"), list) else []
|
||||||
if not exprs:
|
if not exprs:
|
||||||
return "", ""
|
return "", ""
|
||||||
@ -424,9 +426,7 @@ def metrics_query_context(prompt: str, *, allow_tools: bool) -> tuple[str, str]:
|
|||||||
if rendered:
|
if rendered:
|
||||||
rendered_parts.append(rendered)
|
rendered_parts.append(rendered)
|
||||||
if not rendered_parts:
|
if not rendered_parts:
|
||||||
return "", ""
|
return "", f"{panel}: matched dashboard panel but VictoriaMetrics did not return data."
|
||||||
dashboard = entry.get("dashboard") or "dashboard"
|
|
||||||
panel = entry.get("panel_title") or "panel"
|
|
||||||
summary = "\n".join(rendered_parts)
|
summary = "\n".join(rendered_parts)
|
||||||
context = f"Metrics (from {dashboard} / {panel}):\n{summary}"
|
context = f"Metrics (from {dashboard} / {panel}):\n{summary}"
|
||||||
fallback = f"{panel}: {summary}"
|
fallback = f"{panel}: {summary}"
|
||||||
@ -998,8 +998,9 @@ def sync_loop(token: str, room_id: str):
|
|||||||
send_msg(token, rid, names_summary)
|
send_msg(token, rid, names_summary)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Only do live cluster/metrics introspection in DMs.
|
# Only do live cluster introspection in DMs; metrics can be answered when mentioned.
|
||||||
allow_tools = is_dm
|
allow_tools = is_dm
|
||||||
|
allow_metrics = is_dm or mentioned
|
||||||
|
|
||||||
promql = ""
|
promql = ""
|
||||||
if allow_tools:
|
if allow_tools:
|
||||||
@ -1024,7 +1025,7 @@ def sync_loop(token: str, room_id: str):
|
|||||||
rendered = vm_render_result(res, limit=15) or "(no results)"
|
rendered = vm_render_result(res, limit=15) or "(no results)"
|
||||||
extra = "VictoriaMetrics (PromQL result):\n" + rendered
|
extra = "VictoriaMetrics (PromQL result):\n" + rendered
|
||||||
context = (context + "\n\n" + extra).strip() if context else extra
|
context = (context + "\n\n" + extra).strip() if context else extra
|
||||||
metrics_context, metrics_fallback = metrics_query_context(body, allow_tools=allow_tools)
|
metrics_context, metrics_fallback = metrics_query_context(body, allow_tools=allow_metrics)
|
||||||
if metrics_context:
|
if metrics_context:
|
||||||
context = (context + "\n\n" + metrics_context).strip() if context else metrics_context
|
context = (context + "\n\n" + metrics_context).strip() if context else metrics_context
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user