#!/usr/bin/env python3 # -*- coding: utf-8 -*- """作业 8 · 步骤 2:启动 SLA Exporter(:8781)。""" from __future__ import annotations import sys from pathlib import Path import _bootstrap # noqa: F401 import _config as C from dify_api import Dify LOCAL_SH = ( Path(__file__).resolve().parents[2] / "scripts_bash_cursor" / "作业8_SLA监控大盘" / "作业8_启动_exporter.sh" ) def main() -> int: d = Dify(C.DIFY_EMAIL, C.DIFY_PASSWORD) try: d.login() d.sftp.put(str(LOCAL_SH), "/tmp/作业8_启动_exporter.sh") out, err = d.sh("FORCE_RESTART=1 bash /tmp/作业8_启动_exporter.sh") print(out or err) out2, _ = d.sh("curl -sf '%s/metrics' | grep ai_platform_availability_ratio" % C.SLA_EXPORTER_BASE) if "ai_platform_availability_ratio" not in (out2 or ""): print("[FAIL] Exporter 未输出指标") return 1 print("[OK] SLA Exporter %s/metrics" % C.SLA_EXPORTER_BASE) return 0 finally: d.close() if __name__ == "__main__": sys.exit(main())