Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // DefBuckets contains the default buckets for the Duration histogram metric DefBuckets = []float64{.001, .01, .1, 1, 10} )
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// Path of the endpoint (e.g. "/health"). Must include the leading /
Path string
// Handler that implements the endpoint
Handler http.Handler
// Methods that the handler should support. If empty, http.MethodGet is the default
Methods []string
}
Handler contains an endpoint to be registered in the Server's HTTP server
type Metrics ¶
type Metrics 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
}
Metrics contains the metrics that will be captured while serving HTTP requests. If these are not provided then Server will create default metrics and register them with Prometheus' default registry.
func NewMetrics ¶ added in v0.3.0
func (*Metrics) Register ¶ added in v0.3.0
func (m *Metrics) Register(r prometheus.Registerer)
type Option ¶ added in v0.3.0
type Option interface {
Apply(server *Server)
}
Option specified configuration options for Server
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
type WithHandlers ¶ added in v0.3.0
type WithHandlers struct {
Handlers []Handler
}
WithHandlers adds the specified handlers to the server
func (WithHandlers) Apply ¶ added in v0.3.0
func (o WithHandlers) Apply(s *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.
func (WithMetrics) Apply ¶ added in v0.3.0
func (o WithMetrics) Apply(s *Server)
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"
func (WithPrometheus) Apply ¶ added in v0.3.0
func (o WithPrometheus) Apply(s *Server)