stats

package
v1.7.9 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 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 is a function that continuously measures and sets the CPU usage (utilization) percentages.

This function runs indefinitely in a loop and keeps monitoring the CPU utilization and sets the calculated utilization in 'cpuGauge' variable, until an event of cancellation comes from the passed context 'ctx'.

The function uses 'cpu.PercentWithContext' function under the hood which returns the used CPU percentages. It waits for one second 'time.Second', during each iteration and ignores (does not calculate) CPU percentages for idle or sleeping processes (false value passed as last argument to 'cpu.PercentWithContext' function says to not calculate the idle time).

'ctx.Done()' is used as a form of cancellation signal, it unblocks when the 'ctx' is cancelled. Once such cancellation event happens, the function ends (returns), effectively stopping the CPU measurement.

If there is any error while measuring the CPU usage, it gets logged with level error using 'level.Error' method, and the function stops thereafter.

If 'cpu.PercentWithContext' reports CPU usage, only the first measure (percent[0]) is considered (if available). If no measure is available, nothing is set in this iteration.

The gauge 'cpuGauge', is used to store the computed CPU usage.

Parameters: - ctx (context.Context) : Context to handle cancellation.

Note: This function doesn't return anything.

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

	// 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

	// 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