将代码与测试注释改为中文以符合仓库规范;新增中文部署指南、 示例配置,并完善构建脚本对 VERSION 注入的说明。 Co-authored-by: Cursor <cursoragent@cursor.com>
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package collector
|
|
|
|
import (
|
|
"context"
|
|
|
|
"mfd-monitor-agent/internal/snapshot"
|
|
"mfd-monitor-agent/internal/status"
|
|
)
|
|
|
|
// namedCollector 将稳定的采集器名称与采集函数绑定。
|
|
type namedCollector struct {
|
|
name string
|
|
fn func(context.Context, *status.HostStatus) error
|
|
}
|
|
|
|
// Name 返回用于快照错误记录的采集器名称。
|
|
func (c namedCollector) Name() string {
|
|
return c.name
|
|
}
|
|
|
|
// Collect 执行绑定的采集函数。
|
|
func (c namedCollector) Collect(ctx context.Context, out *status.HostStatus) error {
|
|
return c.fn(ctx, out)
|
|
}
|
|
|
|
// New 返回当前平台的默认采集器集合。
|
|
func New(hostID string) []snapshot.Collector {
|
|
return []snapshot.Collector{
|
|
namedCollector{name: "system", fn: func(ctx context.Context, out *status.HostStatus) error {
|
|
return collectSystem(ctx, hostID, out)
|
|
}},
|
|
namedCollector{name: "network", fn: collectNetwork},
|
|
namedCollector{name: "resource", fn: collectResource},
|
|
namedCollector{name: "process", fn: collectProcesses},
|
|
namedCollector{name: "socket", fn: collectSockets},
|
|
}
|
|
}
|