feat: shipping de logs journald a Loki (config loki_url + shipper journalctl→PushLokiStream)

This commit is contained in:
Egutierrez
2026-06-07 13:22:00 +02:00
parent a6e40eeb41
commit 2176e9d442
3 changed files with 174 additions and 9 deletions
+19 -6
View File
@@ -15,6 +15,7 @@
package main
import (
"context"
"flag"
"log"
"os"
@@ -46,14 +47,27 @@ func main() {
return
}
ticker := time.NewTicker(time.Duration(cfg.IntervalSec) * time.Second)
defer ticker.Stop()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-stop
log.Print("shutting down")
cancel()
}()
// Push once right away so a freshly started node shows up immediately,
// then keep pushing on every tick.
// Optional: ship systemd journal logs to Loki in the background.
if cfg.LokiURL != "" {
go shipJournald(ctx, cfg)
}
ticker := time.NewTicker(time.Duration(cfg.IntervalSec) * time.Second)
defer ticker.Stop()
// Push metrics once right away so a freshly started node shows up
// immediately, then keep pushing on every tick.
if err := pushOnce(cfg); err != nil {
log.Printf("push error: %v", err)
}
@@ -63,8 +77,7 @@ func main() {
if err := pushOnce(cfg); err != nil {
log.Printf("push error: %v", err)
}
case <-stop:
log.Print("shutting down")
case <-ctx.Done():
return
}
}