feat: v0.34 健康探针(Architecture B) + Agent v2.1 + 端口监控 + 告警联系人重构
- v0.31: AlertContact 重构(channel_type下拉+webhook_url替代三分立字段) - v0.32: Agent ProcessTop 增强(cmdline/user/cpu_pct/mem_pct) - v0.33: 端口监控 Tab(监听端口自动发现+down联动告警) - v0.34: 健康探针(Agent本地执行HTTP/TCP/Exec→结果随心跳上报) - Agent新增: ContextSwitch/FD/HealthProbe采集器 - 后端新增: health_probe handler + Agent model扩展 - HostMonitor新增Tab: 健康探针/端口监控
This commit is contained in:
1 parent
e1f75f0bc4
commit
d656520428
25 files changed
+1700
-619
No files matched your search
@@ -0,0 +1,39 @@
|
||||
// Package collector 的上下文切换采集器。
|
||||
// 读取 /proc/stat 中的 ctxt(上下文切换)和 intr(中断)累计值。
|
||||
// 注意:此处返回累计值而非速率,后端可用两次上报差值计算。
|
||||
//
|
||||
// 署名 Logan.Li
|
||||
package collector
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"ezops/agent/model"
|
||||
)
|
||||
|
||||
// ContextSwitchCollector 上下文切换采集器
|
||||
type ContextSwitchCollector struct{}
|
||||
|
||||
// NewContextSwitchCollector 创建采集器实例
|
||||
func NewContextSwitchCollector() *ContextSwitchCollector {
|
||||
return &ContextSwitchCollector{}
|
||||
}
|
||||
|
||||
// Collect 读取 /proc/stat 中的上下文切换和中断统计
|
||||
func (c *ContextSwitchCollector) Collect() (*model.ContextSwitchStat, error) {
|
||||
data, err := os.ReadFile("/proc/stat")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("读取 /proc/stat 失败: %w", err)
|
||||
}
|
||||
stat := &model.ContextSwitchStat{}
|
||||
for _, line := range SplitLines(string(data)) {
|
||||
if HasPrefix(line, "ctxt ") {
|
||||
fmt.Sscanf(line, "ctxt %f", &stat.CTXPerSec)
|
||||
}
|
||||
if HasPrefix(line, "intr ") {
|
||||
fmt.Sscanf(line, "intr %f", &stat.IRQPerSec)
|
||||
}
|
||||
}
|
||||
return stat, nil
|
||||
}
|
||||
Reference in new issue
Block a user