rrdmetrics

package module
v0.0.0-...-f39b02e Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 15 Imported by: 1

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 Logger

type Logger interface {
	Info(msg string, args ...any)
}

Logger TODO figure out ideal

type Metric

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

a Metric being tracked by RRDTool

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
}

func NewCollector

func NewCollector(rrdPath string, step uint) MetricsCollector

NewCollector creates a new metrics collector, which will collect every step seconds. 60 is a good default

func (*MetricsCollector) AddGaugeMetric

func (c *MetricsCollector) AddGaugeMetric(gf func() float64)

Call this function regularly

func (*MetricsCollector) AddMetric

func (c *MetricsCollector) AddMetric(m Metric)

func (*MetricsCollector) ChiMetrics

func (c *MetricsCollector) ChiMetrics(r chi.Router)

ChiMetrics wraps all routes associated with a chi router in

func (*MetricsCollector) HTTPMetric

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

HTTPMetric Generates request middleware that updates each request metricName must be 14 characters or shorter, based on rrd limitations

func (*MetricsCollector) SetLogger

func (c *MetricsCollector) SetLogger(l Logger)

func (*MetricsCollector) Track

func (c *MetricsCollector) Track() error

Track syncs the metrics to the RRD database and begins tracking them. metrics will be stored in a buffer and written every `step` seconds 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