feat: 完善堡垒机与 Agent 智能运维能力
- 支持 Windows Agent 构建、安装脚本和统一上报协议 - 增强 RDP 剪贴板、虚拟盘和文件传输能力 - 新增 AIOps 上下文工具、告警 RCA trace 落库和回放接口 - 重构 docs 模块文档并补充终端、堡垒机、监控、AI Agent 设计
This commit is contained in:
1 parent
a9513c2056
commit
e0d652d211
169 files changed
+12192
-9116
No files matched your search
@@ -0,0 +1,62 @@
|
||||
//go:build windows
|
||||
|
||||
// Package collector 提供 Windows 进程 TOP 基础采集能力。 // Logan.Li
|
||||
package collector
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"os/exec"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"ezops/agent/model"
|
||||
)
|
||||
|
||||
type ProcessTopCollector struct{}
|
||||
|
||||
func NewProcessTopCollector() *ProcessTopCollector {
|
||||
return &ProcessTopCollector{}
|
||||
}
|
||||
|
||||
func (p *ProcessTopCollector) Collect(topN int) ([]model.ProcessStat, error) {
|
||||
out, err := exec.Command("tasklist", "/FO", "CSV", "/NH").Output()
|
||||
if err != nil {
|
||||
return []model.ProcessStat{}, nil
|
||||
}
|
||||
rows, err := csv.NewReader(strings.NewReader(string(out))).ReadAll()
|
||||
if err != nil {
|
||||
return []model.ProcessStat{}, nil
|
||||
}
|
||||
var procs []model.ProcessStat
|
||||
for _, row := range rows {
|
||||
if len(row) < 5 {
|
||||
continue
|
||||
}
|
||||
pid, _ := strconv.Atoi(strings.TrimSpace(row[1]))
|
||||
memKB := parseWindowsMemKB(row[4])
|
||||
procs = append(procs, model.ProcessStat{
|
||||
PID: pid,
|
||||
Name: row[0],
|
||||
Cmdline: row[0],
|
||||
User: "",
|
||||
MemoryMB: float64(memKB) / 1024.0,
|
||||
})
|
||||
}
|
||||
sort.Slice(procs, func(i, j int) bool {
|
||||
return procs[i].MemoryMB > procs[j].MemoryMB
|
||||
})
|
||||
if topN > len(procs) {
|
||||
topN = len(procs)
|
||||
}
|
||||
if topN < 0 {
|
||||
topN = 0
|
||||
}
|
||||
return procs[:topN], nil
|
||||
}
|
||||
|
||||
func parseWindowsMemKB(s string) int64 {
|
||||
clean := strings.NewReplacer(",", "", "K", "", "k", "", " ", "").Replace(s)
|
||||
v, _ := strconv.ParseInt(clean, 10, 64)
|
||||
return v
|
||||
}
|
||||
Reference in new issue
Block a user