prometheus

package
v1.80.10 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package prometheus implements the metrics interface with Prometheus.

Index

Constants

View Source
const (
	// NameAPIRequests is the name of the collector that counts the total inbound http requests.
	NameAPIRequests = "api_requests_total"

	// NameInFlightRequests is the name of the collector that counts in-flight inbound http requests.
	NameInFlightRequests = "in_flight_requests"

	// NameRequestDuration is the name of the collector that measures the inbound http request duration in seconds.
	NameRequestDuration = "request_duration_seconds"

	// NameRequestSize is the name of the collector that measures the http request size in bytes.
	NameRequestSize = "request_size_bytes"

	// NameResponseSize is the name of the collector that measures the http response size in bytes.
	NameResponseSize = "response_size_bytes"

	// NameOutboundRequests is the name of the collector that measures the number of outbound requests.
	NameOutboundRequests = "outbound_requests_total"

	// NameOutboundRequestsDuration is the name of the collector that measures the outbound requests duration in seconds.
	NameOutboundRequestsDuration = "outbound_request_duration_seconds"

	// NameOutboundInFlightRequests is the name of the collector that counts in-flight outbound http requests.
	NameOutboundInFlightRequests = "outbound_in_flight_requests"

	// NameErrorLevel is the name of the collector that counts the number of errors for each log severity level.
	NameErrorLevel = "error_level_total"

	// NameErrorCode is the name of the collector that counts the number of errors by task, operation and error code.
	NameErrorCode = "error_code_total"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents the state type of this client.

func New

func New(opts ...Option) (*Client, error)

New creates a new metrics instance with default collectors.

func (*Client) Close

func (c *Client) Close() error

Close method.

func (*Client) IncErrorCounter

func (c *Client) IncErrorCounter(task, operation, code string)

IncErrorCounter increments the number of errors by task, operation and error code.

func (*Client) IncLogLevelCounter

func (c *Client) IncLogLevelCounter(level string)

IncLogLevelCounter counts the number of errors for each log severity level.

func (*Client) InstrumentDB

func (c *Client) InstrumentDB(dbName string, db *sql.DB) error

InstrumentDB wraps a sql.DB to collect metrics.

func (*Client) InstrumentHandler

func (c *Client) InstrumentHandler(path string, handler http.HandlerFunc) http.Handler

InstrumentHandler wraps an http.Handler to collect Prometheus metrics.

func (*Client) InstrumentRoundTripper

func (c *Client) InstrumentRoundTripper(next http.RoundTripper) http.RoundTripper

InstrumentRoundTripper is a middleware that wraps the provided http.RoundTripper to observe the request result with default metrics.

func (*Client) MetricsHandlerFunc

func (c *Client) MetricsHandlerFunc() http.HandlerFunc

MetricsHandlerFunc returns an http handler function to serve the metrics endpoint.

type Option

type Option func(c *Client) error

Option is the interface that allows to set client options.

func WithCollector

func WithCollector(m prometheus.Collector) Option

WithCollector register a new generic collector.

func WithHandlerOpts

func WithHandlerOpts(opts promhttp.HandlerOpts) Option

WithHandlerOpts sets the options how to serve metrics via an http.Handler. The zero value of HandlerOpts is a reasonable default.

func WithInboundRequestDurationBuckets

func WithInboundRequestDurationBuckets(buckets []float64) Option

WithInboundRequestDurationBuckets set the buckets size in seconds for the inbound requests duration.

func WithInboundRequestSizeBuckets

func WithInboundRequestSizeBuckets(buckets []float64) Option

WithInboundRequestSizeBuckets set the buckets size in bytes for the inbound requests.

func WithInboundResponseSizeBuckets

func WithInboundResponseSizeBuckets(buckets []float64) Option

WithInboundResponseSizeBuckets set the buckets size in bytes for the inbound response.

func WithOutboundRequestDurationBuckets

func WithOutboundRequestDurationBuckets(buckets []float64) Option

WithOutboundRequestDurationBuckets set the buckets size in seconds for the outbound requests duration.

Jump to

Keyboard shortcuts

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