metrics

package
v0.0.0-...-f179113 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2024 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package metrics contains definitions of most of the prometheus metrics that we use in AdGuard DNS.

NOTE: Prefer to not import any packages from the current module here, because a lot of packages import metrics, and so import cycles may happen.

TODO(a.garipov): Do not use promauto.

Index

Constants

This section is empty.

Variables

View Source
var (

	// BindToDeviceUnknownTCPRequestsTotal is the total counter of DNS requests
	// over TCP to unknown local addresses.
	BindToDeviceUnknownTCPRequestsTotal = bindToDeviceUnknownRequestsTotal.With(prometheus.Labels{
		"proto": "tcp",
	})

	// BindToDeviceUnknownUDPRequestsTotal is the total counter of DNS requests
	// over UDP to unknown local addresses.
	BindToDeviceUnknownUDPRequestsTotal = bindToDeviceUnknownRequestsTotal.With(prometheus.Labels{
		"proto": "udp",
	})
)
View Source
var (
	// BindToDeviceTCPConnsChanSize is a gauge with the current number of TCP
	// connections in the buffer of the channel by each subnet.
	BindToDeviceTCPConnsChanSize = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Name:      "tcp_conns_chan_size",
		Namespace: namespace,
		Subsystem: subsystemBindToDevice,
		Help:      "The current number of TCP connections in the channel.",
	}, []string{"subnet"})

	// BindToDeviceUDPSessionsChanSize is a gauge with the current number of UDP
	// sessions in the buffer of the channel by each subnet.
	BindToDeviceUDPSessionsChanSize = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Name:      "udp_sessions_chan_size",
		Namespace: namespace,
		Subsystem: subsystemBindToDevice,
		Help:      "The current number of UDP sessions in the channel.",
	}, []string{"subnet"})

	// BindToDeviceUDPWriteRequestsChanSize is a gauge with the current number
	// of UDP write requests in the buffer of the channel for each interface
	// listener.
	BindToDeviceUDPWriteRequestsChanSize = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Name:      "udp_write_requests_chan_size",
		Namespace: namespace,
		Subsystem: subsystemBindToDevice,
		Help:      "The current number of UDP write requests in the channel.",
	}, []string{"name"})

	// BindToDeviceUDPWriteDurationSeconds is a histogram of durations of UDP
	// write operations.  This histogram includes only the write itself and does
	// not include deadline setting and resetting.
	BindToDeviceUDPWriteDurationSeconds = promauto.NewHistogramVec(prometheus.HistogramOpts{
		Name:      "udp_write_duration_seconds",
		Namespace: namespace,
		Subsystem: subsystemBindToDevice,
		Help:      "The duration of a write to a UDP socket.",
		Buckets:   []float64{0.001, 0.01, 0.1, 1},
	}, []string{"name"})
)
View Source
var (
	// DNSDBBufferSize is a gauge with the total count of records in the
	// in-memory temporary buffer.
	DNSDBBufferSize = promauto.NewGauge(prometheus.GaugeOpts{
		Name:      "buffer_size",
		Namespace: namespace,
		Subsystem: subsystemDNSDB,
		Help:      "Count of records in the in-memory buffer.",
	})

	// DNSDBRotateTime is a gauge with the time when the DNSDB was rotated.
	DNSDBRotateTime = promauto.NewGauge(prometheus.GaugeOpts{
		Name:      "rotate_time",
		Namespace: namespace,
		Subsystem: subsystemDNSDB,
		Help:      "Last time when the database was rotated.",
	})

	// DNSDBSaveDuration is a histogram with the time elapsed on rotating the
	// buffer for sending over HTTP.
	DNSDBSaveDuration = promauto.NewHistogram(prometheus.HistogramOpts{
		Name:      "save_duration",
		Namespace: namespace,
		Subsystem: subsystemDNSDB,
		Help:      "Time elapsed on rotating the buffer for sending over HTTP.",
	})
)
View Source
var (

	// DNSSvcDDRRequestsTotal is a counter with total number of requests for
	// Discovery of Designated Resolvers.
	DNSSvcDDRRequestsTotal = specialRequestsTotal.With(prometheus.Labels{
		"kind": "ddr",
	})

	// DNSSvcBadResolverARPA is a counter with total number of requests for
	// malformed resolver.arpa queries.
	DNSSvcBadResolverARPA = specialRequestsTotal.With(prometheus.Labels{
		"kind": "bad_resolver_arpa",
	})

	// DNSSvcChromePrefetchRequestsTotal is a counter with total number of
	// requests for the domain name that Chrome uses to check if it should use
	// its prefetch proxy.
	DNSSvcChromePrefetchRequestsTotal = specialRequestsTotal.With(prometheus.Labels{
		"kind": "chrome_prefetch",
	})

	// DNSSvcFirefoxRequestsTotal is a counter with total number of requests for
	// the domain name that Firefox uses to check if it should use its own
	// DNS-over-HTTPS settings.
	DNSSvcFirefoxRequestsTotal = specialRequestsTotal.With(prometheus.Labels{
		"kind": "firefox",
	})

	// DNSSvcApplePrivateRelayRequestsTotal is a counter with total number of
	// requests for the domain name that Apple devices use to check if Apple
	// Private Relay can be enabled.
	DNSSvcApplePrivateRelayRequestsTotal = specialRequestsTotal.With(prometheus.Labels{
		"kind": "apple_private_relay",
	})

	// DNSSvcDoHAuthFailsTotal is the counter of DoH basic authentication
	// failures.
	DNSSvcDoHAuthFailsTotal = promauto.NewCounter(prometheus.CounterOpts{
		Name:      "doh_authentication_fails",
		Namespace: namespace,
		Subsystem: subsystemDNSSvc,
		Help:      "The number of authentication failures for DoH auth.",
	})
)
View Source
var (

	// ECSNoSupportCacheSize is the gauge with the total number of items in
	// the cache for domain names that do not support ECS.
	ECSNoSupportCacheSize = ecsCacheSize.With(prometheus.Labels{
		"supports": "no",
	})

	// ECSHasSupportCacheSize is the gauge with the total number of items in
	// the cache for domain names that support ECS.
	ECSHasSupportCacheSize = ecsCacheSize.With(prometheus.Labels{
		"supports": "yes",
	})
)

