stats

package
v0.2.3-danish Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

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

Collector tracks and computes queue statistics

func NewCollector

func NewCollector(options StatsOptions) *Collector

NewCollector creates a new stats collector with the provided options

func (*Collector) GetStats

func (c *Collector) GetStats(isHealthy bool) QueueStats

GetStats returns the current queue statistics

func (*Collector) RecordComplete

func (c *Collector) RecordComplete(processingTime time.Duration, success bool)

RecordComplete records a job completing (success or failure)

func (*Collector) RecordDequeue

func (c *Collector) RecordDequeue(enqueuedAt time.Time)

RecordDequeue records a job being taken from the queue

func (*Collector) RecordEnqueue

func (c *Collector) RecordEnqueue()

RecordEnqueue records a job being added to the queue

type QueueStats

type QueueStats struct {
	// Queue size metrics
	QueuedJobs     int64 `json:"queued_jobs"`
	ProcessingJobs int64 `json:"processing_jobs"`
	CompletedJobs  int64 `json:"completed_jobs"`
	FailedJobs     int64 `json:"failed_jobs"`

	// Performance metrics
	EnqueueRate    float64       `json:"enqueue_rate"`     // Jobs/second
	DequeueRate    float64       `json:"dequeue_rate"`     // Jobs/second
	AvgWaitTime    time.Duration `json:"avg_wait_time"`    // Time in queue
	AvgProcessTime time.Duration `json:"avg_process_time"` // Processing duration

	// Health indicators
	IsHealthy    bool      `json:"is_healthy"`
	IsOverloaded bool      `json:"is_overloaded"`
	LastUpdated  time.Time `json:"last_updated"`
}

QueueStats represents the current health metrics of a queue

type StatsOptions

type StatsOptions struct {
	Enabled           bool          // Whether stats collection is enabled
	HistoryWindow     time.Duration // Time window for rate calculations (default: 1 minute)
	MaxSampleSize     int           // Maximum samples to keep (prevent memory bloat)
	OverloadThreshold int64         // Jobs in queue that indicates overload
	OverloadRatio     float64       // Ratio of queued:processing jobs that indicates overload
}

StatsOptions configures how the stats collector operates

func DefaultStatsOptions

func DefaultStatsOptions() StatsOptions

DefaultStatsOptions returns sensible defaults for stats collection.

The default configuration: - Disables stats collection by default - Sets a 1-minute window for rate calculations - Limits to 500 samples to prevent memory issues - Sets an overload threshold of 1000 jobs - Sets an overload ratio of 5.0 (5x more queued than processing jobs indicates overload)

Returns:

  • A StatsOptions struct with default values

Jump to

Keyboard shortcuts

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