promwish

package module
v2.0.0-...-cd4685f Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2025 License: MIT Imports: 13 Imported by: 0

README

promwish

Package promwish provides a simple wish middleware exposing some Prometheus metrics.

Example Usage

You can add promwish as a middleware to your app:

promwish.Middleware("localhost:9222", "my-app"),

This will create the metrics and start a HTTP server on localhost:9222 to expose the metrics.

You can also use promwish.MiddlewareRegistry and promwish.Listen if you need more options.

Check the _examples folder for a full working example.

Example Dashboard

image

Documentation

Overview

Package promwish provides a simple middleware to expose some metrics to Prometheus.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultCommandFn

func DefaultCommandFn(s ssh.Session) string

DefaultCommandFn is a CommandFn that returns the first part of s.Command().

func Listen

func Listen(address string)

Listen creates and starts a HTTP metrics server on the given address, serving the metrics from the default registerer to /metrics. It handles exit signals to gracefully shuts down the server.

func Middleware

func Middleware(address, app string) wish.Middleware

Middleware starts a HTTP server on the given address, serving the metrics from the default registerer to /metrics.

func MiddlewareRegistry

func MiddlewareRegistry(registry prometheus.Registerer, constLabels prometheus.Labels, fn CommandFn) wish.Middleware

Middleware setup the metrics for the given registry without starting any HTTP servers. The caller is then responsible for serving the metrics.

func MiddlewareWithCommand

func MiddlewareWithCommand(address, app string, fn CommandFn) wish.Middleware

MiddlewareWithCommand() starts a HTTP server on the given address, serving the metrics from the default registerer to /metrics, using the given CommandFn to extract the `command` label value.

Types

type CommandFn

type CommandFn func(s ssh.Session) string

CommandFn is used to get the value of the `command` label in the Prometheus metrics.

type Server

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

Server is the metrics HTTP server.

func NewServer

func NewServer(address string, promHadler http.Handler) *Server

Creates a new `Server` with the given address.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts the metrics server.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown the metrics server with the given context.

Jump to

Keyboard shortcuts

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