Cache size metrics.

View Source
var (

	// ECSCacheLookupTotalHits is a counter with the total number of ECS cache
	// hits.
	ECSCacheLookupTotalHits = ecsCacheLookups.With(prometheus.Labels{
		"hit":      "1",
		"supports": "all",
	})

	// ECSCacheLookupHasSupportHits is a counter with the number of ECS cache
	// hits for hosts that support ECS.
	ECSCacheLookupHasSupportHits = ecsCacheLookups.With(prometheus.Labels{
		"hit":      "1",
		"supports": "yes",
	})

	// ECSCacheLookupNoSupportHits is a counter with the number of ECS cache
	// hits for hosts that don't support ECS.
	ECSCacheLookupNoSupportHits = ecsCacheLookups.With(prometheus.Labels{
		"hit":      "1",
		"supports": "no",
	})

	// ECSCacheLookupTotalMisses is a counter with the total number of ECS cache
	// misses.
	ECSCacheLookupTotalMisses = ecsCacheLookups.With(prometheus.Labels{
		"hit":      "0",
		"supports": "all",
	})

	// ECSCacheLookupHasSupportMisses is a counter with the number of ECS cache
	// misses for hosts that support ECS.
	ECSCacheLookupHasSupportMisses = ecsCacheLookups.With(prometheus.Labels{
		"hit":      "0",
		"supports": "yes",
	})

	// ECSCacheLookupNoSupportMisses is a counter with the number of ECS cache
	// misses for hosts that don't support ECS.
	ECSCacheLookupNoSupportMisses = ecsCacheLookups.With(prometheus.Labels{
		"hit":      "0",
		"supports": "no",
	})
)

Lookup metrics.

