metrics

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package metrics provides Prometheus instrumentation for Beamdrop.

It registers counters, histograms, and gauges with the default Prometheus registry and exposes helpers to update them from middleware, handlers, and background goroutines.

Index

Constants

This section is empty.

Variables

View Source
var ActiveConnections = promauto.NewGauge(prometheus.GaugeOpts{
	Namespace: namespace,
	Name:      "active_connections",
	Help:      "Number of currently active HTTP connections.",
})

ActiveConnections tracks the number of in-flight HTTP requests.

View Source
var AuthFailuresTotal = promauto.NewCounterVec(prometheus.CounterOpts{
	Namespace: namespace,
	Name:      "auth_failures_total",
	Help:      "Total number of authentication failures.",
}, []string{"reason"})

AuthFailuresTotal counts authentication failures by reason (invalid_token, missing_token, invalid_password, etc.).

View Source
var DownloadsTotal = promauto.NewCounter(prometheus.CounterOpts{
	Namespace: namespace,
	Name:      "downloads_total",
	Help:      "Total number of completed file downloads.",
})

DownloadsTotal counts completed file downloads.

View Source
var GoroutinesCount = promauto.NewGauge(prometheus.GaugeOpts{
	Namespace: namespace,
	Name:      "goroutines_count",
	Help:      "Current number of goroutines.",
})

GoroutinesCount tracks the current number of goroutines.

View Source
var ObjectsTotal = promauto.NewGauge(prometheus.GaugeOpts{
	Namespace: namespace,
	Name:      "objects_total",
	Help:      "Total number of stored objects (files).",
})

ObjectsTotal reports the current number of objects (files) in the shared directory. Updated periodically by a background collector.

View Source
var RequestDurationSeconds = promauto.NewHistogramVec(prometheus.HistogramOpts{
	Namespace: namespace,
	Name:      "request_duration_seconds",
	Help:      "HTTP request duration in seconds.",
	Buckets:   []float64{0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10},
}, []string{"method", "path", "status"})

RequestDurationSeconds measures per-request latency. The default bucket boundaries are tuned for a file-server workload: most requests complete in under 100ms, but uploads/downloads can take seconds.

View Source
var RequestsTotal = promauto.NewCounterVec(prometheus.CounterOpts{
	Namespace: namespace,
	Name:      "requests_total",
	Help:      "Total number of HTTP requests.",
}, []string{"method", "path", "status"})

RequestsTotal counts every HTTP request, labelled by method, path, and status code so operators can build per-route dashboards.

View Source
var StorageBytes = promauto.NewGauge(prometheus.GaugeOpts{
	Namespace: namespace,
	Name:      "storage_bytes",
	Help:      "Total bytes used by stored files.",
})

StorageBytes reports the total number of bytes used in the shared directory. Updated periodically by a background collector.

View Source
var StorageFreeBytes = promauto.NewGauge(prometheus.GaugeOpts{
	Namespace: namespace,
	Name:      "storage_free_bytes",
	Help:      "Free bytes on the shared-directory filesystem.",
})

StorageFreeBytes reports the free bytes on the filesystem where the shared directory resides.

View Source
var StorageTotalBytes = promauto.NewGauge(prometheus.GaugeOpts{
	Namespace: namespace,
	Name:      "storage_total_bytes",
	Help:      "Total capacity bytes of the shared-directory filesystem.",
})

StorageTotalBytes reports the total capacity of the filesystem where the shared directory resides.

View Source
var UploadSizeBytes = promauto.NewHistogram(prometheus.HistogramOpts{
	Namespace: namespace,
	Name:      "upload_size_bytes",
	Help:      "Size of uploaded files in bytes.",
	Buckets:   prometheus.ExponentialBuckets(1024, 4, 10),
})

UploadSizeBytes tracks individual file upload sizes.

View Source
var UploadsTotal = promauto.NewCounter(prometheus.CounterOpts{
	Namespace: namespace,
	Name:      "uploads_total",
	Help:      "Total number of completed file uploads.",
})

UploadsTotal counts completed file uploads.

Functions

func Middleware

func Middleware(next http.Handler) http.Handler

Middleware returns an http.Handler middleware that records per-request Prometheus metrics: requests_total, request_duration_seconds, and active_connections.

func NormalizePath

func NormalizePath(path string) string

NormalizePath reduces high-cardinality URL paths to a stable label value so the metrics don't explode with unique paths.

Types

type Collector

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

Collector periodically gathers storage and runtime gauges and pushes them into the Prometheus metrics. It runs in a background goroutine and can be stopped via Stop().

func NewCollector

func NewCollector(sharedDir string, interval time.Duration) *Collector

NewCollector creates a new background metrics collector. Call Start() to begin collection and Stop() on shutdown.

func (*Collector) Start

func (c *Collector) Start()

Start begins the periodic collection loop.

func (*Collector) Stop

func (c *Collector) Stop()

Stop signals the collection loop to exit and waits for it to finish.

Jump to

Keyboard shortcuts

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