Documentation
¶
Overview ¶
Package stats provides units for managing statistics of the filtering DNS server.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// UnitID is the function to generate the identifier for current unit. If
// nil, the default function is used, see newUnitID.
UnitID UnitIDGenFunc
// ConfigModified will be called each time the configuration changed via web
// interface.
ConfigModified func()
// ShouldCountClient returns client's ignore setting.
ShouldCountClient func([]string) bool
// HTTPRegister is the function that registers handlers for the stats
// endpoints.
HTTPRegister aghhttp.RegisterFunc
// Ignored contains the list of host names, which should not be counted,
// and matches them.
Ignored *aghnet.IgnoreEngine
// Filename is the name of the database file.
Filename string
// Limit is an upper limit for collecting statistics.
Limit time.Duration
// Enabled tells if the statistics are enabled.
Enabled bool
}
Config is the configuration structure for the statistics collecting.
Do not alter any fields of this structure after using it.
type Entry ¶
type Entry struct {
// Clients is the client's primary ID.
//
// TODO(a.garipov): Make this a {net.IP, string} enum?
Client string
// Domain is the domain name requested.
Domain string
// Upstream is the upstream DNS server.
Upstream string
// Result is the result of processing the request.
Result Result
// ProcessingTime is the duration of the request processing from the start
// of the request including timeouts.
ProcessingTime time.Duration
// UpstreamTime is the duration of the successful request to the upstream.
UpstreamTime time.Duration
}
Entry is a statistics data entry.
type Interface ¶ added in v0.107.10
type Interface interface {
// Start begins the statistics collecting.
Start()
io.Closer
// Update collects the incoming statistics data.
Update(e *Entry)
// GetTopClientIP returns at most limit IP addresses corresponding to the
// clients with the most number of requests.
TopClientsIP(limit uint) []netip.Addr
// WriteDiskConfig puts the Interface's configuration to the dc.
WriteDiskConfig(dc *Config)
// ShouldCount returns true if request for the host should be counted.
ShouldCount(host string, qType, qClass uint16, ids []string) bool
}
Interface is the statistics interface to be used by other packages.
type StatsCtx ¶ added in v0.107.10
type StatsCtx struct {
// contains filtered or unexported fields
}
StatsCtx collects the statistics and flushes it to the database. Its default flushing interval is one hour.
func New ¶
New creates s from conf and properly initializes it. Don't use s before calling it's Start method.
func (*StatsCtx) ShouldCount ¶ added in v0.107.24
ShouldCount returns true if request for the host should be counted.
func (*StatsCtx) Start ¶ added in v0.107.10
func (s *StatsCtx) Start()
Start implements the Interface interface for *StatsCtx.
func (*StatsCtx) TopClientsIP ¶ added in v0.107.10
TopClientsIP implements the Interface interface for *StatsCtx.
func (*StatsCtx) Update ¶ added in v0.107.10
Update implements the Interface interface for *StatsCtx. e must not be nil.
func (*StatsCtx) WriteDiskConfig ¶ added in v0.107.10
WriteDiskConfig implements the Interface interface for *StatsCtx.
type StatsResp ¶ added in v0.107.10
type StatsResp struct {
TimeUnits string `json:"time_units"`
TopQueried []topAddrs `json:"top_queried_domains"`
TopClients []topAddrs `json:"top_clients"`
TopBlocked []topAddrs `json:"top_blocked_domains"`
TopUpstreamsResponses []topAddrs `json:"top_upstreams_responses"`
TopUpstreamsAvgTime []topAddrsFloat `json:"top_upstreams_avg_time"`
DNSQueries []uint64 `json:"dns_queries"`
BlockedFiltering []uint64 `json:"blocked_filtering"`
ReplacedSafebrowsing []uint64 `json:"replaced_safebrowsing"`
ReplacedParental []uint64 `json:"replaced_parental"`
NumDNSQueries uint64 `json:"num_dns_queries"`
NumBlockedFiltering uint64 `json:"num_blocked_filtering"`
NumReplacedSafebrowsing uint64 `json:"num_replaced_safebrowsing"`
NumReplacedSafesearch uint64 `json:"num_replaced_safesearch"`
NumReplacedParental uint64 `json:"num_replaced_parental"`
AvgProcessingTime float64 `json:"avg_processing_time"`
}
StatsResp is a response to the GET /control/stats.
type UnitIDGenFunc ¶ added in v0.107.10
type UnitIDGenFunc func() (id uint32)
UnitIDGenFunc is the signature of a function that generates a unique ID for the statistics unit.