View Source
var (

	// FilterCustomCacheLookupsHits is a counter with the total number of the
	// custom filter cache hits.
	FilterCustomCacheLookupsHits = filterCustomCacheLookups.With(prometheus.Labels{"hit": "1"})

	// FilterCustomCacheLookupsMisses is a counter with the total number of the
	// custom filter cache misses.
	FilterCustomCacheLookupsMisses = filterCustomCacheLookups.With(prometheus.Labels{"hit": "0"})
)
View Source
var (

	// HashPrefixFilterSafeBrowsingCacheSize is the gauge with the total number
	// of items in the cache for domain names for safe browsing filter.
	HashPrefixFilterSafeBrowsingCacheSize = hashPrefixFilterCacheSize.With(prometheus.Labels{
		"filter": "safe_browsing",
	})

	// HashPrefixFilterAdultBlockingCacheSize is the gauge with the total number
	// of items in the cache for domain names for adult blocking filter.
	HashPrefixFilterAdultBlockingCacheSize = hashPrefixFilterCacheSize.With(prometheus.Labels{
		"filter": "adult_blocking",
	})

	// HashPrefixFilterNewRegDomainsCacheSize is the gauge with the total number
	// of items in the cache for domain names for safe browsing newly registered
	// domains filter.
	HashPrefixFilterNewRegDomainsCacheSize = hashPrefixFilterCacheSize.With(prometheus.Labels{
		"filter": "newly_registered_domains",
	})

	// HashPrefixFilterCacheSafeBrowsingHits is a counter with the total number
	// of safe browsing filter cache hits.
	HashPrefixFilterCacheSafeBrowsingHits = hashPrefixFilterCacheLookups.With(prometheus.Labels{
		"hit":    "1",
		"filter": "safe_browsing",
	})

	// HashPrefixFilterCacheSafeBrowsingMisses is a counter with the total number
	// of safe browsing filter cache misses.
	HashPrefixFilterCacheSafeBrowsingMisses = hashPrefixFilterCacheLookups.With(prometheus.Labels{
		"hit":    "0",
		"filter": "safe_browsing",
	})

	// HashPrefixFilterCacheAdultBlockingHits is a counter with the total number
	// of adult blocking filter cache hits.
	HashPrefixFilterCacheAdultBlockingHits = hashPrefixFilterCacheLookups.With(prometheus.Labels{
		"hit":    "1",
		"filter": "adult_blocking",
	})

	// HashPrefixFilterCacheAdultBlockingMisses is a counter with the total number
	// of adult blocking filter cache misses.
	HashPrefixFilterCacheAdultBlockingMisses = hashPrefixFilterCacheLookups.With(prometheus.Labels{
		"hit":    "0",
		"filter": "adult_blocking",
	})

	// HashPrefixFilterCacheNewRegDomainsHits is a counter with the total number
	// of newly registered domains filter cache hits.
	HashPrefixFilterCacheNewRegDomainsHits = hashPrefixFilterCacheLookups.With(prometheus.Labels{
		"hit":    "1",
		"filter": "newly_registered_domains",
	})

	// HashPrefixFilterCacheNewRegDomainsMisses is a counter with the total
	// number of newly registered domains filter cache misses.
	HashPrefixFilterCacheNewRegDomainsMisses = hashPrefixFilterCacheLookups.With(prometheus.Labels{
		"hit":    "0",
		"filter": "newly_registered_domains",
	})
)
View Source
var (
	// GeoIPUpdateTime is a gauge with the timestamp of the last GeoIP database
	// update.
	GeoIPUpdateTime = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Name:      "update_time",
		Subsystem: subsystemGeoIP,
		Namespace: namespace,
		Help:      "The time when the GeoIP was loaded last time.",
	}, []string{"path"})

	// GeoIPUpdateStatus is a gauge with the last GeoIP database update status.
	// 1 means success, 0 means an error occurred.
	GeoIPUpdateStatus = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Name:      "update_status",
		Subsystem: subsystemGeoIP,
		Namespace: namespace,
		Help:      "Status of the last GeoIP update. 1 is okay, 0 means that something went wrong.",
	}, []string{"path"})
)
View Source
var (

	// GeoIPCacheLookupsHits is a counter with the total number of the GeoIP IP
	// cache hits.
	GeoIPCacheLookupsHits = geoIPCacheLookups.With(prometheus.Labels{"hit": "1"})

	// GeoIPCacheLookupsMisses is a counter with the total number of the GeoIP
	// IP cache misses.
	GeoIPCacheLookupsMisses = geoIPCacheLookups.With(prometheus.Labels{"hit": "0"})
)
View Source
var (

	// GeoIPHostCacheLookupsHits is a counter with the total number of the GeoIP
	// hostname cache hits.
	GeoIPHostCacheLookupsHits = geoIPHostCacheLookups.With(prometheus.Labels{"hit": "1"})

	// GeoIPHostCacheLookupsMisses is a counter with the total number of the
	// GeoIP hostname cache misses.
	GeoIPHostCacheLookupsMisses = geoIPHostCacheLookups.With(prometheus.Labels{"hit": "0"})
)
View Source
var (
	// RuleStatCacheSize is a gauge with the count of recorded rule hits not
	// yet uploaded.
	RuleStatCacheSize = promauto.NewGauge(prometheus.GaugeOpts{
		Name:      "stats_cache_size",
		Namespace: namespace,
		Subsystem: subsystemRuleStat,
		Help:      "Count of recorded rule hits not yet dumped.",
	})
	// RuleStatUploadStatus is a gauge with the status of the last stats upload.
	RuleStatUploadStatus = promauto.NewGauge(prometheus.GaugeOpts{
		Name:      "stats_upload_status",
		Namespace: namespace,
		Subsystem: subsystemRuleStat,
		Help:      "Status of the last stats upload.",
	})
	// RuleStatUploadTimestamp is a gauge with the timestamp of the last stats
	// upload.
	RuleStatUploadTimestamp = promauto.NewGauge(prometheus.GaugeOpts{
		Name:      "stats_upload_timestamp",
		Namespace: namespace,
		Subsystem: subsystemRuleStat,
		Help:      "Time when stats were uploaded last time.",
	})
)
View Source
var (

	// WebSvcError404RequestsTotal is a counter with total number of
	// requests with error 404.
	WebSvcError404RequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "error404",
	})

	// WebSvcError500RequestsTotal is a counter with total number of
	// requests with error 500.
	WebSvcError500RequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "error500",
	})

	// WebSvcStaticContentRequestsTotal is a counter with total number of
	// requests for static content.
	WebSvcStaticContentRequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "static_content",
	})

	// WebSvcDNSCheckTestRequestsTotal is a counter with total number of
	// requests for dnscheck_test.
	WebSvcDNSCheckTestRequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "dnscheck_test",
	})

	// WebSvcRobotsTxtRequestsTotal is a counter with total number of
	// requests for robots_txt.
	WebSvcRobotsTxtRequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "robots_txt",
	})

	// WebSvcRootRedirectRequestsTotal is a counter with total number of
	// root redirected requests.
	WebSvcRootRedirectRequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "root_redirect",
	})

	// WebSvcLinkedIPProxyRequestsTotal is a counter with total number of
	// requests with linked ip.
	WebSvcLinkedIPProxyRequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "linkip",
	})

	// WebSvcAdultBlockingPageRequestsTotal is a counter with total number
	// of requests for adult blocking page.
	WebSvcAdultBlockingPageRequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "adult_blocking_page",
	})

	// WebSvcGeneralBlockingPageRequestsTotal is a counter with total number
	// of requests for general blocking page.
	WebSvcGeneralBlockingPageRequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "general_blocking_page",
	})

	// WebSvcSafeBrowsingPageRequestsTotal is a counter with total number
	// of requests for safe browsing page.
	WebSvcSafeBrowsingPageRequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "safe_browsing_page",
	})
)
View Source
var AccessProfileInitDuration = promauto.NewHistogram(prometheus.HistogramOpts{
	Name:      "profile_init_engine_duration_seconds",
	Namespace: namespace,
	Subsystem: subsystemAccess,
	Help:      "Time elapsed on profile access engine initialization.",
})

