stats

package
v1.10.6 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HavePrometheusLabelEnabled added in v1.3.3

func HavePrometheusLabelEnabled(prometheusLabel string) bool

HavePrometheusLabelEnabled returns true if the specified Prometheus label is enabled in the server configuration, otherwise false.

func MeasureCPU

func MeasureCPU(ctx context.Context)

MeasureCPU monitors and calculates CPU usage statistics at periodic intervals until the provided context is canceled.

func PrintStats

func PrintStats()

PrintStats prints various memory statistics using the default logger. It retrieves the memory statistics using the runtime.ReadMemStats function and then logs the statistics using level.Info from the logging package. The statistics logged include:

  • alloc: The number of kilobytes (KB) allocated.
  • heap_alloc: The number of kilobytes (KB) allocated on the heap.
  • heap_in_use: The number of kilobytes (KB) in use on the heap.
  • heap_idle: The number of kilobytes (KB) idle on the heap.
  • stack_in_use: The number of kilobytes (KB) in use on the stack.
  • stack_sys: The stack size of the program.
  • sys: The total memory allocated by the program.
  • total_alloc: The total number of kilobytes (KB) allocated.
  • num_gc: The number of garbage collections performed.

It uses the util.ByteSize function to convert the memory values in bytes to kilobytes (KB) by dividing them by 1024. The logging is performed using the Logger from the logging package. Note: The declarations of log.Logger, definitions.LogKeyStatsAlloc, util.ByteSize, and other related declarations are not shown here.

func PrometheusTimer added in v1.1.0

func PrometheusTimer(serviceName string, taskName string) func()

PrometheusTimer is a function that takes a prometheus label (promLabel) and a prometheus observer (prometheusObserver) as arguments. The function first checks if the Prometheus Timer is enabled in the server configuration (config.GetFile().GetServer().PrometheusTimer.Enabled). If the Prometheus Timer is not enabled, it returns an empty function. If enabled, it iterates over the labels of the Prometheus Timer specified in the server configuration (config.GetFile().GetServer().PrometheusTimer.Labels). For each label, it checks if it matches with the provided promLabel. If there is a match, it creates a new timer (timer) with the given prometheus observer and returns a function that observes the duration of the timer when called. If there is no match, it returns an empty function. This function is used to measure the time duration using Prometheus, a powerful time-series monitoring service.

func UpdateGenericConnections added in v1.3.0

func UpdateGenericConnections()

UpdateGenericConnections reads from GenericConnectionChan and updates the GenericConnections metric for each connection.

Types

type Metrics added in v1.4.11

