feat(agent) multi-driver db monitoring, hot-plug config, release pipeline
This commit is contained in:
@@ -11,6 +11,8 @@ import (
|
||||
"bugs.watch/agent/internal/collectors/disk"
|
||||
"bugs.watch/agent/internal/collectors/memory"
|
||||
"bugs.watch/agent/internal/collectors/uptime"
|
||||
"bugs.watch/agent/internal/config"
|
||||
"bugs.watch/agent/internal/dbmanager"
|
||||
"bugs.watch/agent/internal/sender"
|
||||
)
|
||||
|
||||
@@ -19,13 +21,12 @@ const (
|
||||
windowDuration = 60 * time.Second
|
||||
)
|
||||
|
||||
func Run(ctx context.Context) {
|
||||
func Run(ctx context.Context, cfg config.Config) {
|
||||
log.Println("bugswatch agent starting")
|
||||
log.Printf("db config: %s", cfg.DBConfigPath)
|
||||
|
||||
// Aggregation window
|
||||
window := aggregate.NewWindow()
|
||||
|
||||
// Register collectors
|
||||
cols := []collectors.Collector{
|
||||
uptime.New(),
|
||||
cpu.New(),
|
||||
@@ -33,8 +34,10 @@ func Run(ctx context.Context) {
|
||||
disk.New(),
|
||||
}
|
||||
|
||||
// Sender (HTTP or logging)
|
||||
snd := sender.NewHTTPSender("http://172.17.0.1:5173/api/health")
|
||||
mgr := dbmanager.New(cfg.DBConfigPath)
|
||||
go mgr.Watch(ctx)
|
||||
|
||||
snd := sender.NewHTTPSender(cfg)
|
||||
|
||||
ticker := time.NewTicker(sampleInterval)
|
||||
defer ticker.Stop()
|
||||
@@ -43,21 +46,19 @@ func Run(ctx context.Context) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
log.Println("bugswatch agent shutting down")
|
||||
|
||||
// Best-effort final flush with bounded timeout
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
|
||||
emitSnapshot(shutdownCtx, snd, window)
|
||||
emitSnapshot(shutdownCtx, snd, window, mgr)
|
||||
return
|
||||
|
||||
case <-ticker.C:
|
||||
for _, c := range cols {
|
||||
c.Collect(window)
|
||||
}
|
||||
mgr.Collect(window)
|
||||
|
||||
if window.Ready(windowDuration) {
|
||||
emitSnapshot(ctx, snd, window)
|
||||
emitSnapshot(ctx, snd, window, mgr)
|
||||
window = aggregate.NewWindow()
|
||||
}
|
||||
}
|
||||
@@ -68,6 +69,7 @@ func emitSnapshot(
|
||||
ctx context.Context,
|
||||
snd sender.Sender,
|
||||
window *aggregate.Window,
|
||||
mgr *dbmanager.Manager,
|
||||
) {
|
||||
snap := window.Snapshot()
|
||||
_ = snd.Send(ctx, snap)
|
||||
|
||||
Reference in New Issue
Block a user