AccessProfileInitDuration is a histogram with the duration of a profile access internal engine initialization.

View Source
var ConnLimiterActiveStreamConns = promauto.NewGaugeVec(prometheus.GaugeOpts{
	Name:      "active_stream_conns",
	Namespace: namespace,
	Subsystem: subsystemConnLimiter,
	Help:      `The number of currently active stream-connections.`,
}, []string{"name", "proto", "addr"})

ConnLimiterActiveStreamConns is the gauge vector for the number of active stream-connections.

View Source
var ConnLimiterLimits = promauto.NewGaugeVec(prometheus.GaugeOpts{
	Name:      "limits",
	Namespace: namespace,
	Subsystem: subsystemConnLimiter,
	Help: `The current limits of the number of active stream-connections: ` +
		`kind="stop" for the stopping limit and kind="resume" for the resuming one.`,
}, []string{"kind"})

ConnLimiterLimits is the gauge vector for showing the configured limits of the number of active stream-connections.

View Source
var DNSCheckErrorTotal = promauto.NewGaugeVec(prometheus.GaugeOpts{
	Name:      "error_total",
	Namespace: namespace,
	Subsystem: subsystemDNSCheck,
	Help:      "The total number of errors with requests to the DNSCheck service.",
}, []string{"source", "type"})

DNSCheckErrorTotal is a gauge with the total number of errors occurred with dnscheck requests. "source" can be "dns" or "http". "type" is either "timeout", "ratelimit" or "other".

View Source
var DNSCheckRequestTotal = promauto.NewCounterVec(prometheus.CounterOpts{
	Name:      "request_total",
	Namespace: namespace,
	Subsystem: subsystemDNSCheck,
	Help:      "The number of requests to the DNSCheck service.",
}, []string{"type", "valid"})

DNSCheckRequestTotal is a counter with the total number of dnscheck requests. "type" can be "dns" or "http". "valid" can be "1" or "0".

View Source
var QueryLogItemSize = promauto.NewHistogram(prometheus.HistogramOpts{
	Name:      "items_size_bytes",
	Subsystem: subsystemQueryLog,
	Namespace: namespace,
	Help:      "A histogram with the query log items size.",

	Buckets: []float64{50, 100, 200, 300, 400, 600, 800, 1000, 2000},
})

QueryLogItemSize is a histogram with the query log items size.

View Source
var QueryLogItemsCount = promauto.NewCounter(prometheus.CounterOpts{
	Name:      "items_total",
	Subsystem: subsystemQueryLog,
	Namespace: namespace,
	Help:      "The total number of query log items written.",
})

