Documentation ¶
Index ¶
- Variables
- func MeterNumberOfRequests(i *Info, m *Metrics)
- func MeterRequestBodySize(i *Info, m *Metrics)
- func MeterRequestOperation(i *Info, m *Metrics)
- func MeterResponseBodySize(i *Info, m *Metrics)
- func MeterResponseStatus(i *Info, m *Metrics)
- func MeterResponseTime(i *Info, m *Metrics)
- type GaugeFunc
- type Info
- type Meter
- type MeterFunc
- type Metrics
- type Report
- type Reporter
- type RuntimeCollector
Constants ¶
This section is empty.
Variables ¶
var Meters = []MeterFunc{ MeterNumberOfRequests, MeterResponseStatus, MeterRequestOperation, MeterResponseTime, MeterResponseBodySize, MeterRequestBodySize, }
Meters stores the built-in function meters used by default for metrics collection. You can define your custom meter functions via metrics.AddMeter() or metrics.SetMeters().
var PublishInterval = 15 * time.Second
PublishInterval defines the amount of time to wait between metrics publish cycles. Defaults to 15 seconds.
var RuntimeInterval = 10 * time.Second
RuntimeInterval the amount of time to wait between runtime metrics report cycles. Defaults to 10 seconds.
Functions ¶
func MeterNumberOfRequests ¶
MeterNumberOfRequests is used to register the total number of served requests.
func MeterRequestBodySize ¶
MeterRequestBodySize is used to measure the HTTP request body length. Data will be stored in a histogram.
func MeterRequestOperation ¶
MeterRequestOperation is used to count the number of request by HTTP operation. Operation in inferred by HTTP verb:
- GET, HEAD = read operation - POST, PUT, PATCH, DELETE = write operation
func MeterResponseBodySize ¶
MeterResponseBodySize is used to measure the HTTP response body length. Data will be stored in a histogram.
func MeterResponseStatus ¶
MeterResponseStatus is used to count the response status code by range (2xx, 4xx, 5xx).
func MeterResponseTime ¶
MeterResponseTime is used to measure the HTTP request/response time. Data will be stored in a histogram.
Types ¶
type GaugeFunc ¶
GaugeFunc is an interface that implements the setting of a gauge value in a stats system. It should be expected that key will contain multiple parts separated by the '.' character in the form used by statsd (e.x. "mem.heap.alloc")
type Info ¶
type Info struct { // Status stores the response HTTP status. Status int // BodyLength stores the response body length in bytes. BodyLength int64 // TimeStart stores when the request was received by the server. TimeStart time.Time // TimeEnd stores when the response is written. TimeEnd time.Time // Header stores the response HTTP header. Header http.Header // Request points to the original http.Request instance. Request *http.Request }
Info is used in meter functions to access to collected data from the response writer.
type Meter ¶
Meter provides a metrics instrumentation for vinxi Supports configurable metrics reporters and meters.
func (*Meter) AddReporter ¶
AddReporter adds one or multiple metrics reporters.
func (*Meter) Publish ¶
func (m *Meter) Publish()
Publish publishes the metrics snapshot report to the registered reporters.
func (*Meter) Register ¶
func (m *Meter) Register(mw layer.Middleware)
Register registers the metrics middleware function.
type MeterFunc ¶
MeterFunc represents the function interface to be implemented by metrics meter functions.
type Metrics ¶
type Metrics struct { // Mutex provides synchronization for thead safety. sync.Mutex // contains filtered or unexported fields }
Metrics is used to temporary store metrics data of multiple origins and nature. Provides a simple interface to write and read metric values.
Metrics is designed to be safety used by multiple goroutines.
func (*Metrics) Counter ¶
Counter returns a counter metric by key. If the counter doesn't exists, it will be transparently created.
func (*Metrics) Guage ¶
Guage returns a gauge metric by key. If the gauge doesn't exists, it will be transparently created.
func (*Metrics) Histogram ¶
Histogram returns an histrogram by key. If the histogram doesn't exists, it will be transparently created.
type Report ¶
type Report struct { // Gauges stores metrics gauges values accesible by key. Gauges map[string]int64 // Counters stores the metrics counters accesible by key. Counters map[string]uint64 }
Report is used to expose Counters and Gauges collected via Metrics.
type Reporter ¶
Reporter represents the function interface to be implemented by metrics reporters. Metric reporters are responsable of reading, filtering and adapting metrics data. Also, reporters tipically sends the metrics to an external service.
type RuntimeCollector ¶
type RuntimeCollector struct { // PauseTime represents the interval inbetween each set of stats output. // Defaults to 10 seconds. PauseTime time.Duration // EnableCPU determines whether CPU statisics will be output. Defaults to true. EnableCPU bool // EnableMem determines whether memory statistics will be output. Defaults to true. EnableMem bool // EnableGC determines whether garbage collection statistics will be output. EnableMem // must also be set to true for this to take affect. Defaults to true. EnableGC bool // Done, when closed, is used to signal RuntimeCollector that is should stop collecting // statistics and the Start function should return. If Done is set, upon shutdown // all gauges will be sent a final zero value to reset their values to 0. Done <-chan struct{} // contains filtered or unexported fields }
RuntimeCollector implements the periodic grabbing of informational data from the runtime package and outputting the values to a GaugeFunc.
func NewRuntimeCollector ¶
func NewRuntimeCollector(gaugeFunc GaugeFunc) *RuntimeCollector
NewRuntimeCollector creates a new RuntimeCollector that will periodically output statistics to gaugeFunc. It will also set the values of the exported fields to the described defaults. The values of the exported defaults can be changed at any point before Run is called.
func (*RuntimeCollector) Start ¶
func (c *RuntimeCollector) Start()
Start gathers statistics from package runtime and outputs them to the configured GaugeFunc every PauseTime. This function will not return until Done has been closed (or never if Done is nil), therefore it should be called in its own goroutine.