prometheus

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package prometheus provides a Prometheus wshub.MetricsCollector for wshub.

Usage:

reg := prometheus.NewRegistry()
collector := wshubprom.New(wshubprom.WithRegistry(reg))
hub := wshub.NewHub(wshub.WithMetrics(collector))
go hub.Run()
http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{}))

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 implements wshub.MetricsCollector using Prometheus metrics. It is safe for concurrent use.

func New

func New(opts ...Option) *Collector

New creates a new Prometheus Collector and registers all metrics. It panics if any metric fails to register (e.g. duplicate names).

func (*Collector) DecrementConnections

func (c *Collector) DecrementConnections()

DecrementConnections decrements the active connections gauge.

func (*Collector) DecrementRooms

func (c *Collector) DecrementRooms()

DecrementRooms decrements the active rooms gauge.

func (*Collector) IncrementConnections

func (c *Collector) IncrementConnections()

IncrementConnections increments both active and total connection counters.

func (*Collector) IncrementErrors

func (c *Collector) IncrementErrors(errorType string)

IncrementErrors increments the error counter for the given error type.

func (*Collector) IncrementMessagesDropped

func (c *Collector) IncrementMessagesDropped()

IncrementMessagesDropped increments the counter for messages dropped due to full send buffers.

func (*Collector) IncrementMessagesReceived

func (c *Collector) IncrementMessagesReceived()

IncrementMessagesReceived increments the counter for messages received from clients.

func (*Collector) IncrementMessagesSent

func (c *Collector) IncrementMessagesSent(count int)

IncrementMessagesSent increments the counter for messages sent to clients by the given count.

func (*Collector) IncrementRoomJoins

func (c *Collector) IncrementRoomJoins()

IncrementRoomJoins increments the counter for room join operations.

func (*Collector) IncrementRoomLeaves

func (c *Collector) IncrementRoomLeaves()

IncrementRoomLeaves increments the counter for room leave operations.

func (*Collector) IncrementRooms

func (c *Collector) IncrementRooms()

IncrementRooms increments the active rooms gauge.

func (*Collector) RecordBroadcastDuration

func (c *Collector) RecordBroadcastDuration(duration time.Duration)

RecordBroadcastDuration observes a broadcast fanout duration in the histogram.

func (*Collector) RecordLatency

func (c *Collector) RecordLatency(duration time.Duration)

RecordLatency observes a message handler processing latency in the histogram.

func (*Collector) RecordMessageSize

func (c *Collector) RecordMessageSize(size int)

RecordMessageSize adds the given message size to the total bytes received counter.

type Option

type Option func(*Collector)

Option configures a Collector.

func WithBroadcastBuckets

func WithBroadcastBuckets(buckets []float64) Option

WithBroadcastBuckets sets custom histogram buckets for broadcast duration. Default: {.0001, .0005, .001, .005, .01, .05, .1, .5, 1}.

func WithLatencyBuckets

func WithLatencyBuckets(buckets []float64) Option

WithLatencyBuckets sets custom histogram buckets for message latency. Default: prometheus.DefBuckets.

func WithNamespace

func WithNamespace(ns string) Option

WithNamespace sets the metric namespace (prefix). Default: "wshub".

func WithRegistry

func WithRegistry(reg prometheus.Registerer) Option

WithRegistry sets a custom Prometheus registerer. Default: prometheus.DefaultRegisterer.

Jump to

Keyboard shortcuts

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