周期性线程监控 API#
本文描述了在 LMCache 中引入的周期性线程监控 API 功能。
概述#
周期性线程监控 API 提供 HTTP 端点,以监控和检查在 LMCache 系统中运行的所有周期性后台线程的状态。这对于调试、健康检查和操作监控非常有用。
API 端点#
在内部 API 服务器下提供三个 API 端点:
GET /periodic-threads#
返回所有注册的周期线程的信息。
查询参数:
参数 |
默认 |
描述 |
|---|---|---|
|
(无) |
按线程级别过滤( |
|
|
仅显示正在运行的线程 |
|
|
仅显示活动线程 |
响应示例:
{
"summary": {
"total_count": 5,
"running_count": 3,
"active_count": 3,
"by_level": {
"critical": {"total": 1, "running": 1, "active": 1},
"high": {"total": 2, "running": 1, "active": 1},
"medium": {"total": 1, "running": 1, "active": 1},
"low": {"total": 1, "running": 0, "active": 0}
}
},
"threads": [
{
"name": "pin_monitor",
"level": "high",
"is_running": true,
"is_active": true,
"last_run_time": 1706000000.0,
"last_run_ago": "2.5s"
}
]
}
GET /periodic-threads/{thread_name}#
返回有关特定周期线程的详细信息。
响应示例:
{
"name": "pin_monitor",
"level": "high",
"is_running": true,
"is_active": true,
"last_run_time": 1706000000.0,
"last_run_ago": "2.5s",
"interval": 1.0,
"total_runs": 100,
"failed_runs": 0
}
GET /periodic-threads-health#
对周期性线程的快速健康检查。返回所有关键和高级线程是否处于活动状态。
响应示例:
{
"healthy": true,
"unhealthy_count": 0,
"unhealthy_threads": []
}
线程级别#
周期性线程按重要性级别分类:
级别 |
描述 |
|---|---|
|
系统运行所必需 |
|
对性能很重要 |
|
标准后台任务 |
|
可选/辅助任务 |
健康检查端点专门监控 critical 和 high 级别的线程以确定系统健康状况。
不可恢复异常处理#
周期性线程现在正确处理 IrrecoverableException。当在线程执行期间引发此类异常时:
该异常的完整回溯将被记录。
线程运行被标记为失败
线程 停止其执行循环 而不是继续执行。
这可以防止线程无休止地重试无法成功的操作。
使用示例#
检查整体线程健康状况#
curl http://localhost:8080/periodic-threads-health
列出所有正在运行的线程#
curl "http://localhost:8080/periodic-threads?running_only=true"
仅获取关键线程#
curl "http://localhost:8080/periodic-threads?level=critical"
检查特定线程状态#
curl http://localhost:8080/periodic-threads/pin_monitor