QueryLogItemsCount is a counter with the total number of query log items written to the file.

View Source
var QueryLogWriteDuration = promauto.NewHistogram(prometheus.HistogramOpts{
	Name:      "write_duration_seconds",
	Subsystem: subsystemQueryLog,
	Namespace: namespace,
	Help:      "A histogram with the query log items size.",

	Buckets: []float64{0.00001, 0.0001, 0.001, 0.01, 0.1, 1},
})

QueryLogWriteDuration is a histogram with the time spent writing a query log item to the file.

View Source
var StreamConnLifeDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
	Name:      "stream_conn_life_duration_seconds",
	Subsystem: subsystemConnLimiter,
	Namespace: namespace,
	Help:      "How long a stream connection lives, in seconds.",
	Buckets:   []float64{0.1, 1, 5, 10, 30, 60},
}, []string{"name", "proto", "addr"})

StreamConnLifeDuration is a histogram with the duration of lives of stream connections.

View Source
var StreamConnWaitDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
	Name:      "stream_conn_wait_duration_seconds",
	Subsystem: subsystemConnLimiter,
	Namespace: namespace,
	Help:      "How long a stream connection waits for an accept, in seconds.",
	Buckets:   []float64{0.00001, 0.01, 0.1, 1, 10, 30, 60},
}, []string{"name", "proto", "addr"})

StreamConnWaitDuration is a histogram with the duration of waiting times for accepting stream connections.

Functions

func BoolString

func BoolString(cond bool) (s string)

BoolString returns "1" if cond is true and "0" otherwise.

func ExperimentGauge

func ExperimentGauge(constLabels prometheus.Labels) (g prometheus.Gauge)

ExperimentGauge returns the gauge used to inform about running experiments.

func IncrementCond

func IncrementCond(cond bool, trueCounter, falseCounter prometheus.Counter)

IncrementCond increments trueCounter if cond is true and falseCounter otherwise.

func Namespace

func Namespace() (ns string)

Namespace returns the namespace that we use in our prometheus metrics.

func SetAdditionalInfo

func SetAdditionalInfo(info map[string]string)

SetAdditionalInfo adds a gauge with extra info labels. If info is nil, SetAdditionalInfo does nothing.

func SetStatusGauge

func SetStatusGauge(gauge prometheus.Gauge, err error)

SetStatusGauge is a helper function that automatically checks if there's an error and sets the gauge to either 1 (success) or 0 (error).

func SetUpGauge

func SetUpGauge(version, commitTime, branch, revision, goversion string)

SetUpGauge signals that the server has been started. Use a function here to avoid circular dependencies.

Types

type Allowlist

type Allowlist struct {
	// contains filtered or unexported fields
}

Allowlist is the Prometheus-based implementation of the [consul.Metrics] interface.

func NewAllowlist

func NewAllowlist(
	namespace string,
	reg prometheus.Registerer,
	typ string,
) (m *Allowlist, err error)

NewAllowlist registers the Consul allowlist metrics in reg and returns a properly initialized Allowlist.

func (*Allowlist) SetSize

func (m *Allowlist) SetSize(_ context.Context, n int)

SetSize implements the [consul.Metrics] interface for *Allowlist.

func (*Allowlist) SetStatus

func (m *Allowlist) SetStatus(_ context.Context, err error)

SetStatus implements the [consul.Metrics] interface for *Allowlist.

type BackendGRPC

type BackendGRPC struct {
	// contains filtered or unexported fields
}

BackendGRPC is the Prometheus-based implementation of the [backendpb.GRPCMetrics] interface.

func NewBackendGRPC

func NewBackendGRPC(namespace string, reg prometheus.Registerer) (m *BackendGRPC, err error)

NewBackendGRPC registers the protobuf errors metrics in reg and returns a properly initialized BackendGRPC.

func (*BackendGRPC) IncrementErrorCount

func (m *BackendGRPC) IncrementErrorCount(_ context.Context, errType GRPCError)

IncrementErrorCount implements the [backendpb.GRPCMetrics] interface for BackendGRPC.

type BackendProfileDB

type BackendProfileDB struct {
	// contains filtered or unexported fields
}

BackendProfileDB is the Prometheus-based implementation of the [backendpb.ProfileDBMetrics] interface.

func NewBackendProfileDB

func NewBackendProfileDB(
	namespace string,
	reg prometheus.Registerer,
) (m *BackendProfileDB, err error)

NewBackendProfileDB registers the protobuf errors metrics in reg and returns a properly initialized BackendProfileDB.

func (*BackendProfileDB) IncrementInvalidDevicesCount

