AdGuardHome/internal/stats/stats.go
Ainar Garipov a572876775 Pull request: all: fix lint and naming issues
Merge in DNS/adguard-home from 2276-fix-lint to master

Updates #2276.

Squashed commit of the following:

commit 433f44cc7b674a20ed60a9d29466ba888b3ef66e
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon Dec 7 14:14:28 2020 +0300

    querylog: improve code and documentation

commit 851df97d2a87de5e7180a502055ee6f1a6defdca
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Dec 4 20:36:32 2020 +0300

    all: fix lint and naming issues
2020-12-07 14:32:06 +03:00

86 lines
1.9 KiB
Go

// Package stats provides units for managing statistics of the filtering DNS
// server.
package stats
import (
"net"
"net/http"
)
type unitIDCallback func() uint32
// DiskConfig - configuration settings that are stored on disk
type DiskConfig struct {
Interval uint32 `yaml:"statistics_interval"` // time interval for statistics (in days)
}
// Config - module configuration
type Config struct {
Filename string // database file name
LimitDays uint32 // time limit (in days)
UnitID unitIDCallback // user function to get the current unit ID. If nil, the current time hour is used.
AnonymizeClientIP bool // anonymize clients' IP addresses
// Called when the configuration is changed by HTTP request
ConfigModified func()
// Register an HTTP handler
HTTPRegister func(string, string, func(http.ResponseWriter, *http.Request))
limit uint32 // maximum time we need to keep data for (in hours)
}
// New - create object
func New(conf Config) (Stats, error) {
return createObject(conf)
}
// Stats - main interface
type Stats interface {
Start()
// Close object.
// This function is not thread safe
// (can't be called in parallel with any other function of this interface).
Close()
// Update counters
Update(e Entry)
// Get IP addresses of the clients with the most number of requests
GetTopClientsIP(limit uint) []string
// WriteDiskConfig - write configuration
WriteDiskConfig(dc *DiskConfig)
}
// TimeUnit - time unit
type TimeUnit int
// Supported time units
const (
Hours TimeUnit = iota
Days
)
// Result of DNS request processing
type Result int
// Supported result values
const (
RNotFiltered Result = iota + 1
RFiltered
RSafeBrowsing
RSafeSearch
RParental
rLast
)
// Entry - data to add
type Entry struct {
Domain string
Client net.IP
Result Result
Time uint32 // processing time (msec)
}