github.com/hellobchain/third_party@v0.0.0-20230331131523-deb0478a2e52/hyperledger/fabric/common/metrics/provider.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package metrics 8 9 // A Provider is an abstraction for a metrics provider. It is a factory for 10 // Counter, Gauge, and Histogram meters. 11 type Provider interface { 12 // NewCounter creates a new instance of a Counter. 13 NewCounter(CounterOpts) Counter 14 // NewGauge creates a new instance of a Gauge. 15 NewGauge(GaugeOpts) Gauge 16 // NewHistogram creates a new instance of a Histogram. 17 NewHistogram(HistogramOpts) Histogram 18 } 19 20 // A Counter represents a monotonically increasing value. 21 type Counter interface { 22 // With is used to provide label values when updating a Counter. This must be 23 // used to provide values for all LabelNames provided to CounterOpts. 24 With(labelValues ...string) Counter 25 26 // Add increments a counter value. 27 Add(delta float64) 28 } 29 30 // CounterOpts is used to provide basic information about a counter to the 31 // metrics subsystem. 32 type CounterOpts struct { 33 // Namespace, Subsystem, and Name are components of the fully-qualified name 34 // of the Metric. The fully-qualified aneme is created by joining these 35 // components with an appropriate separator. Only Name is mandatory, the 36 // others merely help structuring the name. 37 Namespace string 38 Subsystem string 39 Name string 40 41 // Help provides information about this metric. 42 Help string 43 44 // LabelNames provides the names of the labels that can be attached to this 45 // metric. When a metric is recorded, label values must be provided for each 46 // of these label names. 47 LabelNames []string 48 49 // StatsdFormat determines how the fully-qualified statsd bucket name is 50 // constructed from Namespace, Subsystem, Name, and Labels. This is done by 51 // including field references in `%{reference}` escape sequences. 52 // 53 // The following reference names are supported: 54 // - #namespace - the value of Namespace 55 // - #subsystem - the value of Subsystem 56 // - #name - the value of Name 57 // - #fqname - the fully-qualified metric name 58 // - label_name - the value associated with the named label 59 // 60 // The result of the formatting must be a valid statsd bucket name. 61 StatsdFormat string 62 } 63 64 // A Gauge is a meter that expresses the current value of some metric. 65 type Gauge interface { 66 // With is used to provide label values when recording a Gauge value. This 67 // must be used to provide values for all LabelNames provided to GaugeOpts. 68 With(labelValues ...string) Gauge 69 70 // Add increments a Gauge value. 71 Add(delta float64) // TODO: consider removing 72 73 // Set is used to update the current value associted with a Gauge. 74 Set(value float64) 75 } 76 77 // GaugeOpts is used to provide basic information about a gauge to the 78 // metrics subsystem. 79 type GaugeOpts struct { 80 // Namespace, Subsystem, and Name are components of the fully-qualified name 81 // of the Metric. The fully-qualified aneme is created by joining these 82 // components with an appropriate separator. Only Name is mandatory, the 83 // others merely help structuring the name. 84 Namespace string 85 Subsystem string 86 Name string 87 88 // Help provides information about this metric. 89 Help string 90 91 // LabelNames provides the names of the labels that can be attached to this 92 // metric. When a metric is recorded, label values must be provided for each 93 // of these label names. 94 LabelNames []string 95 96 // StatsdFormat determines how the fully-qualified statsd bucket name is 97 // constructed from Namespace, Subsystem, Name, and Labels. This is done by 98 // including field references in `%{reference}` escape sequences. 99 // 100 // The following reference names are supported: 101 // - #namespace - the value of Namespace 102 // - #subsystem - the value of Subsystem 103 // - #name - the value of Name 104 // - #fqname - the fully-qualified metric name 105 // - label_name - the value associated with the named label 106 // 107 // The result of the formatting must be a valid statsd bucket name. 108 StatsdFormat string 109 } 110 111 // A Histogram is a meter that records an observed value into quantized 112 // buckets. 113 type Histogram interface { 114 // With is used to provide label values when recording a Histogram 115 // observation. This must be used to provide values for all LabelNames 116 // provided to HistogramOpts. 117 With(labelValues ...string) Histogram 118 Observe(value float64) 119 } 120 121 // HistogramOpts is used to provide basic information about a histogram to the 122 // metrics subsystem. 123 type HistogramOpts struct { 124 // Namespace, Subsystem, and Name are components of the fully-qualified name 125 // of the Metric. The fully-qualified aneme is created by joining these 126 // components with an appropriate separator. Only Name is mandatory, the 127 // others merely help structuring the name. 128 Namespace string 129 Subsystem string 130 Name string 131 132 // Help provides information about this metric. 133 Help string 134 135 // Buckets can be used to provide the bucket boundaries for Prometheus. When 136 // omitted, the default Prometheus bucket values are used. 137 Buckets []float64 138 139 // LabelNames provides the names of the labels that can be attached to this 140 // metric. When a metric is recorded, label values must be provided for each 141 // of these label names. 142 LabelNames []string 143 144 // StatsdFormat determines how the fully-qualified statsd bucket name is 145 // constructed from Namespace, Subsystem, Name, and Labels. This is done by 146 // including field references in `%{reference}` escape sequences. 147 // 148 // The following reference names are supported: 149 // - #namespace - the value of Namespace 150 // - #subsystem - the value of Subsystem 151 // - #name - the value of Name 152 // - #fqname - the fully-qualified metric name 153 // - label_name - the value associated with the named label 154 // 155 // The result of the formatting must be a valid statsd bucket name. 156 StatsdFormat string 157 }