Open
Description
In order to avoid data race on GetMonitor()
, gin-metrics has to use sync.Once
or sync.Mutex
.
For example with sync.Once
:
var (
defaultDuration = []float64{0.1, 0.3, 1.2, 5, 10}
monitor *Monitor
onceMonitor sync.Once
promTypeHandler = map[MetricType]func(metric *Metric) error{
Counter: counterHandler,
Gauge: gaugeHandler,
Histogram: histogramHandler,
Summary: summaryHandler,
}
)
// GetMonitor used to get global Monitor object,
// this function returns a singleton object.
func GetMonitor() *Monitor {
onceMonitor.Do(
func() {
monitor = &Monitor{
metricPath: defaultMetricPath,
slowTime: defaultSlowTime,
reqDuration: defaultDuration,
metrics: make(map[string]*Metric),
}
}
return monitor
}
Metadata
Metadata
Assignees
Labels
No labels