forked from Cloudbox/autoscan
/
stats.go
40 lines (36 loc) · 897 Bytes
/
stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"errors"
"time"
"github.com/rs/zerolog/log"
"github.com/aleksasiriski/autoscan"
"github.com/aleksasiriski/autoscan/processor"
)
func scanStats(proc *processor.Processor, interval time.Duration) {
st := time.NewTicker(interval)
for {
select {
case _ = <-st.C:
// retrieve amount of scans remaining
sm, err := proc.ScansRemaining()
switch {
case err == nil:
log.Info().
Int("remaining", sm).
Int64("processed", proc.ScansProcessed()).
Msg("Scan stats")
case errors.Is(err, autoscan.ErrFatal):
log.Error().
Err(err).
Msg("Fatal error determining amount of remaining scans, scan stats stopped...")
st.Stop()
return
default:
// ErrNoScans should never occur as COUNT should always at-least return 0
log.Error().
Err(err).
Msg("Failed determining amount of remaining scans")
}
}
}
}