type Metrics interface {
	// GetInstanceInfo provides metrics about the version information using a GaugeVec with a "version" label.
	GetInstanceInfo() *prometheus.GaugeVec

	// GetLdapCacheHitsTotal returns a counter vector tracking the total number of LDAP cache hits with specified labels.
	GetLdapCacheHitsTotal() *prometheus.CounterVec

	// GetLdapAuthRateLimitedTotal returns a CounterVec for rate-limited auth requests.
	GetLdapAuthRateLimitedTotal() *prometheus.CounterVec

	// GetLdapCacheMissesTotal returns a Prometheus CounterVec tracking the total number of LDAP cache misses.
	GetLdapCacheMissesTotal() *prometheus.CounterVec

	// GetLdapCacheEntries provides a metric gauge vector for tracking the current number of LDAP cache entries.
	GetLdapCacheEntries() *prometheus.GaugeVec

	// GetLdapCacheEvictionsTotal returns a CounterVec metric tracking the total number of LDAP cache evictions.
	GetLdapCacheEvictionsTotal() *prometheus.CounterVec

	// GetLdapErrorsTotal returns a CounterVec for LDAP errors with labels {pool, op, code}.
	GetLdapErrorsTotal() *prometheus.CounterVec

	// GetLdapRetriesTotal returns a CounterVec for LDAP retries with labels {pool, op}.
	GetLdapRetriesTotal() *prometheus.CounterVec

	// GetCurrentRequests is a Prometheus Gauge metric that tracks the number of current requests being processed by the server.
	GetCurrentRequests() prometheus.Gauge

	// GetHttpRequestsTotal returns a Prometheus CounterVec that tracks the total HTTP requests processed, with a "path" label.
	GetHttpRequestsTotal() *prometheus.CounterVec

	// GetHttpResponseTimeSeconds provides a Prometheus HistogramVec that tracks HTTP response times, with a "path" label.
	GetHttpResponseTimeSeconds() *prometheus.HistogramVec

	// GetLoginsCounter tracks the total number of login attempts (failed and successful) as a Prometheus CounterVec.
	GetLoginsCounter() *prometheus.CounterVec

	// GetRedisReadCounter counts the total number of Redis read operations.
	GetRedisReadCounter() prometheus.Counter

	// GetRedisWriteCounter counts the total number of Redis write operations.
	GetRedisWriteCounter() prometheus.Counter

	// GetFunctionDuration tracks the time spent in functions as a Prometheus HistogramVec, with "service" and "task" labels.
	GetFunctionDuration() *prometheus.HistogramVec

	// GetRblDuration tracks the duration of DNS RBL lookups as a Prometheus HistogramVec.
	GetRblDuration() *prometheus.HistogramVec

	// GetCacheHits counts the total number of cache hits as a Prometheus Counter.
	GetCacheHits() prometheus.Counter

	// GetCacheMisses counts the total number of cache misses as a Prometheus Counter.
	GetCacheMisses() prometheus.Counter

	// GetRedisHits tracks the total number of times a free connection was found in the Redis pool as a Prometheus CounterVec.
	GetRedisHits() *prometheus.CounterVec

	// GetRedisMisses tracks the total number of times a free connection was NOT found in the Redis pool as a Prometheus CounterVec.
	GetRedisMisses() *prometheus.CounterVec

	// GetRedisTimeouts tracks the total number of wait timeouts for Redis connections as a Prometheus CounterVec.
	GetRedisTimeouts() *prometheus.CounterVec

	// GetRedisTotalConns tracks the total number of Redis connections in the pool as a Prometheus GaugeVec.
	GetRedisTotalConns() *prometheus.GaugeVec

	// GetRedisIdleConns tracks the total number of idle Redis connections in the pool as a Prometheus GaugeVec.
	GetRedisIdleConns() *prometheus.GaugeVec

	// GetRedisStaleConns tracks the total number of stale connections removed from the Redis pool as a Prometheus GaugeVec.
	GetRedisStaleConns() *prometheus.GaugeVec

	// GetBruteForceRejected tracks the total number of brute force attempts rejected, categorized by bucket, as a Prometheus CounterVec.
	GetBruteForceRejected() *prometheus.CounterVec

	// GetBruteForceHits counts the total number of brute force hits before being rejected as a Prometheus CounterVec.
	GetBruteForceHits() *prometheus.CounterVec

	// GetRejectedProtocols tracks the total number of protocol rejection attempts as a Prometheus CounterVec, categorized by protocol.
	GetRejectedProtocols() *prometheus.CounterVec

	// GetAcceptedProtocols counts the total number of protocol acceptance attempts as a Prometheus CounterVec, categorized by protocol.
	GetAcceptedProtocols() *prometheus.CounterVec

	// GetBackendServerStatus tracks the status of monitored backend servers as a Prometheus GaugeVec, categorized by server status.
	GetBackendServerStatus() *prometheus.GaugeVec

	// GetLdapPoolStatus provides metrics about actively used connections in the LDAP connection pool as a Prometheus GaugeVec.
	GetLdapPoolStatus() *prometheus.GaugeVec

	// GetLdapOpenConnections tracks the number of currently open LDAP connections as a Prometheus GaugeVec.
	GetLdapOpenConnections() *prometheus.GaugeVec

	// GetLdapStaleConnections tracks the number of stale LDAP connections requiring closure as a Prometheus GaugeVec.
	GetLdapStaleConnections() *prometheus.GaugeVec

	// GetLdapPoolSize provides the size of the LDAP connection pool as a Prometheus GaugeVec.
	GetLdapPoolSize() *prometheus.GaugeVec

	// GetLdapIdlePoolSize tracks the number of idle LDAP pool connections as a Prometheus GaugeVec.
	GetLdapIdlePoolSize() *prometheus.GaugeVec

	// GetLdapQueueDepth tracks the current depth of LDAP queues (lookup/auth) per pool as a Prometheus GaugeVec.
	GetLdapQueueDepth() *prometheus.GaugeVec

	// GetLdapQueueWaitSeconds tracks the time spent waiting in LDAP queues (enqueue to dequeue) as a Prometheus HistogramVec.
	GetLdapQueueWaitSeconds() *prometheus.HistogramVec

	// GetLdapQueueDroppedTotal counts dropped LDAP requests due to queue overflow as a Prometheus CounterVec.
	GetLdapQueueDroppedTotal() *prometheus.CounterVec

	// GetLdapBreakerState exposes circuit breaker state per LDAP target: 0=closed, 1=open, 2=half-open.
	GetLdapBreakerState() *prometheus.GaugeVec

	// GetLdapTargetHealth exposes 0/1 health status per LDAP target.
	GetLdapTargetHealth() *prometheus.GaugeVec

	// GetLdapTargetInflight exposes current in-flight requests per LDAP target.
	GetLdapTargetInflight() *prometheus.GaugeVec

	// GetLuaQueueDepth returns a Prometheus GaugeVec metric tracking the depth of the Lua request queue per backend.
	GetLuaQueueDepth() *prometheus.GaugeVec

	// GetLuaQueueWaitSeconds returns a histogram vector tracking wait times for requests in the Lua script execution queue.
	GetLuaQueueWaitSeconds() *prometheus.HistogramVec

	// GetLuaQueueDroppedTotal returns a CounterVec metric that tracks the total number of Lua queue requests dropped.
	GetLuaQueueDroppedTotal() *prometheus.CounterVec

	// GetLuaVMInUse returns a prometheus.GaugeVec tracking the current number of Lua virtual machines in use.
	GetLuaVMInUse() *prometheus.GaugeVec

	// GetLuaVMReplacedTotal returns a prometheus.CounterVec that tracks the total count of replaced Lua virtual machines.
	GetLuaVMReplacedTotal() *prometheus.CounterVec

	// GetRblRejected tracks the total number of DNS RBL request rejections as a Prometheus CounterVec, categorized by RBL.
	GetRblRejected() *prometheus.CounterVec

	// GetGenericConnections tracks the current number of established generic connections as a Prometheus GaugeVec, categorized by description, target, and direction.
	GetGenericConnections() *prometheus.GaugeVec
}

