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 (m *Metric) Add(labelValues []string, value float64) error
Add adds the given value to the Metric object. Only for Counter/Gauge type metric.
func (m *Metric) Inc(labelValues []string) error
Inc increases value for Counter/Gauge type metric, increments the counter by 1
func (m *Metric) Observe(labelValues []string, value float64) error
Observe is used by Histogram and Summary type metric to add observations.
func (m *Metric) SetGaugeValue(labelValues []string, value float64) error
SetGaugeValue set data for Gauge type Metric.
type MetricType int
const ( None MetricType = iota Counter Gauge Histogram Summary )
Monitor is an object that uses to set gin server monitor.
type Monitor struct {
// contains filtered or unexported fields
}
func GetMonitor() *Monitor
GetMonitor used to get global Monitor object, this function returns a singleton object.
func (m *Monitor) AddMetric(metric *Metric) error
AddMetric add custom monitor metric.
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 (m *Monitor) GetMetric(name string) *Metric
GetMetric used to get metric object by metric_name.
func (m *Monitor) SetDuration(duration []float64)
SetDuration set reqDuration property. reqDuration is used to ginRequestDuration metric buckets.
func (m *Monitor) SetMetricPath(path string)
SetMetricPath set metricPath property. metricPath is used for Prometheus to get gin server monitoring data.
func (m *Monitor) SetMetricPrefix(prefix string)
func (m *Monitor) SetMetricSuffix(suffix string)
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 (m *Monitor) Use(r gin.IRoutes)
Use set gin metrics middleware
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