go-metrics-prometheus

module
v0.0.0-...-623074c Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: Apache-2.0

README

Prometheus

This is a reporter for the go-metrics that will posts metrics to Prometheus.

Note: this codebase is very young and might contain bugs.

Why use this module?

It is a very minimal module with no external dependencies other that the go-metrics module. This module does not require the standard Prometheus go client which itself is quite a large module containing lots of other code not related to exposing metrics to Prometheus.

This module is quite small so feel free to internalize it into your codebase and adjust it to your needs.

Usage

import "github.com/rcrowley/go-metrics"
import "github.com/LasseJacobs/go-metrics-prometheus"

http.Handle("/metrics", prometheus.MakePrometheusHandler(nil, nil))

fmt.Printf("Starting server at port 8080\n")
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal(err)
}

See example/simple-server for a full working example. Alternatively you can run docker-compose up --build, this will start a test web-app that exposes some metrics, and a prometheus server that will monitor these metrics.

By supplying nil to the MakePrometheusHandler the default metrics registry will be used.

You can verify that it is working by going to: localhost:8080/metrics. Note that if you do not expose any metrics, as is the case in this example, this page will be empty.

Install

go get -u github.com/LasseJacobs/go-metrics-prometheus

running go tidy might be required:

go mode tidy

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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