observability

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package observability collects metrics (per-command calls and latency), the slow log, and MONITOR streaming (tracing.go).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandSnapshot

type CommandSnapshot struct {
	Name   string
	Calls  int64
	Errors int64
	Usec   int64
}

CommandSnapshot is a plain copy of CommandStats.

type CommandStats

type CommandStats struct {
	Calls   atomic.Int64
	Errors  atomic.Int64
	Usec    atomic.Int64
	Buckets [12]atomic.Int64 // len(buckets)+1, last is +Inf
}

type Gauge

type Gauge struct {
	Name, Help string
	Value      float64
}

Gauge is an extra value written by WritePrometheus (memory, keys, ...).

type Metrics

type Metrics struct {
	Started          time.Time
	TotalCommands    atomic.Int64
	TotalConnections atomic.Int64
	RejectedConns    atomic.Int64
	ConnectedClients atomic.Int64
	NetInputBytes    atomic.Int64
	NetOutputBytes   atomic.Int64
	// contains filtered or unexported fields
}

func NewMetrics

func NewMetrics() *Metrics

func (*Metrics) Commands

func (m *Metrics) Commands() []CommandSnapshot

Commands returns stats for every command that has run, sorted by name.

func (*Metrics) Observe

func (m *Metrics) Observe(cmd string, dur time.Duration, failed bool)

Observe records one executed command.

func (*Metrics) ResetCommands

func (m *Metrics) ResetCommands()

ResetCommands clears per-command stats (CONFIG RESETSTAT).

func (*Metrics) WritePrometheus

func (m *Metrics) WritePrometheus(w io.Writer, gauges []Gauge)

WritePrometheus writes all metrics in the Prometheus text format.

type Monitor

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

Monitor streams every executed command to MONITOR clients, in the same format as Redis: 1700000000.123456 [0 127.0.0.1:5000] "SET" "a" "1"

func NewMonitor

func NewMonitor() *Monitor

func (*Monitor) Active

func (m *Monitor) Active() bool

Active reports whether anyone is monitoring (cheap check before formatting).

func (*Monitor) Add

func (m *Monitor) Add(s Subscriber)

func (*Monitor) Feed

func (m *Monitor) Feed(fromID int64, addr string, args []string)

Feed sends one command to all monitors, except the client that ran it.

func (*Monitor) Remove

func (m *Monitor) Remove(s Subscriber)

type SlowEntry

type SlowEntry struct {
	ID         int64
	Time       time.Time
	Duration   time.Duration
	Args       []string
	ClientAddr string
	ClientName string
}

SlowEntry is one SLOWLOG record.

type Slowlog

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

Slowlog keeps the most recent commands slower than a threshold.

func NewSlowlog

func NewSlowlog() *Slowlog

func (*Slowlog) Get

func (s *Slowlog) Get(n int) []SlowEntry

Get returns up to n entries, newest first (n < 0 = all).

func (*Slowlog) Len

func (s *Slowlog) Len() int

func (*Slowlog) Record

func (s *Slowlog) Record(thresholdMicros int64, maxLen int, dur time.Duration, args []string, addr, name string)

Record adds an entry if dur exceeds thresholdMicros (<0 disables, 0 logs everything).

func (*Slowlog) Reset

func (s *Slowlog) Reset()

type Subscriber

type Subscriber interface {
	Push(v resp.Value) bool
	ClientID() int64
}

Subscriber receives MONITOR lines. Push must not block.

Jump to

Keyboard shortcuts

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