Documentation
¶
Index ¶
- Constants
- func ToGRPCPromCounterOption(opts *Options) grpcProm.CounterOption
- func ToGRPCPromHistogramOption(opts *Options) grpcProm.HistogramOption
- type Counter
- type DummyRegistry
- func (d *DummyRegistry) NewCounter(key string, opts ...Option) Counter
- func (d *DummyRegistry) NewGauge(key string, opts ...Option) Gauge
- func (d *DummyRegistry) NewHistogram(key string, opts ...Option) Histogram
- func (d *DummyRegistry) NewHttpServerMetrics(opts ...Option) HttpServerMetrics
- func (d *DummyRegistry) NewServerMetrics(opts ...Option) ServerMetrics
- func (d *DummyRegistry) NewTimer(key string, opts ...Option) Timer
- func (d *DummyRegistry) NewWorker(key string, opts ...Option) Worker
- func (d *DummyRegistry) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type Gauge
- type Histogram
- type HttpMetrics
- func (m *HttpMetrics) Collect(ch chan<- prom.Metric)
- func (m *HttpMetrics) Describe(ch chan<- *prom.Desc)
- func (m *HttpMetrics) EnableHandlingTimeHistogram(opts ...grpcProm.HistogramOption)
- func (m *HttpMetrics) Register(r prom.Registerer) errordeprecated
- func (m *HttpMetrics) ServeHTTP(rw http.ResponseWriter, req *http.Request, next http.HandlerFunc)
- type HttpServerMetrics
- type Option
- type Options
- type PrometheusRegistry
- func (p *PrometheusRegistry) AppendLabels(labels map[string]string)
- func (p *PrometheusRegistry) NewCounter(key string, opts ...Option) Counter
- func (p *PrometheusRegistry) NewGauge(key string, opts ...Option) Gauge
- func (p *PrometheusRegistry) NewHistogram(key string, opts ...Option) Histogram
- func (p *PrometheusRegistry) NewHttpServerMetrics(opts ...Option) HttpServerMetrics
- func (p *PrometheusRegistry) NewServerMetrics(opts ...Option) ServerMetrics
- func (p *PrometheusRegistry) NewTimer(key string, opts ...Option) Timer
- func (p *PrometheusRegistry) NewWorker(key string, opts ...Option) Worker
- func (p *PrometheusRegistry) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (p *PrometheusRegistry) SetNamespace(namespace string)
- type Registry
- type ServerMetrics
- type Timer
- type Worker
Constants ¶
const MetricsEnabledFlag = "metrics"
Variables ¶
This section is empty.
Functions ¶
func ToGRPCPromCounterOption ¶
func ToGRPCPromCounterOption(opts *Options) grpcProm.CounterOption
To support grpc prometheus options
func ToGRPCPromHistogramOption ¶
func ToGRPCPromHistogramOption(opts *Options) grpcProm.HistogramOption
Types ¶
type Counter ¶
type Counter interface { Inc() Add(float64) }
Counter is a Metric that represents a single numerical value that only ever goes up. A Counter is typically used to count requests served, tasks completed, errors occurred, etc.
func NewCounter ¶
type DummyRegistry ¶
type DummyRegistry struct { }
func NewDummyRegistry ¶
func NewDummyRegistry() *DummyRegistry
func (*DummyRegistry) NewCounter ¶
func (d *DummyRegistry) NewCounter(key string, opts ...Option) Counter
func (*DummyRegistry) NewHistogram ¶
func (d *DummyRegistry) NewHistogram(key string, opts ...Option) Histogram
func (*DummyRegistry) NewHttpServerMetrics ¶ added in v1.0.1
func (d *DummyRegistry) NewHttpServerMetrics(opts ...Option) HttpServerMetrics
func (*DummyRegistry) NewServerMetrics ¶
func (d *DummyRegistry) NewServerMetrics(opts ...Option) ServerMetrics
func (*DummyRegistry) NewWorker ¶
func (d *DummyRegistry) NewWorker(key string, opts ...Option) Worker
func (*DummyRegistry) ServeHTTP ¶
func (d *DummyRegistry) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Gauge ¶
type Gauge interface {
Set(float64)
}
Gauge is a Metric that represents a single numerical value that can arbitrarily go up and down. A Gauge is typically used for measured values like temperatures or current memory usage.
type Histogram ¶
type Histogram interface {
Observe(float64)
}
A Histogram counts individual observations from an event or sample stream in configurable buckets. Similar to a summary, it also provides a sum of observations and an observation count.
func NewHistogram ¶
type HttpMetrics ¶ added in v1.0.1
type HttpMetrics struct {
// contains filtered or unexported fields
}
HttpMetrics represents a collection of metrics to be registered on a Prometheus metrics registry for a http server.
func NewHttpMetrics ¶ added in v1.0.1
func NewHttpMetrics(counterOpts ...grpcProm.CounterOption) *HttpMetrics
NewHttpMetrics returns a HttpMetrics object. Use a new instance of HttpMetrics when not using the default Prometheus metrics registry, for example when wanting to control which metrics are added to a registry as opposed to automatically adding metrics via init functions.
func (*HttpMetrics) Collect ¶ added in v1.0.1
func (m *HttpMetrics) Collect(ch chan<- prom.Metric)
Collect is called by the Prometheus registry when collecting metrics. The implementation sends each collected metric via the provided channel and returns once the last metric has been sent.
func (*HttpMetrics) Describe ¶ added in v1.0.1
func (m *HttpMetrics) Describe(ch chan<- *prom.Desc)
Describe sends the super-set of all possible descriptors of metrics collected by this Collector to the provided channel and returns once the last descriptor has been sent.
func (*HttpMetrics) EnableHandlingTimeHistogram ¶ added in v1.0.1
func (m *HttpMetrics) EnableHandlingTimeHistogram(opts ...grpcProm.HistogramOption)
EnableHandlingTimeHistogram enables histograms being registered when registering the HttpMetrics on a Prometheus registry. Histograms can be expensive on Prometheus servers. It takes options to configure histogram options such as the defined buckets.
func (*HttpMetrics) Register
deprecated
added in
v1.0.1
func (m *HttpMetrics) Register(r prom.Registerer) error
Register registers all server metrics in a given metrics registry. Depending on histogram options and whether they are enabled, histogram metrics are also registered.
Deprecated: HttpMetrics implements Prometheus Collector interface. You can register an instance of HttpMetrics directly by using prometheus.Register(m).
func (*HttpMetrics) ServeHTTP ¶ added in v1.0.1
func (m *HttpMetrics) ServeHTTP(rw http.ResponseWriter, req *http.Request, next http.HandlerFunc)
UnaryServerInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Unary RPCs.
type HttpServerMetrics ¶ added in v1.0.1
type HttpServerMetrics interface {
ServeHTTP(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
}
HttpServerMetrics is an integrated metric collector to measure count of any kind of error and elapsed time of each http call.
func NewHttpServerMetrics ¶ added in v1.0.1
func NewHttpServerMetrics(opts ...Option) HttpServerMetrics
type PrometheusRegistry ¶
type PrometheusRegistry struct {
// contains filtered or unexported fields
}
func NewPrometheusRegistry ¶
func NewPrometheusRegistry() *PrometheusRegistry
func (*PrometheusRegistry) AppendLabels ¶
func (p *PrometheusRegistry) AppendLabels(labels map[string]string)
func (*PrometheusRegistry) NewCounter ¶
func (p *PrometheusRegistry) NewCounter(key string, opts ...Option) Counter
func (*PrometheusRegistry) NewGauge ¶
func (p *PrometheusRegistry) NewGauge(key string, opts ...Option) Gauge
func (*PrometheusRegistry) NewHistogram ¶
func (p *PrometheusRegistry) NewHistogram(key string, opts ...Option) Histogram
func (*PrometheusRegistry) NewHttpServerMetrics ¶ added in v1.0.1
func (p *PrometheusRegistry) NewHttpServerMetrics(opts ...Option) HttpServerMetrics
func (*PrometheusRegistry) NewServerMetrics ¶
func (p *PrometheusRegistry) NewServerMetrics(opts ...Option) ServerMetrics
func (*PrometheusRegistry) NewTimer ¶
func (p *PrometheusRegistry) NewTimer(key string, opts ...Option) Timer
func (*PrometheusRegistry) NewWorker ¶
func (p *PrometheusRegistry) NewWorker(key string, opts ...Option) Worker
func (*PrometheusRegistry) ServeHTTP ¶
func (p *PrometheusRegistry) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*PrometheusRegistry) SetNamespace ¶
func (p *PrometheusRegistry) SetNamespace(namespace string)
type Registry ¶
type Registry interface { NewHttpServerMetrics(opts ...Option) HttpServerMetrics NewServerMetrics(opts ...Option) ServerMetrics NewCounter(key string, opts ...Option) Counter NewGauge(key string, opts ...Option) Gauge NewHistogram(key string, opts ...Option) Histogram NewTimer(key string, opts ...Option) Timer NewWorker(key string, opts ...Option) Worker // ServeHTTP is used to display all metric values through http request ServeHTTP(w http.ResponseWriter, r *http.Request) }
Registry is a metrics gather
var DefaultRegistry Registry = NewDummyRegistry()
type ServerMetrics ¶
type ServerMetrics interface { InitializeMetrics(*grpc.Server) StreamServerInterceptor() func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error UnaryServerInterceptor() func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) }
ServerMetrics is an integrated metric collector to measure count of any kind of error and elapsed time of each grpc method.
func NewServerMetrics ¶
func NewServerMetrics(opts ...Option) ServerMetrics
type Timer ¶
Timer represents a Histogram Metrics to observe the time duration according to given begin time. Timer is usually used to time a function call in the following way:
func TimeMe() { begin := time.Now() defer Timer.Observe(begin) }
type Worker ¶
Worker includes Timer Metrics to observe the time duration according to given begin time, and counter Metreic to gather the success count and fail count. Worker is usually used to measure a function call in the following way:
func MeasureMe()(err error) { begin := time.Now() defer Worker.Observe(begin, err) }