- stats: use --workdir
This commit is contained in:
parent
d0dcaeaa04
commit
97684368b9
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
|
||||||
|
@ -34,9 +35,9 @@ func initDNSServer(baseDir string) {
|
||||||
log.Fatalf("Cannot create DNS data dir at %s: %s", baseDir, err)
|
log.Fatalf("Cannot create DNS data dir at %s: %s", baseDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
config.stats = stats.New("./data/stats.db", int(config.DNS.StatsInterval), nil)
|
config.stats, err = stats.New(filepath.Join(baseDir, "stats.db"), int(config.DNS.StatsInterval), nil)
|
||||||
if config.stats == nil {
|
if err != nil {
|
||||||
log.Fatal("config.stats == nil")
|
log.Fatal("Couldn't initialize statistics module")
|
||||||
}
|
}
|
||||||
config.dnsServer = dnsforward.NewServer(baseDir, config.stats)
|
config.dnsServer = dnsforward.NewServer(baseDir, config.stats)
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ type unitIDCallback func() int
|
||||||
// filename: DB file name
|
// filename: DB file name
|
||||||
// limit: time limit (in days)
|
// limit: time limit (in days)
|
||||||
// unitID: user function to get the current unit ID. If nil, the current time hour is used.
|
// unitID: user function to get the current unit ID. If nil, the current time hour is used.
|
||||||
func New(filename string, limit int, unitID unitIDCallback) Stats {
|
func New(filename string, limit int, unitID unitIDCallback) (Stats, error) {
|
||||||
return createObject(filename, limit, unitID)
|
return createObject(filename, limit, unitID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ func UIntArrayEquals(a []uint, b []uint) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStats(t *testing.T) {
|
func TestStats(t *testing.T) {
|
||||||
s := New("./stats.db", 1, nil)
|
s, _ := New("./stats.db", 1, nil)
|
||||||
|
|
||||||
e := Entry{}
|
e := Entry{}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ func TestLargeNumbers(t *testing.T) {
|
||||||
// log.SetLevel(log.DEBUG)
|
// log.SetLevel(log.DEBUG)
|
||||||
fn := "./stats.db"
|
fn := "./stats.db"
|
||||||
os.Remove(fn)
|
os.Remove(fn)
|
||||||
s := New(fn, 1, newID)
|
s, _ := New(fn, 1, newID)
|
||||||
e := Entry{}
|
e := Entry{}
|
||||||
|
|
||||||
n := 1000 // number of distinct clients and domains every hour
|
n := 1000 // number of distinct clients and domains every hour
|
||||||
|
|
|
@ -62,7 +62,7 @@ type unitDB struct {
|
||||||
TimeAvg uint // usec
|
TimeAvg uint // usec
|
||||||
}
|
}
|
||||||
|
|
||||||
func createObject(filename string, limitDays int, unitID unitIDCallback) *statsCtx {
|
func createObject(filename string, limitDays int, unitID unitIDCallback) (*statsCtx, error) {
|
||||||
s := statsCtx{}
|
s := statsCtx{}
|
||||||
s.limit = limitDays * 24
|
s.limit = limitDays * 24
|
||||||
s.filename = filename
|
s.filename = filename
|
||||||
|
@ -72,7 +72,7 @@ func createObject(filename string, limitDays int, unitID unitIDCallback) *statsC
|
||||||
}
|
}
|
||||||
|
|
||||||
if !s.dbOpen() {
|
if !s.dbOpen() {
|
||||||
return nil
|
return nil, fmt.Errorf("open database")
|
||||||
}
|
}
|
||||||
|
|
||||||
id := s.unitID()
|
id := s.unitID()
|
||||||
|
@ -116,7 +116,7 @@ func createObject(filename string, limitDays int, unitID unitIDCallback) *statsC
|
||||||
go s.periodicFlush()
|
go s.periodicFlush()
|
||||||
|
|
||||||
log.Debug("Stats: initialized")
|
log.Debug("Stats: initialized")
|
||||||
return &s
|
return &s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *statsCtx) dbOpen() bool {
|
func (s *statsCtx) dbOpen() bool {
|
||||||
|
|
Loading…
Reference in New Issue