#!/usr/bin/env python3 # -*- coding: utf-8 -*- """作业 1 · 模拟「查询服务器状态」HTTP 工具(FastAPI)。 启动(207 上): pip3 install fastapi uvicorn -q uvicorn 作业1_server_status_api:app --host 0.0.0.0 --port 8777 或:bash scripts_bash_cursor/作业1_启动_server_status.sh """ from __future__ import annotations from fastapi import FastAPI app = FastAPI( title="Server Status API", version="1.0.0", description="Dify Agent 作业 1:模拟查询服务器 CPU / 内存 / GPU 状态", ) @app.get("/server/status", operation_id="getServerStatus", summary="查询服务器状态") def get_status(server_name: str) -> dict[str, str]: """根据 server_name 返回模拟监控指标(本服务不连真实监控)。""" return { "server": server_name, "cpu": "45%", "memory": "62%", "gpu_util": "78%", "gpu_memory": "18.2/24 GB", } @app.get("/health") def health() -> dict[str, str]: return {"status": "ok"} if __name__ == "__main__": import uvicorn uvicorn.run("作业1_server_status_api:app", host="0.0.0.0", port=8777, reload=False)