Add prometheus exporter on :9100

This commit is contained in:
2026-03-24 03:49:22 +01:00
parent c7f8455188
commit 91eb56a64c
8 changed files with 486 additions and 20 deletions

View File

@@ -6,6 +6,7 @@ import (
"flag"
"log"
"net"
"net/http"
"os"
"os/signal"
"path/filepath"
@@ -19,6 +20,7 @@ import (
func main() {
listen := flag.String("listen", ":9090", "gRPC listen address")
promListen := flag.String("prom-listen", ":9100", "Prometheus metrics listen address (empty to disable)")
logPaths := flag.String("logs", "", "comma-separated log file paths/globs to tail")
logsFile := flag.String("logs-file", "", "file containing one log path/glob per line")
source := flag.String("source", hostname(), "name for this collector (default: hostname)")
@@ -40,6 +42,18 @@ func main() {
ch := make(chan LogRecord, 200_000)
store := NewStore(*source)
if *promListen != "" {
ps := NewPromStore()
store.prom = ps
mux := http.NewServeMux()
mux.Handle("/metrics", ps)
go func() {
log.Printf("collector: Prometheus metrics on %s/metrics", *promListen)
if err := http.ListenAndServe(*promListen, mux); err != nil {
log.Fatalf("collector: Prometheus server: %v", err)
}
}()
}
go store.Run(ch)
tailer := NewMultiTailer(patterns, *scanInterval, *v4prefix, *v6prefix, ch)