💥 feat(agent)!: 添加主机监控代理首版
* 实现周期采集、快照缓存、本地 HTTP API 和主动上报 * 补齐 Linux 和 Windows 主机、网络、资源、进程和 TCP 采集 * 添加服务生命周期管理、配置加载、构建脚本和测试覆盖 BREAKING CHANGE: network.ips 拆分为 network.ipv4s 和 network.ipv6s。
This commit is contained in:
37
internal/collector/collector.go
Normal file
37
internal/collector/collector.go
Normal file
@@ -0,0 +1,37 @@
|
||||
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},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user