metrics

package module
v0.0.0-...-625bcac Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2025 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OK  string = "ok"
	Err string = "err"
)

Variables

View Source
var (
	StatusTotal   = expvar.NewMap("status_total")
	RequestsTotal = expvar.NewMap("requests_total")
	ErrorsTotal   = expvar.NewMap("errors_total")
)
View Source
var (
	InFlightGauge = prometheus.NewGauge(
		prometheus.GaugeOpts{
			Name: "in_flight_requests",
			Help: "A gauge of requests currently being served by the wrapped handler.",
		},
	)

	// RequestDuration is partitioned by the HTTP method and handler. It uses custom
	// buckets based on the expected request duration.
	RequestDuration = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{

			Name:    "request_duration_seconds",
			Help:    "A histogram of latencies for requests.",
			Buckets: prometheus.DefBuckets,
		},
		[]string{"method", "path", "status", "version"},
	)

	// ResponseSize has no labels, making it a zero-dimensional
	// ObserverVec.
	ResponseSize = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "response_size_bytes",
			Help:    "A histogram of response sizes for requests.",
			Buckets: []float64{200, 500, 900, 1500},
		},
		[]string{},
	)

	RED = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "red",
			Help:    "RED metrics",
			Buckets: prometheus.DefBuckets,
		},
		[]string{"service", "action", "status"},
	)
)

Functions

func CounterHandler

func CounterHandler(h http.Handler) http.Handler

CounterHandler tracks the success and error count. Install the expvar.Handler: mux.Handle("GET /debug/vars", expvar.Handler())

func ObserveResponseSize

func ObserveResponseSize(r *http.Request) int

func RequestDurationHandler

func RequestDurationHandler(version string, next http.Handler) http.Handler

func TrackerHandler

func TrackerHandler(h http.Handler, tracker *Tracker, userFn func(r *http.Request) string, logger *slog.Logger) http.Handler

func TrackerStatsHandler

func TrackerStatsHandler(tracker *Tracker) http.Handler

Types

type Prefix

type Prefix string

func (Prefix) Format

func (p Prefix) Format(args ...any) string

type REDTracker

type REDTracker struct {
	Now time.Time
	// contains filtered or unexported fields
}

func NewRED

func NewRED(service, action string) *REDTracker

func (*REDTracker) Done

func (r *REDTracker) Done()

func (*REDTracker) Fail

func (r *REDTracker) Fail()

func (*REDTracker) SetStatus

func (r *REDTracker) SetStatus(status string)

type Stats

type Stats struct {
	Path   string
	P50    float64
	P90    float64
	P95    float64
	Unique int64
	Total  int64
}

func (*Stats) String

func (s *Stats) String() string

type Tracker

type Tracker struct {
	Name string
	Now  func() time.Time
	// contains filtered or unexported fields
}

func NewTracker

func NewTracker(name string, client *redis.Client) *Tracker

func (*Tracker) Record

func (t *Tracker) Record(ctx context.Context, path, userID string, duration time.Duration) error

func (*Tracker) Stats

func (t *Tracker) Stats(ctx context.Context, at time.Time) ([]Stats, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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