rrdmetrics

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 31, 2025 License: MIT Imports: 17 Imported by: 0

README

rrd_metrics

Tools for instrumenting Go web apps with rrdtool as the backend. Basic analytics for small apps where heavier weight and more complex solutions may be overkill

Free yourself from Prometheus monoculture

Has some chi-specific stuff, but you could use it without chi

Requirements: rrdtool librrd

Documentation

Overview

rrdmetrics uses RRDTool as a backend to track application metrics, such as for a running web server

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChiCollector

type ChiCollector struct {
	*MetricsCollector
	// contains filtered or unexported fields
}

ChiCollector extends MetricsCollector with some chi-specific stuff

func (*ChiCollector) RouteMetrics

func (c *ChiCollector) RouteMetrics() func(http.Handler) http.Handler

RouteMetrics build a middleware that automatically pulls metrics from routes

func (*ChiCollector) Run

func (c *ChiCollector) Run() error

type CollectorOption

type CollectorOption func(*MetricsCollector)

func WithStepSize

func WithStepSize(s uint) CollectorOption

WithStepSize configures the step size, ie, how frequently in seconds the metric collector writes to RRD

type Metric

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

Metric is a Metric being tracked by RRDTool metrics share the same namespace, so it's up to you to make sure that they don't collide

func NewMetric

func NewMetric(name, dsType string, options ...MetricOption) Metric

type MetricOption

type MetricOption func(*Metric)

func WithHeartbeat

func WithHeartbeat(h int) MetricOption

func WithMaxValue

func WithMaxValue(mx int) MetricOption

func WithMinValue

func WithMinValue(mn int) MetricOption

type MetricsCollector

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

MetricsCollector

func NewCollector

func NewCollector(rrdPath string, options ...CollectorOption) MetricsCollector

NewCollector creates a new metrics collector

func (*MetricsCollector) AddGaugeMetric

func (c *MetricsCollector) AddGaugeMetric(name string, gf func() float64)

AddGaugeMetric will start tracking a metric of a given name whose value is fetched by the function.

func (*MetricsCollector) AddMetric

func (c *MetricsCollector) AddMetric(m Metric)

AddMetric adds a metric to the metrics being tracked

func (*MetricsCollector) HTTPMetric

func (c *MetricsCollector) HTTPMetric(metricName string) func(http.Handler) http.Handler

HTTPMetric returns a middleware that will start collecting metrics for a handler the metric name will be metricName, which must be 14 characters max and only consist of alphanumeric, _ or -

func (*MetricsCollector) NewChiCollector

func (c *MetricsCollector) NewChiCollector(m *chi.Mux) ChiCollector

NewChiCollector extends the metrics collector with some Chi-specific stuff

func (*MetricsCollector) Run

func (c *MetricsCollector) Run() error

Run will syncs the metrics to the RRD database and begin tracking them. Renaming an existing metric will lead to it being truncated -- use rrdtool tune if this concerns you. Metrics with the same name with 'double up'. you're responsible for avoiding namespace collisions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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