metrics

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultReadTimeout  = 600
	DefaultWriteTimeout = 600
	DefaultHost         = "localhost"
	DefaultPort         = 2201
	DefaultEndpoint     = "/metrics"

	ErrNilConfig = utils.Error("Config is nil")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host         string `json:"host"`
	Port         int    `json:"port"`
	Endpoint     string `json:"endpoint"`
	ReadTimeout  int    `json:"readTimeout"`
	WriteTimeout int    `json:"writeTimeout"`
	tlsProvider.ServerConfig
}

func NewConfig

func NewConfig() *Config

func (*Config) NewServer

func (c *Config) NewServer() (*Server, error)

func (*Config) Validate

func (c *Config) Validate() error

type Server

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

func NewCustomServer

func NewCustomServer(cfg *Config, gatherer prometheus.Gatherer, opts promhttp.HandlerOpts) (*Server, error)

NewCustomServer creates a new custom server based on the provided config, Prometheus gatherer, and handler options. It validates the config using the ParseToken method, then creates a new http.ServeMux and registers the Prometheus handler with it. The server is created with the specified host, port, router, read timeout, write timeout, and TLS config. Finally, it returns a pointer to the created Server instance. Example usage:

cfg := &Config{...}
gatherer := prometheus.DefaultGatherer
opts := promhttp.HandlerOpts{...}
server, err := NewCustomServer(*cfg, gatherer, opts)
if err != nil {
    // handle error
}
defer server.Shutdown(context.Background())
err = server.Start()
if err != nil {
    // handle error
}

func NewServer

func NewServer(cfg *Config) (*Server, error)

func (*Server) Shutdown

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

Shutdown gracefully shuts down the server by calling the Shutdown method of the underlying http.Server It takes a context.Context object as a parameter, which can be used to control the shutdown process. The method returns an error if the shutdown process fails.

func (*Server) Start

func (s *Server) Start() error

Start starts the server and listens for incoming connections. It uses the http.ListenAndServe function if the server's TLSConfig is nil, otherwise it uses the http.ListenAndServeTLS function. The method returns an error if the server fails to start. If the server is shut down using the Shutdown method, the returned error is http.ErrServerClosed.

Jump to

Keyboard shortcuts

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