Documentation
¶
Overview ¶
Package metrics provides a way to collect metrics in a thread-safe way
Index ¶
- func Make(ctx context.Context, workers int) context.Context
- func WithWorkerID(ctx context.Context, id int) context.Context
- func WorkerID(ctx context.Context) int
- type Stats
- type TimerType
- type Value
- func (m *Value) Add(key string, delta int) int
- func (m *Value) AddWaitTime(wid int, d time.Duration)
- func (m *Value) Get(key string) int
- func (m *Value) GetStats() Stats
- func (m *Value) Inc(key string) int
- func (m *Value) IncDropped(wid int)
- func (m *Value) IncErrors(wid int)
- func (m *Value) IncProcessed(wid int)
- func (m *Value) StartTimer(wid int, t TimerType) func()
- func (m *Value) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithWorkerID ¶
WithWorkerID sets worker ID in the context
Types ¶
type Stats ¶
type Stats struct {
// raw counters
Processed int
Errors int
Dropped int
// timing
ProcessingTime time.Duration
WaitTime time.Duration
InitTime time.Duration
WrapTime time.Duration
TotalTime time.Duration
// derived stats, calculated on GetStats
RatePerSec float64 // items processed per second
AvgLatency time.Duration // average processing time per item
ErrorRate float64 // portion of errors
DroppedRate float64 // portion of dropped items
Utilization float64 // portion of time spent processing vs waiting
}
Stats represents worker-specific metrics with derived values
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value holds both per-worker stats and shared user stats
func Get ¶
Get metrics from context. If not found, creates new instance with same worker count as stored in context.
func (*Value) AddWaitTime ¶ added in v0.3.1
AddWaitTime adds wait time directly to worker stats
func (*Value) GetStats ¶ added in v0.2.0
GetStats returns combined stats from all workers. For accurate results, call this method after pool completion (Close/Wait returned). Calling during active processing may return inconsistent values due to concurrent writes.
func (*Value) IncDropped ¶ added in v0.2.0
IncDropped increments dropped count for worker
func (*Value) IncProcessed ¶ added in v0.2.0
IncProcessed increments processed count for worker
func (*Value) StartTimer ¶
StartTimer returns a function that when called will record the duration in worker stats