gohttpmetrics

package module
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

README

go-http-metrics

Fork of https://github.com/slok/go-http-metrics to support VictoriaMetrics/metrics (and nothing else)

Documentation

Overview

Package gohttpmetrics knows how to measure http metrics in VictoriaMetrics format. it comes with a middleware that can be used for the main Go net/http handler:

package main

import (
	"log"
	"net/http"

	victoriametrics "github.com/VictoriaMetrics/metrics"
	victoria "github.com/dottedmag/go-http-metrics/metrics/victoria"
	httpmiddleware "github.com/dottedmag/go-http-metrics/middleware"
	httpstdmiddleware "github.com/dottedmag/go-http-metrics/middleware/std"
)

func main() {
	// Create our middleware.
	mdlw := victoria.New(victoria.Config{})

	// Our handler.
	myHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusOK)
		w.Write([]byte("hello world!"))
	})
	h := httpstdmiddleware.Handler("", mdlw, myHandler)

	// Serve metrics.
	log.Printf("serving metrics at: %s", ":9090")
	go http.ListenAndServe(":9090", promhttp.Handler())

	// Serve our handler.
	log.Printf("listening at: %s", ":8080")
	if err := http.ListenAndServe(":8080", h); err != nil {
		log.Panicf("error while serving: %s", err)
	}
}

Directories

Path Synopsis
internal
mocks
Package mocks will have all the mocks of the library.
Package mocks will have all the mocks of the library.
Package middleware will measure metrics of different http handler types using a `metrics.Recorder`.
Package middleware will measure metrics of different http handler types using a `metrics.Recorder`.
std
Package std is a helper package to get a standard `http.Handler` compatible middleware.
Package std is a helper package to get a standard `http.Handler` compatible middleware.

Jump to

Keyboard shortcuts

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