Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AvgMetrics ¶ added in v0.4.0
type AvgMetrics struct {
// Requests records the number of times a handler was called. This is a prometheus.CounterVec with three labels: "method", "path" and "code".
Requests *prometheus.CounterVec
// Duration records the latency of each handler call. This is a prometheus.HistogramVec with two labels: "method" and "path".
Duration *prometheus.SummaryVec
}
AvgMetrics uses a Summary to record request duration metrics. Use this if you are only interested in the average time to service requests.
func (*AvgMetrics) GetRequestCountMetric ¶ added in v0.4.0
func (m *AvgMetrics) GetRequestCountMetric(method, path string, statusCode int) prometheus.Counter
GetRequestCountMetric returns the Counter to record request count
func (*AvgMetrics) GetRequestDurationMetric ¶ added in v0.4.0
func (m *AvgMetrics) GetRequestDurationMetric(method, path string) prometheus.Observer
GetRequestDurationMetric returns the Observer to record request duration
type Handler ¶
type Handler struct {
// Path of the endpoint (e.g. "/health"). Can be any path that's valid for gorilla/mux router's Path().
Path string
// Handler that implements the endpoint
Handler http.Handler
// Methods that the handler should support. If empty, defaults to http.MethodGet
Methods []string
}
Handler contains an endpoint to be registered in the Server's HTTP server
type Metrics ¶
type Metrics interface {
GetRequestDurationMetric(method, path string) prometheus.Observer
GetRequestCountMetric(method, path string, statusCode int) prometheus.Counter
}
Metrics interface contains the methods httpserver's middleware expects to record performance metrics
func NewAvgMetrics ¶ added in v0.4.0
func NewAvgMetrics(name string, r prometheus.Registerer) Metrics
NewAvgMetrics creates a new AvgMetrics and registers it with the provided prometheus.Registerer. If no registerer is provided, the metrics will be registered with prometheus.DefaultRegisterer.
func NewSLOMetrics ¶ added in v0.4.0
func NewSLOMetrics(name string, r prometheus.Registerer) Metrics
NewSLOMetrics creates a new SLOMetrics and registers it with the provided prometheus.Registerer. If no registerer is provided, the metrics will be registered with prometheus.DefaultRegisterer. NewSLOMetrics uses the standard prometheus default buckets (prometheus.DefBuckets). To override the default buckets, use NewSLOMetricsWithBuckets().
func NewSLOMetricsWithBuckets ¶ added in v0.4.0
func NewSLOMetricsWithBuckets(name string, buckets []float64, r prometheus.Registerer) Metrics
NewSLOMetricsWithBuckets creates a new SLOMetrics with the specified buckets and registers it with the provided prometheus.Registerer. If no registerer is provided, the metrics will be registered with prometheus.DefaultRegisterer.
type Option ¶ added in v0.3.0
type Option interface {
// contains filtered or unexported methods
}
Option specified configuration options for Server
type SLOMetrics ¶ added in v0.4.0
type SLOMetrics struct {
// RequestCounter records the number of times a handler was called. This is a prometheus.CounterVec with three labels: "method", "path" and "code".
// By default, a metric called "http_requests_totals" will be used
RequestCounter *prometheus.CounterVec
// DurationHistogram records the latency of each handler call. This is a prometheus.HistogramVec with two labels: "method" and "path".
// By default, a metric called "http_requests_duration_seconds" will be used, with DefBuckets as the histogram's buckets.
DurationHistogram *prometheus.HistogramVec
}
SLOMetrics uses a histogram to record request duration metrics. Use this to measure an SLO (e.g. 95% of all requests must be serviced below x seconds). SLOMetrics uses Prometheus' default buckets.
func (*SLOMetrics) GetRequestCountMetric ¶ added in v0.4.0
func (m *SLOMetrics) GetRequestCountMetric(method, path string, statusCode int) prometheus.Counter
GetRequestCountMetric returns the Counter to record request count
func (*SLOMetrics) GetRequestDurationMetric ¶ added in v0.4.0
func (m *SLOMetrics) GetRequestDurationMetric(method, path string) prometheus.Observer
GetRequestDurationMetric returns the Observer to record request duration
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server implements a configurable HTTP Server. See the different WithXXX structs for available options.
type WithHandlers ¶ added in v0.3.0
type WithHandlers struct {
Handlers []Handler
}
WithHandlers adds the specified handlers to the server
type WithMetrics ¶ added in v0.3.0
type WithMetrics struct {
Metrics Metrics
}
WithMetrics will collect the specified metrics to instrument the Server's Handlers.
type WithPort ¶ added in v0.3.0
type WithPort struct {
Port int
}
WithPort specifies the Server's listening port. If no port is specified, Server will listen on a random port. Use GetPort() to determine the actual listening port
type WithPrometheus ¶ added in v0.3.0
type WithPrometheus struct {
Path string
}
WithPrometheus adds a Prometheus metrics endpoint to the server at the specified Path. Default path is "/metrics"