metrics

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2025 License: BSD-2-Clause Imports: 5 Imported by: 0

README

Metrics

Go library for working with Prometheus metrics.

Features

  • Name Builder: Create valid Prometheus metric names from arbitrary strings
  • Pusher: Push metrics to Prometheus Pushgateway

Installation

go get github.com/bborbe/metrics

Usage

Building Metric Names
import "github.com/bborbe/metrics"

// Create a valid Prometheus metric name
name := metrics.BuildName("my-service", "request_count")
// Result: "my_service_request_count"

// Add to existing name
name = name.Add("total")
// Result: "my_service_request_count_total"

The BuildName function:

  • Converts to lowercase
  • Replaces illegal characters with underscores
  • Handles leading numbers
  • Collapses multiple underscores
Pushing Metrics
import (
    "context"
    "github.com/bborbe/metrics"
)

pusher := metrics.NewPusher(
    "http://pushgateway:9091",
    metrics.BuildName("my_service"),
)

if err := pusher.Push(context.Background()); err != nil {
    // handle error
}

Development

make precommit  # Format, generate, test, and check
make test       # Run tests
make check      # Run linters and security checks

License

BSD-style license. Copyright Benjamin Borbe.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Name

type Name string

func BuildName

func BuildName(names ...string) Name

BuildName from the given string. Replace all illegal characters with underscore

func (Name) Add

func (n Name) Add(name string) Name

func (Name) String

func (n Name) String() string

type Pusher

type Pusher interface {
	Push(ctx context.Context) error
}

Pusher pushes metrics to a push gateway.

func NewPusher

func NewPusher(
	url string,
	name Name,
) Pusher

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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