github.com/gogf/gf/v2@v2.7.4/os/gmetric/gmetric_provider.go (about) 1 // Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package gmetric 8 9 // GlobalProvider hold the entry for creating Meter and Metric. 10 // The GlobalProvider has only one function for Meter creating, which is designed for convenient usage. 11 type GlobalProvider interface { 12 // Meter creates and returns the Meter by given MeterOption. 13 Meter(option MeterOption) Meter 14 } 15 16 // Meter hold the functions for kinds of Metric creating. 17 type Meter interface { 18 // Counter creates and returns a new Counter. 19 Counter(name string, option MetricOption) (Counter, error) 20 21 // UpDownCounter creates and returns a new UpDownCounter. 22 UpDownCounter(name string, option MetricOption) (UpDownCounter, error) 23 24 // Histogram creates and returns a new Histogram. 25 Histogram(name string, option MetricOption) (Histogram, error) 26 27 // ObservableCounter creates and returns a new ObservableCounter. 28 ObservableCounter(name string, option MetricOption) (ObservableCounter, error) 29 30 // ObservableUpDownCounter creates and returns a new ObservableUpDownCounter. 31 ObservableUpDownCounter(name string, option MetricOption) (ObservableUpDownCounter, error) 32 33 // ObservableGauge creates and returns a new ObservableGauge. 34 ObservableGauge(name string, option MetricOption) (ObservableGauge, error) 35 36 // MustCounter creates and returns a new Counter. 37 // It panics if any error occurs. 38 MustCounter(name string, option MetricOption) Counter 39 40 // MustUpDownCounter creates and returns a new UpDownCounter. 41 // It panics if any error occurs. 42 MustUpDownCounter(name string, option MetricOption) UpDownCounter 43 44 // MustHistogram creates and returns a new Histogram. 45 // It panics if any error occurs. 46 MustHistogram(name string, option MetricOption) Histogram 47 48 // MustObservableCounter creates and returns a new ObservableCounter. 49 // It panics if any error occurs. 50 MustObservableCounter(name string, option MetricOption) ObservableCounter 51 52 // MustObservableUpDownCounter creates and returns a new ObservableUpDownCounter. 53 // It panics if any error occurs. 54 MustObservableUpDownCounter(name string, option MetricOption) ObservableUpDownCounter 55 56 // MustObservableGauge creates and returns a new ObservableGauge. 57 // It panics if any error occurs. 58 MustObservableGauge(name string, option MetricOption) ObservableGauge 59 60 // RegisterCallback registers callback on certain metrics. 61 // A callback is bound to certain component and version, it is called when the associated metrics are read. 62 // Multiple callbacks on the same component and version will be called by their registered sequence. 63 RegisterCallback(callback Callback, canBeCallbackMetrics ...ObservableMetric) error 64 65 // MustRegisterCallback performs as RegisterCallback, but it panics if any error occurs. 66 MustRegisterCallback(callback Callback, canBeCallbackMetrics ...ObservableMetric) 67 } 68 69 type localGlobalProvider struct { 70 } 71 72 var ( 73 // globalProvider is the provider for global usage. 74 globalProvider Provider 75 ) 76 77 // GetGlobalProvider retrieves the GetGlobalProvider instance. 78 func GetGlobalProvider() GlobalProvider { 79 return &localGlobalProvider{} 80 } 81 82 // SetGlobalProvider registers `provider` as the global Provider, 83 // which means the following metrics creating will be base on the global provider. 84 func SetGlobalProvider(provider Provider) { 85 globalProvider = provider 86 } 87 88 // Meter creates and returns the Meter by given MeterOption. 89 func (l *localGlobalProvider) Meter(option MeterOption) Meter { 90 return newMeter(option) 91 }