...

Package ginmetrics

import "github.com/penglongli/gin-metrics/ginmetrics"
Overview
Index

Overview ▾

type Metric

Metric defines a metric object. Users can use it to save metric data. Every metric should be globally unique by name.

type Metric struct {
    Type        MetricType
    Name        string
    Description string
    Labels      []string
    Buckets     []float64
    Objectives  map[float64]float64
    // contains filtered or unexported fields
}

func (*Metric) Add

func (m *Metric) Add(labelValues []string, value float64) error

Add adds the given value to the Metric object. Only for Counter/Gauge type metric.

func (*Metric) Inc

func (m *Metric) Inc(labelValues []string) error

Inc increases value for Counter/Gauge type metric, increments the counter by 1

func (*Metric) Observe

func (m *Metric) Observe(labelValues []string, value float64) error

Observe is used by Histogram and Summary type metric to add observations.

func (*Metric) SetGaugeValue

func (m *Metric) SetGaugeValue(labelValues []string, value float64) error

SetGaugeValue set data for Gauge type Metric.

type MetricType

type MetricType int
const (
    None MetricType = iota
    Counter
    Gauge
    Histogram
    Summary
)

type Monitor

Monitor is an object that uses to set gin server monitor.

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

func GetMonitor

func GetMonitor() *Monitor

GetMonitor used to get global Monitor object, this function returns a singleton object.

func (*Monitor) AddMetric

func (m *Monitor) AddMetric(metric *Metric) error

AddMetric add custom monitor metric.

func (*Monitor) Expose

func (m *Monitor) Expose(r gin.IRoutes)

Expose adds metric path to a given router. The router can be different with the one passed to UseWithoutExposingEndpoint. This allows to expose metrics on different port.

func (*Monitor) GetMetric

func (m *Monitor) GetMetric(name string) *Metric

GetMetric used to get metric object by metric_name.

func (*Monitor) SetDuration

func (m *Monitor) SetDuration(duration []float64)

SetDuration set reqDuration property. reqDuration is used to ginRequestDuration metric buckets.

func (*Monitor) SetMetricPath

func (m *Monitor) SetMetricPath(path string)

SetMetricPath set metricPath property. metricPath is used for Prometheus to get gin server monitoring data.

func (*Monitor) SetMetricPrefix

func (m *Monitor) SetMetricPrefix(prefix string)

func (*Monitor) SetMetricSuffix

func (m *Monitor) SetMetricSuffix(suffix string)

func (*Monitor) SetSlowTime

func (m *Monitor) SetSlowTime(slowTime int32)

SetSlowTime set slowTime property. slowTime is used to determine whether the request is slow. For "gin_slow_request_total" metric.

func (*Monitor) Use

func (m *Monitor) Use(r gin.IRoutes)

Use set gin metrics middleware

func (*Monitor) UseWithoutExposingEndpoint

func (m *Monitor) UseWithoutExposingEndpoint(r gin.IRoutes)

UseWithoutExposingEndpoint is used to add monitor interceptor to gin router It can be called multiple times to intercept from multiple gin.IRoutes http path is not set, to do that use Expose function