Files
mfd-monitor-agent/internal/collector/collector.go
codex 89d5e27874 💥 feat(agent)!: 添加主机监控代理首版
* 实现周期采集、快照缓存、本地 HTTP API 和主动上报

* 补齐 Linux 和 Windows 主机、网络、资源、进程和 TCP 采集

* 添加服务生命周期管理、配置加载、构建脚本和测试覆盖

BREAKING CHANGE: network.ips 拆分为 network.ipv4s 和 network.ipv6s。
2026-05-18 15:25:51 +00:00

38 lines
1.1 KiB
Go

package collector
import (
"context"
"mfd-monitor-agent/internal/snapshot"
"mfd-monitor-agent/internal/status"
)
// namedCollector binds a stable collector name to a collection function.
type namedCollector struct {
name string
fn func(context.Context, *status.HostStatus) error
}
// Name returns the collector name used in snapshot error records.
func (c namedCollector) Name() string {
return c.name
}
// Collect runs the wrapped collection function.
func (c namedCollector) Collect(ctx context.Context, out *status.HostStatus) error {
return c.fn(ctx, out)
}
// New returns the default collector set for the current platform.
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},
}
}