Add local monitor bridge service
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"git.hangman-lab.top/zhi/HarborForge.Monitor/internal/bridge"
|
||||
"git.hangman-lab.top/zhi/HarborForge.Monitor/internal/config"
|
||||
"git.hangman-lab.top/zhi/HarborForge.Monitor/internal/telemetry"
|
||||
)
|
||||
@@ -50,11 +51,30 @@ func main() {
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
// Start the bridge server if MONITOR_PORT is configured.
|
||||
// The bridge is independent of heartbeat — if it fails to start,
|
||||
// heartbeat continues normally.
|
||||
var bridgeSrv *bridge.Server
|
||||
if cfg.MonitorPort > 0 {
|
||||
bridgeSrv = bridge.New(cfg, logger)
|
||||
go func() {
|
||||
if err := bridgeSrv.Start(ctx); err != nil {
|
||||
logger.Printf("bridge error (non-fatal): %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
sendOnce := func() error {
|
||||
payload, err := telemetry.BuildPayload(ctx, cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Update bridge with latest telemetry
|
||||
if bridgeSrv != nil {
|
||||
bridgeSrv.UpdatePayload(payload)
|
||||
}
|
||||
|
||||
if printPayload || dryRun {
|
||||
buf, _ := json.MarshalIndent(payload, "", " ")
|
||||
fmt.Println(string(buf))
|
||||
|
||||
Reference in New Issue
Block a user