v0.3.3.
This commit is contained in:
1 parent
677a0e4d2c
commit
c85c9fc144
4 files changed
+31
-7
No files matched your search
+21
-5
@@ -52,15 +52,31 @@ func main() {
|
||||
func collect(ctx context.Context, cfg config.Config, tq *ts3.Query, rm *rrd.Manager) {
|
||||
run := func() {
|
||||
c, cancel := context.WithTimeout(ctx, cfg.TSQueryTimeout)
|
||||
defer cancel()
|
||||
n, err := tq.CountOnline(c)
|
||||
cancel()
|
||||
if err != nil {
|
||||
log.Printf("stats query failed: %v", err)
|
||||
return
|
||||
}
|
||||
c2, cancel2 := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel2()
|
||||
if err := rm.Update(c2, n); err != nil {
|
||||
// Treat "query failed" and "query succeeded but nobody is online"
|
||||
// the same way: repeat the last known sample instead of writing 0.
|
||||
// This matches the original PHP app's collector exactly (it never
|
||||
// distinguished the two cases either). At a 1-minute sampling
|
||||
// interval a real but brief empty-server moment plots as a sharp
|
||||
// spike down to 0 and back up, which reads as broken/jagged far
|
||||
// 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.
|
||||
if n == 0 {
|
||||
c2, cancel2 := context.WithTimeout(ctx, 2*time.Second)
|
||||
last, lastErr := rm.Last(c2)
|
||||
cancel2()
|
||||
if lastErr == nil {
|
||||
n = last
|
||||
}
|
||||
}
|
||||
c3, cancel3 := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel3()
|
||||
if err := rm.Update(c3, n); err != nil {
|
||||
log.Printf("rrd update failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user