- 支持 Windows Agent 构建、安装脚本和统一上报协议 - 增强 RDP 剪贴板、虚拟盘和文件传输能力 - 新增 AIOps 上下文工具、告警 RCA trace 落库和回放接口 - 重构 docs 模块文档并补充终端、堡垒机、监控、AI Agent 设计
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
//go:build !windows
|
|
|
|
// 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
|
|
}
|