metricsrv

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

README

Metric Server

The package core/workers/metricsrv provides a default set of configuration for hosting a http prometheus metrics in a service.

Configuration

The metric server can be configured through the environment to match setup in the infrastructure.

  • PROMETHEUS_ADDR default: :5117
  • PROMETHEUS_PATH default: /metrics

Examples

Starting server and exposing metrics
srv := metricsrv.New(&metricsrv.Config{
    Server: &http.Server{
        Addr: "0.0.0.0:5117",
    },
    Path: "/metrics",
})
srv.Run(ctx)

Documentation

Overview

Package metricsrv provides a default set of configuration for hosting http prometheus metrics in a service.

Index

Examples

Constants

View Source
const (
	// DefaultAddr is the port that we listen to the prometheus path on by default.
	DefaultAddr = "0.0.0.0:5117"

	// DefaultPath is the path where we expose prometheus by default.
	DefaultPath = "/metrics"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v0.8.0

type Config struct {
	Path   string
	Server *http.Server
}

Config represents the configuration for the metrics server.

type Server

type Server struct {
	Path   string
	Server *http.Server
	// contains filtered or unexported fields
}

Server represents a prometheus metrics server.

func New

func New(config *Config) *Server

New creates a new default metrics server.

func (*Server) Addr added in v0.8.0

func (s *Server) Addr() *net.TCPAddr

Addr will block until you have received an address for your server.

func (*Server) Halt added in v0.21.0

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

Halt will attempt to gracefully shut down the server.

func (*Server) Run

func (s *Server) Run(_ context.Context) error

Run will start the metrics server.

Example
package main

import (
	"context"
	"net/http"

	"github.com/LUSHDigital/core/workers/metricsrv"
)

var ctx context.Context

func main() {
	srv := metricsrv.New(&metricsrv.Config{
		Server: &http.Server{
			Addr: "0.0.0.0:5117",
		},
		Path: "/metrics",
	})
	srv.Run(ctx)
}
Output:

Jump to

Keyboard shortcuts

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