mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-16 10:28:29 -07:00
6563886b49
Close #1293
Squashed commit of the following:
commit 0981754c5c2c67f2567ee4af0d9ab24377c53413
Merge: ef81f2c8 a6d75118
Author: Simon Zolin <s.zolin@adguard.com>
Date: Thu Jan 16 14:19:20 2020 +0300
Merge remote-tracking branch 'origin/master' into 1293-install
commit ef81f2c886f3bfcff4e4352d7ecea6642be7d8e1
Author: Simon Zolin <s.zolin@adguard.com>
Date: Mon Dec 30 18:32:11 2019 +0300
linter
commit 9e205be53d9de25bd2ad63398644e14b09f95238
Author: Simon Zolin <s.zolin@adguard.com>
Date: Mon Dec 30 17:22:17 2019 +0300
- install: recover from error on DNS server start
Close all modules properly
Don't register HTTP handlers twice
85 lines
1.7 KiB
Go
85 lines
1.7 KiB
Go
// Module for managing statistics for DNS filtering 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.
|
|
|
|
// 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)
|
|
}
|