func (m *BackendProfileDB) IncrementInvalidDevicesCount(_ context.Context)

IncrementInvalidDevicesCount implements the [backendpb.ProfileDBMetrics] interface for BackendProfileDB.

func (*BackendProfileDB) UpdateStats

func (m *BackendProfileDB) UpdateStats(_ context.Context, avgRecv, avgDec time.Duration)

UpdateStats implements the [backendpb.ProfileDBMetrics] interface for BackendProfileDB.

type BackendRemoteKV

type BackendRemoteKV struct {
	// contains filtered or unexported fields
}

BackendRemoteKV is the Prometheus-based implementation of the [backendpb.Metrics] interface.

func NewBackendRemoteKV

func NewBackendRemoteKV(
	namespace string,
	reg prometheus.Registerer,
) (m *BackendRemoteKV, err error)

NewBackendRemoteKV registers the backend remote key-value storage metrics in reg and returns a properly initialized BackendRemoteKV.

func (*BackendRemoteKV) IncrementLookups

func (m *BackendRemoteKV) IncrementLookups(_ context.Context, hit bool)

IncrementLookups implements the [backendpb.RemoteKVMetrics] interface for *BackendRemoteKV.

func (*BackendRemoteKV) ObserveOperation

func (m *BackendRemoteKV) ObserveOperation(_ context.Context, op string, dur time.Duration)

ObserveOperation implements the [backendpb.RemoteKVMetrics] interface for *BackendRemoteKV.

type Billstat

type Billstat struct {
	// contains filtered or unexported fields
}

Billstat is the Prometheus-based implementation of the [billstat.Metrics] interface.

func NewBillstat

func NewBillstat(namespace string, reg prometheus.Registerer) (m *Billstat, err error)

NewBillstat registers the billing-statistics metrics in reg and returns a properly initialized Billstat.

func (*Billstat) BufferSizeSet

func (m *Billstat) BufferSizeSet(_ context.Context, n float64)

BufferSizeSet implements the [billstat.Metrics] interface for *Billstat.

func (*Billstat) HandleUploadDuration

func (m *Billstat) HandleUploadDuration(_ context.Context, dur float64, isSuccess bool)

HandleUploadDuration implements the [billstat.Metrics] interface for *Billstat.

type ClonerStat

type ClonerStat struct{}

ClonerStat is the Prometheus-based implementation of the [dnsmsg.ClonerStat] interface.

func (ClonerStat) OnClone

func (ClonerStat) OnClone(isFull bool)

OnClone implements the [dnsmsg.ClonerStat] interface for ClonerStat.

type DefaultMainMiddleware

type DefaultMainMiddleware struct {
	// contains filtered or unexported fields
}

DefaultMainMiddleware is the Prometheus-based implementation of the MainMiddleware interface.

func NewDefaultMainMiddleware

func NewDefaultMainMiddleware(
	namespace string,
	reg prometheus.Registerer,
) (m *DefaultMainMiddleware, err error)

NewDefaultMainMiddleware registers the filtering-middleware metrics in reg and returns a properly initialized *DefaultMainMiddleware.

func (*DefaultMainMiddleware) OnRequest

OnRequest implements the [Metrics] interface for *DefaultMainMiddleware.

type DefaultRatelimitMiddleware

type DefaultRatelimitMiddleware struct {
	// contains filtered or unexported fields
}

DefaultRatelimitMiddleware is the Prometheus-based implementation of the RatelimitMiddleware interface.

func NewDefaultRatelimitMiddleware

func NewDefaultRatelimitMiddleware(
	namespace string,
	reg prometheus.Registerer,
) (m *DefaultRatelimitMiddleware, err error)

NewDefaultRatelimitMiddleware registers the middleware metrics of the access and ratelimiting middleware in reg and returns a properly initialized *DefaultRatelimitMiddleware.

func (*DefaultRatelimitMiddleware) IncrementAccessBlockedByHost

func (m *DefaultRatelimitMiddleware) IncrementAccessBlockedByHost(_ context.Context)

IncrementAccessBlockedByHost implements the RatelimitMiddleware interface for *DefaultRatelimitMiddleware.

func (*DefaultRatelimitMiddleware) IncrementAccessBlockedByProfile

func (m *DefaultRatelimitMiddleware) IncrementAccessBlockedByProfile(_ context.Context)

IncrementAccessBlockedByProfile implements the RatelimitMiddleware interface for *DefaultRatelimitMiddleware.

func (*DefaultRatelimitMiddleware) IncrementAccessBlockedBySubnet

func (m *DefaultRatelimitMiddleware) IncrementAccessBlockedBySubnet(_ context.Context)

