39 lines
1.0 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Command agent 是 host-metrics-collector 的 Agent 端入口:定时采集主机
// CPU/内存/磁盘/网络/进程指标与文件日志,经本地 WAL 断点续传,批量上报到
// Collector Gateway默认 http://127.0.0.1:4318
package main
import (
"context"
"log"
"os"
"os/signal"
"syscall"
"git.opencomputing.cn/yumoqing/host-metrics-collector/internal/agent"
"git.opencomputing.cn/yumoqing/host-metrics-collector/internal/config"
)
func main() {
cfg := config.DefaultAgentConfig()
log.Printf("[agent] starting host=%s version=%s gateway=%s", cfg.HostID, cfg.AgentVersion, cfg.GatewayURL)
a, err := agent.New(cfg)
if err != nil {
log.Fatalf("[agent] init failed: %v", err)
}
defer func() {
if err := a.Close(); err != nil {
log.Printf("[agent] close: %v", err)
}
}()
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
if err := a.Run(ctx); err != nil {
log.Printf("[agent] run: %v", err)
}
log.Printf("[agent] stopped")
}