Metrics ist ein Interface, das alle Getter-Methoden für Metriken definiert.

func GetMetrics added in v1.4.11

func GetMetrics() Metrics

GetMetrics initializes and returns a singleton instance of the Metrics interface.

func NewMetrics added in v1.4.11

func NewMetrics() Metrics

type Reloader added in v1.4.11

type Reloader interface {
	// Reload triggers the reinitialization or refresh of the implementing component, reloading its state or configuration.
	Reload()

	// GetLastReload retrieves the timestamp of the most recent reload operation as a time.Time value.
	GetLastReload() time.Time

	// GetLastReloadFloat64 returns the last reload timestamp as a float64 representing milliseconds since the Unix epoch.
	GetLastReloadFloat64() float64
}

Reloader defines an interface for components that support reinitialization or refreshing their state or configuration.

func GetReloader added in v1.4.11

func GetReloader() Reloader

GetReloader returns a singleton instance of Reloader, initializing it if not already created.

func NewReloader added in v1.4.11

func NewReloader() Reloader

NewReloader creates and returns a new instance of a struct implementing the Reloader interface.

type ReloaderImp added in v1.4.11

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

ReloaderImp is a thread-safe implementation of the Reloader interface, managing state reinitialization timestamps.

func (*ReloaderImp) GetLastReload added in v1.4.11

func (r *ReloaderImp) GetLastReload() time.Time

GetLastReload returns the timestamp of the last reload action performed by the ReloaderImp instance.

func (*ReloaderImp) GetLastReloadFloat64 added in v1.4.11

func (r *ReloaderImp) GetLastReloadFloat64() float64

GetLastReloadFloat64 returns the last reload timestamp as a float64 representing milliseconds since the Unix epoch.

func (*ReloaderImp) Reload added in v1.4.11

func (r *ReloaderImp) Reload()

Reload updates the lastReloadTime with the current timestamp while ensuring thread-safe access via a mutex lock.

Jump to

Keyboard shortcuts

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