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 ¶
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.
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.).
var DownloadsTotal = promauto.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "downloads_total",
Help: "Total number of completed file downloads.",
})
DownloadsTotal counts completed file downloads.
var GoroutinesCount = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "goroutines_count",
Help: "Current number of goroutines.",
})
GoroutinesCount tracks the current number of goroutines.
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.
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.
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.
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.
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.
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.
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.
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 ¶
Middleware returns an http.Handler middleware that records per-request Prometheus metrics: requests_total, request_duration_seconds, and active_connections.
func NormalizePath ¶
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 ¶
NewCollector creates a new background metrics collector. Call Start() to begin collection and Stop() on shutdown.