diff --git a/.env.example b/.env.example index e250b04..d683b82 100644 --- a/.env.example +++ b/.env.example @@ -2,6 +2,9 @@ APP_SECRET=CHANGE_ME_TO_A_LONG_RANDOM_SECRET LISTEN_ADDR=0.0.0.0:8080 HTTPS_ONLY=true +# Verbose per-cycle stats-collector logging (raw TS3 reading vs what got +# written to the RRD). Noisy, meant for troubleshooting only. +DEBUG=false # Origins allowed to embed /embed/channel in an iframe. Space-separated, origins only. FRAME_ANCESTORS=https://www.example.org diff --git a/VERSION b/VERSION index 1c09c74..449d7e7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.3 +0.3.6 diff --git a/cmd/ts3monolith/main.go b/cmd/ts3monolith/main.go index 36f258a..9febcb0 100644 --- a/cmd/ts3monolith/main.go +++ b/cmd/ts3monolith/main.go @@ -66,14 +66,24 @@ func collect(ctx context.Context, cfg config.Config, tq *ts3.Query, rm *rrd.Mana // more than it reads as useful information -- so, deliberately, // a true "server went empty for a while" no longer shows as 0 in // the graph, same trade-off the original app made. + raw := n if n == 0 { c2, cancel2 := context.WithTimeout(ctx, 2*time.Second) last, lastErr := rm.Last(c2) cancel2() - if lastErr == nil { + if lastErr != nil { + log.Printf("collect: raw=0, rrd lastupdate failed (writing raw 0): %v", lastErr) + } else { n = last } } + // DEBUG=1 turns on a log line for every single collection cycle + // (raw TS3 reading vs. what actually got written to the RRD) -- + // useful while diagnosing the stats collector, far too noisy to + // leave on permanently (one line per STATS_INTERVAL, forever). + if cfg.Debug { + log.Printf("collect: raw=%d written=%d", raw, n) + } c3, cancel3 := context.WithTimeout(ctx, 5*time.Second) defer cancel3() if err := rm.Update(c3, n); err != nil { diff --git a/internal/config/config.go b/internal/config/config.go index 11cb201..71d490e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -15,6 +15,7 @@ type Config struct { ListenAddr string AppSecret string HTTPSOnly bool + Debug bool FrameAncestors []string TrustedProxies []*net.IPNet TSQueryHost string @@ -39,6 +40,7 @@ func Load() (Config, error) { return c, errors.New("APP_SECRET must contain at least 32 characters") } c.HTTPSOnly = envBool("HTTPS_ONLY", true) + c.Debug = envBool("DEBUG", false) var err error c.FrameAncestors, err = frameAncestors(os.Getenv("FRAME_ANCESTORS")) diff --git a/packaging/ts3monolith.default b/packaging/ts3monolith.default index 5a1438e..af4fd88 100644 --- a/packaging/ts3monolith.default +++ b/packaging/ts3monolith.default @@ -27,3 +27,7 @@ RRDTOOL=rrdtool RRD_PATH=/var/lib/ts3monolith/online.rrd GRAPH_DIR=/var/lib/ts3monolith/graphs STATS_INTERVAL=60s +# Szczegolowy log kazdego cyklu zbierania statystyk (surowy odczyt z TS3 vs +# co faktycznie trafilo do RRD). Przydatne tylko przy diagnozowaniu -- zalewa +# journald jednym wpisem na STATS_INTERVAL, zostaw wylaczone na co dzien. +DEBUG=false