IncrementAccessBlockedBySubnet implements the RatelimitMiddleware interface for *DefaultRatelimitMiddleware.

func (*DefaultRatelimitMiddleware) IncrementRatelimitedByProfile

func (m *DefaultRatelimitMiddleware) IncrementRatelimitedByProfile(_ context.Context)

IncrementRatelimitedByProfile implements the RatelimitMiddleware interface for *DefaultRatelimitMiddleware.

func (*DefaultRatelimitMiddleware) IncrementUnknownDedicated

func (m *DefaultRatelimitMiddleware) IncrementUnknownDedicated(_ context.Context)

IncrementUnknownDedicated implements the RatelimitMiddleware interface for *DefaultRatelimitMiddleware.

func (*DefaultRatelimitMiddleware) OnAllowlisted

func (m *DefaultRatelimitMiddleware) OnAllowlisted(
	ctx context.Context,
	req *dns.Msg,
	rw dnsserver.ResponseWriter,
)

OnAllowlisted implements the RatelimitMiddleware interface for *DefaultRatelimitMiddleware.

func (*DefaultRatelimitMiddleware) OnRateLimited

func (m *DefaultRatelimitMiddleware) OnRateLimited(
	ctx context.Context,
	req *dns.Msg,
	rw dnsserver.ResponseWriter,
)

OnRateLimited implements the RatelimitMiddleware interface for *DefaultRatelimitMiddleware.

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

Filter is the Prometheus-based implementation of the Filter interface.

func NewFilter

func NewFilter(namespace string, reg prometheus.Registerer) (m *Filter, err error)

NewFilter registers the filtering metrics in reg and returns a properly initialized *Filter.

func (*Filter) SetFilterStatus

func (m *Filter) SetFilterStatus(
	ctx context.Context,
	id string,
	updTime time.Time,
	ruleCount int,
	err error,
)

SetFilterStatus implements the [filter.Metrics] interface for *Filter.

type GRPCError

type GRPCError = string

GRPCError is a type alias for string that contains gGRPC error type.

See [backendpb.GRPCMetrics.IncrementErrorCount].

const (
	GRPCErrAuthentication GRPCError = "auth"
	GRPCErrBadRequest     GRPCError = "bad_req"
	GRPCErrDeviceQuota    GRPCError = "dev_quota"
	GRPCErrOther          GRPCError = "other"
	GRPCErrRateLimit      GRPCError = "rate_limit"
	GRPCErrTimeout        GRPCError = "timeout"
)

gRPC errors of GRPCError type.

NOTE: Keep in sync with [backendpb.GRPCError].

type MainMiddleware

type MainMiddleware interface {
	OnRequest(ctx context.Context, m *MainMiddlewareRequestMetrics)
}

MainMiddleware is an interface for collection of the statistics of the main filtering middleware.

NOTE: Keep in sync with [dnssvc.MainMiddleware].

type MainMiddlewareRequestMetrics

type MainMiddlewareRequestMetrics = struct {
	RemoteIP          netip.Addr
	Continent         string
	Country           string
	FilterListID      string
	FilteringDuration time.Duration
	ASN               uint32
	IsAnonymous       bool
	IsBlocked         bool
}

MainMiddlewareRequestMetrics is an alias for a structure that contains the information about a request that has reached the filtering middleware.

See [mainmw.RequestMetrics].

type ProfileDB

type ProfileDB struct {
	// contains filtered or unexported fields
}

ProfileDB is the Prometheus-based implementation of the [profiledb.Metrics] interface.

func NewProfileDB

func NewProfileDB(namespace string, reg prometheus.Registerer) (m *ProfileDB, err error)

NewProfileDB registers the user profiles metrics in reg and returns a properly initialized ProfileDB.

func (*ProfileDB) HandleProfilesUpdate

func (m *ProfileDB) HandleProfilesUpdate(_ context.Context, u *UpdateMetrics)

HandleProfilesUpdate implements the [profilesdb.Metrics] interface for *ProfileDB.

func (*ProfileDB) IncrementDeleted

func (m *ProfileDB) IncrementDeleted(_ context.Context)

IncrementDeleted implements the [profilesdb.Metrics] interface for *ProfileDB.

func (*ProfileDB) IncrementSyncTimeouts

func (m *ProfileDB) IncrementSyncTimeouts(_ context.Context, isFullSync bool)

IncrementSyncTimeouts implements the [profilesdb.Metrics] interface for *ProfileDB.

func (*ProfileDB) SetProfilesAndDevicesNum

func (m *ProfileDB) SetProfilesAndDevicesNum(_ context.Context, profNum, devNum uint)

SetProfilesAndDevicesNum implements the [profilesdb.Metrics] interface for *ProfileDB.

type RatelimitMiddleware

