feat: shipping de logs journald a Loki (config loki_url + shipper journalctl→PushLokiStream)
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user