metrics

package
v0.0.0-...-63956fc Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HandlerWrapperBuilder

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

HandlerWrapperBuilder contains the data and logic needed to build a new metrics handler wrapper that creates HTTP handlers that generate the following Prometheus metrics:

<subsystem>_request_count - Number of API requests sent.
<subsystem>_request_duration_sum - Total time to send API requests, in seconds.
<subsystem>_request_duration_count - Total number of API requests measured.
<subsystem>_request_duration_bucket - Number of API requests organized in buckets.

To set the subsystem prefix use the Subsystem method.

The duration buckets metrics contain an `le` label that indicates the upper bound. For example if the `le` label is `1` then the value will be the number of requests that were processed in less than one second.

The metrics will have the following labels:

method - Name of the HTTP method, for example GET or POST.
path - Request path, for example /api/my/v1/resources.
code - HTTP response code, for example 200 or 500.

To calculate the average request duration during the last 10 minutes, for example, use a Prometheus expression like this:

rate(my_request_duration_sum[10m]) / rate(my_request_duration_count[10m])

In order to reduce the cardinality of the metrics the path label is modified to remove the identifiers of the objects. For example, if the original path is .../resources/123 then it will be replaced by .../resources/-, and the values will be accumulated. The line returned by the metrics server will be like this:

<subsystem>_request_count{code="200",method="GET",path=".../resources/-"} 56

The meaning of that is that there were a total of 56 requests to get specific resources, independently of the specific identifier of the resource.

The value of the `code` label will be zero when sending the request failed without a response code, for example if it wasn't possible to open the connection, or if there was a timeout waiting for the response.

Note that setting this attribute is not enough to have metrics published, you also need to create and start a metrics server, as described in the documentation of the Prometheus library.

Don't create objects of this type directly; use the NewHandlerWrapper function instead.

func NewHandlerWrapper

func NewHandlerWrapper() *HandlerWrapperBuilder

NewHandlerWrapper creates a new builder that can then be used to configure and create a new metrics handler wrapper.

func (*HandlerWrapperBuilder) AddPath

AddPath adds a path that will be accepted as a value for the `path` label. For paths aren't explicitly specified here then their metrics will be accumulated in the `/-` path.

func (*HandlerWrapperBuilder) AddPaths

func (b *HandlerWrapperBuilder) AddPaths(values ...string) *HandlerWrapperBuilder

AddPaths adds a list of paths that will be accepted as a value for the `path` label. For paths aren't explicitly specified here then their metrics will be accumulated in the `/-` path.

func (*HandlerWrapperBuilder) Build

func (b *HandlerWrapperBuilder) Build() (result func(http.Handler) http.Handler, err error)

Build uses the information stored in the builder to create a new handler wrapper.

func (*HandlerWrapperBuilder) SetRegisterer

SetRegisterer sets the Prometheus registerer that will be used to register the metrics. The default is to use the default Prometheus registerer and there is usually no need to change that. This is intended for unit tests, where it is convenient to have a registerer that doesn't interfere with the rest of the system.

func (*HandlerWrapperBuilder) SetSubsystem

func (b *HandlerWrapperBuilder) SetSubsystem(value string) *HandlerWrapperBuilder

SetSubsystem sets the name of the subsystem that will be used by to register the metrics with Prometheus. For example, if the value is `my` then the following metrics will be registered:

my_request_count - Number of API requests sent.
my_inbound_request_duration_sum - Total time to send API requests, in seconds.
my_inbound_request_duration_count - Total number of API requests measured.
my_inbound_request_duration_bucket - Number of API requests organized in buckets.

This is mandatory.

type TransportWrapperBuilder

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

TransportWrapperBuilder contains the data and logic needed to build a new metrics transport wrapper that creates HTTP round trippers that generate the following Prometheus metrics:

<subsystem>_request_count - Number of API requests sent.
<subsystem>_request_duration_sum - Total time to send API requests, in seconds.
<subsystem>_request_duration_count - Total number of API requests measured.
<subsystem>_request_duration_bucket - Number of API requests organized in buckets.

To set the subsystem prefix use the Subsystem method.

The duration buckets metrics contain an `le` label that indicates the upper bound. For example if the `le` label is `1` then the value will be the number of requests that were processed in less than one second.

The metrics will have the following labels:

method - Name of the HTTP method, for example GET or POST.
path - Request path, for example /o2ims-infrastructureInventory/v1/resourcePools
code - HTTP response code, for example 200 or 500.

To calculate the average request duration during the last 10 minutes, for example, use a Prometheus expression like this:

rate(my_request_duration_sum[10m]) / rate(my_request_duration_count[10m])

In order to reduce the cardinality of the metrics the path label is modified to remove the identifiers of the objects. For example, if the original path is ../resources/123 then it will be replaced by .../resources/-, and the values will be accumulated. The line returned by the metrics server will be like this:

<subsystem>_request_count{code="200",method="GET",path=".../resources/-"} 56

The meaning of that is that there were a total of 56 requests to get specific resources, independently of the specific identifier of the resource.

The value of the `code` label will be zero when sending the request failed without a response code, for example if it wasn't possible to open the connection, or if there was a timeout waiting for the response.

Note that setting this attribute is not enough to have metrics published, you also need to create and start a metrics server, as described in the documentation of the Prometheus library.

Don't create objects of this type directly; use the NewTransportWrapper function instead.

func NewTransportWrapper

func NewTransportWrapper() *TransportWrapperBuilder

NewTransportWrapper creates a new builder that can then be used to configure and create a new metrics round tripper.

func (*TransportWrapperBuilder) AddPath

AddPath adds a path that will be accepted as a value for the `path` label. For paths that aren't explicitly specified here their metrics will be accumulated in the `/-` path.

func (*TransportWrapperBuilder) AddPaths

func (b *TransportWrapperBuilder) AddPaths(values ...string) *TransportWrapperBuilder

AddPaths adds a list path that will be accepted as a value for the `path` label. For paths that aren't explicitly specified here their metrics will be accumulated in the `/-` path.

func (*TransportWrapperBuilder) Build

func (b *TransportWrapperBuilder) Build() (result func(http.RoundTripper) http.RoundTripper,
	err error)

Build uses the information stored in the builder to create a new transport wrapper.

func (*TransportWrapperBuilder) SetRegisterer

SetRegisterer sets the Prometheus registerer that will be used to register the metrics. The default is to use the default Prometheus registerer and there is usually no need to change that. This is intended for unit tests, where it is convenient to have a registerer that doesn't interfere with the rest of the system.

func (*TransportWrapperBuilder) SetSubsystem

func (b *TransportWrapperBuilder) SetSubsystem(value string) *TransportWrapperBuilder

SetSubsystem sets the name of the subsystem that will be used by to register the metrics with Prometheus. For example, if the value is `my` then the following metrics will be registered:

my_request_count - Number of API requests sent.
my_request_duration_sum - Total time to send API requests, in seconds.
my_request_duration_count - Total number of API requests measured.
my_request_duration_bucket - Number of API requests organized in buckets.

This is mandatory.

Jump to

Keyboard shortcuts

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