metrics

package
v0.0.0-...-0ad4d90 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	None MetricType = iota
	Counter
	Gauge
	Histogram
	Summary

	MetricRequestTotal    = "gin_request_total"
	MetricRequestUVTotal  = "gin_request_uv_total"
	MetricURIRequestTotal = "gin_uri_request_total"
	MetricRequestBody     = "gin_request_body_total"
	MetricResponseBody    = "gin_response_body_total"
	MetricRequestDuration = "gin_request_duration"
	MetricSlowRequest     = "gin_slow_request_total"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Metric

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

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

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

type 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) 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 sets the reqDuration property. reqDuration is used to ginRequestDuration metric buckets.

func (*Monitor) SetMetricPath

func (m *Monitor) SetMetricPath(path string)

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

func (*Monitor) SetMetricPort

func (m *Monitor) SetMetricPort(port int)

SetMetricPort sets the metricPort property. metricPort is to expose the metrics

func (*Monitor) SetSlowTime

func (m *Monitor) SetSlowTime(slowTime int32)

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

func (*Monitor) Start

func (m *Monitor) Start()

func (*Monitor) Use

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

Use set gin metrics middleware

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL