stats

package
v4.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HavePrometheusLabelEnabled

func HavePrometheusLabelEnabled(cfg config.File, prometheusLabel string) bool

HavePrometheusLabelEnabled provides the exported HavePrometheusLabelEnabled function.

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(logger *slog.Logger)

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

func PrometheusTimer(cfg config.File, serviceName string, taskName string, resource string) func()

PrometheusTimer returns a closure that, when executed, stops a Prometheus timer for a given service and task. If the Prometheus Timer is disabled or the specified task is not enabled in the configuration, it returns nil.

func UpdateGenericConnections

func UpdateGenericConnections(ctx context.Context)

UpdateGenericConnections reads from GenericConnectionChan and updates the GenericConnections metric. It exits when ctx is canceled.

Types

type Metrics

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

	// GetGRPCRequestsTotal returns a counter vector tracking completed gRPC requests by bounded method and status code.
	GetGRPCRequestsTotal() *prometheus.CounterVec

	// GetGRPCResponseTimeSeconds returns a histogram vector tracking gRPC response-boundary durations by bounded method.
	GetGRPCResponseTimeSeconds() *prometheus.HistogramVec

	// GetAuthenticationResponseTimeSeconds tracks authentication response latency by bounded transport, outcome, and protocol.
	GetAuthenticationResponseTimeSeconds() *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

	// GetBackchannelCallerAuthTotal counts backchannel caller authentication outcomes by bounded transport and outcome.
	GetBackchannelCallerAuthTotal() *prometheus.CounterVec

	// GetRWPDecisionsTotal counts repeating-wrong-password verdicts by outcome:
	// repeated, counted or undecided. Undecided means the store could not answer,
	// which is the one case that must never be read as an attack.
	GetRWPDecisionsTotal() *prometheus.CounterVec

	// GetRWPWindowDuration observes how long one RWP sliding-window round-trip takes.
	GetRWPWindowDuration() prometheus.Histogram

	// GetTolerationDecisionsTotal counts toleration lookups by resulting mode.
	GetTolerationDecisionsTotal() *prometheus.CounterVec

	// GetTolerationPercent observes the tolerated percentage actually applied.
	GetTolerationPercent() prometheus.Histogram

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

	// GetBruteForceEvalSeconds measures end-to-end latency of the brute-force evaluation path.
	GetBruteForceEvalSeconds() prometheus.Histogram

	// GetBruteForceCacheHitsTotal counts in-process cache/burst gating hits within the brute-force path, labeled by kind.
	GetBruteForceCacheHitsTotal() *prometheus.CounterVec

	// GetBruteForceRulesMatchedTotal counts how often a brute-force rule matched (pre or final).
	GetBruteForceRulesMatchedTotal() prometheus.Counter

	// GetRedisRoundtripsTotal counts Redis roundtrips attributable to the brute-force path, labeled by kind.
	GetRedisRoundtripsTotal() *prometheus.CounterVec

	// GetIdpLoginsTotal tracks the total number of IDP logins.
	GetIdpLoginsTotal() *prometheus.CounterVec

	// GetIdpTokensIssuedTotal tracks the total number of IDP tokens issued.
	GetIdpTokensIssuedTotal() *prometheus.CounterVec

	// GetIdpConsentTotal tracks the total number of IDP consent operations.
	GetIdpConsentTotal() *prometheus.CounterVec

	// GetIdpMfaOperationsTotal tracks the total number of IDP MFA operations.
	GetIdpMfaOperationsTotal() *prometheus.CounterVec

	// GetIdpDynamicClientRegistrationsTotal tracks bounded dynamic-registration outcomes.
	GetIdpDynamicClientRegistrationsTotal() *prometheus.CounterVec
	// GetIdpDynamicClientRegistrationDurationSeconds tracks DCR request latency without unbounded labels.
	GetIdpDynamicClientRegistrationDurationSeconds() prometheus.Histogram

	// GetWebAuthnCeremonyReferenceCookieBytes tracks the bounded dedicated cookie size.
	GetWebAuthnCeremonyReferenceCookieBytes() prometheus.Histogram

	// GetWebAuthnCeremonyReferenceOperationsTotal tracks bounded store, take, and delete outcomes.
	GetWebAuthnCeremonyReferenceOperationsTotal() *prometheus.CounterVec

	// GetAuthFSMTransitionsTotal tracks auth FSM transitions labeled by from/event/to.
	GetAuthFSMTransitionsTotal() *prometheus.CounterVec

	// GetAuthnFSMGuardViolationsTotal counts policy permits the host-evidence auth FSM rejected, by bounded
	// operation and checkpoint.
	GetAuthnFSMGuardViolationsTotal() *prometheus.CounterVec

	// GetPluginCallsTotal tracks host-invoked native plugin calls with bounded component labels.
	GetPluginCallsTotal() *prometheus.CounterVec

	// GetPluginCallDurationSeconds tracks native plugin call duration with bounded component labels.
	GetPluginCallDurationSeconds() *prometheus.HistogramVec

	// GetPluginReconfigureTotal tracks per-module outcomes of native plugin config reloads.
	GetPluginReconfigureTotal() *prometheus.CounterVec

	// GetPostActionPlanDurationSeconds tracks complete accepted post-action plan duration by result.
	GetPostActionPlanDurationSeconds() *prometheus.HistogramVec

	// GetPostActionEffectStatesTotal tracks bounded supervisor transitions without correlation labels.
	GetPostActionEffectStatesTotal() *prometheus.CounterVec

	// GetPostActionAcceptanceFailuresTotal counts rejected post-action ownership transfers by error class.
	GetPostActionAcceptanceFailuresTotal() *prometheus.CounterVec

	// GetPolicyAuthnAdmissionRejectionsTotal counts internal authn sessions rejected for capacity by bounded reason.
	GetPolicyAuthnAdmissionRejectionsTotal() *prometheus.CounterVec

	// GetAuthApplicationErrorsTotal counts unexpected auth application errors answered as tempfail by bounded transport.
	GetAuthApplicationErrorsTotal() *prometheus.CounterVec
}

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

func GetMetrics

func GetMetrics() Metrics

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

func NewMetrics

func NewMetrics() Metrics

NewMetrics provides the exported NewMetrics function.

type Reloader

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

func GetReloader() Reloader

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

func NewReloader

func NewReloader() Reloader

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

type ReloaderImp

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

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

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

func (*ReloaderImp) GetLastReloadFloat64

func (r *ReloaderImp) GetLastReloadFloat64() float64

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

func (*ReloaderImp) Reload

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