instrument

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 6 Imported by: 0

README

instrument — Prometheus metrics for HTTP, DB, and scheduler

import "github.com/downsized-devs/sdk-go/instrument"

Stability: Stable — see STABILITY.md

Wraps prometheus/client_golang with pre-built collectors for the SDK's primary surfaces (HTTP, SQL pools, scheduled jobs).

Features

  • MetricsHandler() — drop-in http.Handler for /metrics.
  • HTTPRequestTimer, HTTPRequestCounter, HTTPResponseStatusCounter.
  • RegisterDBStats, DatabaseQueryTimer — used by sql.
  • SchedulerRunningCounter, SchedulerRunningTimer — used by scheduler.
  • IsEnabled — quick gate for callers that should no-op when metrics are off.

Installation

go get github.com/downsized-devs/sdk-go/instrument

Quick Start

m := instrument.Init(instrument.Config{Enabled: true})
http.Handle("/metrics", m.MetricsHandler())

API Reference

Symbol Signature
Init func Init(cfg Config) Interface
Interface.IsEnabled () bool
Interface.MetricsHandler () http.Handler
Interface.HTTPRequestTimer (method, route string) *prometheus.HistogramVec
Interface.HTTPRequestCounter (method, route string) prometheus.Counter
Interface.HTTPResponseStatusCounter (method, route, status string) prometheus.Counter
Interface.RegisterDBStats (name string, db DBStats)
Interface.DatabaseQueryTimer (name, op string) prometheus.Observer
Interface.SchedulerRunningCounter (job string) prometheus.Counter
Interface.SchedulerRunningTimer (job string) prometheus.Observer

Configuration

Field Description
Enabled Master on/off switch.
Namespace, Subsystem Optional Prometheus label prefixes.

Dependencies

  • External: github.com/prometheus/client_golang

Testing

go test ./instrument/...

Two test files cover handler, counters, and timer registration.

Contributing

See CONTRIBUTING.md. Metric names are public — don't rename existing ones (breaks dashboards and alerts).

  • sql — consumer for RegisterDBStats and DatabaseQueryTimer.
  • scheduler — consumer for scheduler timers/counters.
  • tracker — Prometheus push gateway (this package exposes pull).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Metrics MetricsConfig
}

type Interface

type Interface interface {
	// Other Functions
	IsEnabled() bool
	// HTTP Handler
	MetricsHandler() http.Handler
	// HTTP Metrics
	HTTPRequestTimer(path, method string) *prometheus.Timer
	HTTPRequestCounter(path, method string)
	HTTPResponseStatusCounter(code int)
	// Database Metrics
	RegisterDBStats(db *sql.DB, dbname string)
	DatabaseQueryTimer(dbname, conntype, queryname string) *prometheus.Timer
	// Scheduler Metrics
	SchedulerRunningCounter(schedulername string)
	SchedulerRunningTimer(schedulername string) *prometheus.Timer
}

func Init

func Init(cfg Config) Interface

type MetricsConfig

type MetricsConfig struct {
	Enabled bool
}

Jump to

Keyboard shortcuts

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