type RatelimitMiddleware interface {
	ratelimit.Metrics

	IncrementAccessBlockedByHost(ctx context.Context)
	IncrementAccessBlockedByProfile(ctx context.Context)
	IncrementAccessBlockedBySubnet(ctx context.Context)
	IncrementRatelimitedByProfile(ctx context.Context)
	IncrementUnknownDedicated(ctx context.Context)
}

RatelimitMiddleware is an interface for collection of the statistics of the access and ratelimit middleware.

NOTE: Keep in sync with [dnssvc.RatelimitMiddleware].

type RedisKV

type RedisKV struct {
	// contains filtered or unexported fields
}

RedisKV is the Prometheus-based implementation of the [rediskv.Metrics] interface.

func NewRedisKV

func NewRedisKV(namespace string, reg prometheus.Registerer) (m *RedisKV, err error)

NewRedisKV registers the Redis KV metrics in reg and returns a properly initialized RedisKV.

func (*RedisKV) UpdateMetrics

func (m *RedisKV) UpdateMetrics(_ context.Context, val uint, isSuccess bool)

UpdateMetrics implements the [rediskv.Metrics] interface for *RedisKV.

type RemoteKVOp

type RemoteKVOp = string

RemoteKVOp is the type alias for string that contains remote key-value storage operation name.

See [backendpb.RemoteKVMetrics.ObserveOperation].

const (
	RemoteKVOpGet RemoteKVOp = "get"
	RemoteKVOpSet RemoteKVOp = "set"
)

Remote key-value storage operation names for RemoteKVOp.

NOTE: Keep in sync with [backendpb.RemoteKVOp].

type TLSConfig

type TLSConfig struct {
	// contains filtered or unexported fields
}

TLSConfig is the Prometheus-based implementation of the [tlsconfig.Metrics] interface.

func NewTLSConfig

func NewTLSConfig(namespace string, reg prometheus.Registerer) (m *TLSConfig, err error)

NewTLSConfig registers the TLS-related metrics in reg and returns a properly initialized TLSConfig.

func (*TLSConfig) AfterHandshake

func (m *TLSConfig) AfterHandshake(
	proto string,
	srvName string,
	devDomains []string,
	srvCerts []*tls.Certificate,
) (f func(tls.ConnectionState) error)

AfterHandshake implements the [tlsconfig.Metrics] interface for *TLSConfig.

func (*TLSConfig) BeforeHandshake

func (m *TLSConfig) BeforeHandshake(
	proto string,
) (f func(*tls.ClientHelloInfo) (*tls.Config, error))

BeforeHandshake implements the [tlsconfig.Metrics] interface for *TLSConfig.

func (*TLSConfig) SetCertificateInfo

func (m *TLSConfig) SetCertificateInfo(_ context.Context, algo, subj string, notAfter time.Time)

SetCertificateInfo implements the [tlsconfig.Metrics] interface for *TLSConfig.

func (*TLSConfig) SetSessionTicketRotationStatus

func (m *TLSConfig) SetSessionTicketRotationStatus(_ context.Context, enabled bool)

SetSessionTicketRotationStatus implements the [tlsconfig.Metrics] interface for *TLSConfig.

type UpdateMetrics

type UpdateMetrics = struct {
	Duration    time.Duration
	ProfilesNum uint
	DevicesNum  uint
	IsSuccess   bool
	IsFullSync  bool
}

UpdateMetrics is an alias for a structure that contains the information about a user profiles update operation.

See [profiledb.UpdateMetrics].

type UserCounter

type UserCounter struct {
	// contains filtered or unexported fields
}

UserCounter is used to save estimated counts of active users per hour and per day by some data.

TODO(a.garipov): Improve and move to golibs.

func NewUserCounter

func NewUserCounter(lastHour, lastDay prometheus.Gauge) (c *UserCounter)

NewUserCounter initializes and returns a properly initialized *UserCounter that uses the given gauges to estimate the user count.

func (*UserCounter) Estimate

func (c *UserCounter) Estimate() (hourly, daily uint64)

Estimate uses HyperLogLog counters to return the number of users for the last hour and the last day. It doesn't include the data for current minute.

It must not be called concurrently with [UserCounter.updateCounters].

TODO(a.garipov): Unexport and use gauges instead?

func (*UserCounter) Record

func (c *UserCounter) Record(now time.Time, userData []byte, syncUpdate bool)

Record updates the current minute-of-the-day counter as well as sets the values of the hourly and daily metric counters, if necessary. now is the time for which to Record the IP address or other data, typically the current time.

If syncUpdate is true, Record performs the metric counter updates synchronously. It is currently only used in tests.

It currently assumes that it will be called at least once per day.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL