@@ -127,8 +127,12 @@ func L(name string, value string) metrics.Label {
127
127
//
128
128
// metriks.Inc("publisher.errors", 1)
129
129
//
130
- func Inc (name string , val int64 ) {
131
- metrics .IncrCounter ([]string {name }, float32 (val ))
130
+ func Inc (name string , val int64 , labels ... metrics.Label ) {
131
+ if len (labels ) > 0 {
132
+ metrics .IncrCounterWithLabels ([]string {name }, float32 (val ), labels )
133
+ } else {
134
+ metrics .IncrCounter ([]string {name }, float32 (val ))
135
+ }
132
136
}
133
137
134
138
// IncLabels increments a counter with additional labels
@@ -138,7 +142,7 @@ func Inc(name string, val int64) {
138
142
// metriks.IncLabels("publisher.errors", metriks.Labels(metriks.L("status_class", "4xx")), 1)
139
143
//
140
144
func IncLabels (name string , labels []metrics.Label , val int64 ) {
141
- metrics . IncrCounterWithLabels ([] string { name }, float32 ( val ) , labels )
145
+ Inc ( name , val , labels ... )
142
146
}
143
147
144
148
// MeasureSince records the time from start until the invocation of the function
@@ -153,13 +157,17 @@ func IncLabels(name string, labels []metrics.Label, val int64) {
153
157
// return db.Execute(query)
154
158
// }
155
159
//
156
- func MeasureSince (name string , start time.Time ) {
157
- metrics .MeasureSince ([]string {name }, start )
160
+ func MeasureSince (name string , start time.Time , labels ... metrics.Label ) {
161
+ if len (labels ) > 0 {
162
+ metrics .MeasureSinceWithLabels ([]string {name }, start , labels )
163
+ } else {
164
+ metrics .MeasureSince ([]string {name }, start )
165
+ }
158
166
}
159
167
160
168
// MeasureSinceLabels is the same as MeasureSince, but with additional labels
161
169
func MeasureSinceLabels (name string , labels []metrics.Label , start time.Time ) {
162
- metrics . MeasureSinceWithLabels ([] string { name } , start , labels )
170
+ MeasureSince ( name , start , labels ... )
163
171
}
164
172
165
173
// Sample records a float32 sample as part of a histogram. This will get histogram
@@ -169,25 +177,33 @@ func MeasureSinceLabels(name string, labels []metrics.Label, start time.Time) {
169
177
//
170
178
// metriks.Sample("publisher-payload-size", float32(len(payload)))
171
179
//
172
- func Sample (name string , val float32 ) {
173
- metrics .AddSample ([]string {name }, val )
180
+ func Sample (name string , val float32 , labels ... metrics.Label ) {
181
+ if len (labels ) > 0 {
182
+ metrics .AddSampleWithLabels ([]string {name }, val , labels )
183
+ } else {
184
+ metrics .AddSample ([]string {name }, val )
185
+ }
174
186
}
175
187
176
188
// SampleLabels is the same as Sample but with additional labels
177
189
func SampleLabels (name string , labels []metrics.Label , val float32 ) {
178
- metrics . AddSampleWithLabels ([] string { name } , val , labels )
190
+ Sample ( name , val , labels ... )
179
191
}
180
192
181
193
// Gauge is used to report a single float32 value. It is most often used during a
182
194
// periodic update or timer to report the current size of a queue or how many
183
195
// connections are currently connected.
184
- func Gauge (name string , val float32 ) {
185
- metrics .SetGauge ([]string {name }, val )
196
+ func Gauge (name string , val float32 , labels ... metrics.Label ) {
197
+ if len (labels ) > 0 {
198
+ metrics .SetGaugeWithLabels ([]string {name }, val , labels )
199
+ } else {
200
+ metrics .SetGauge ([]string {name }, val )
201
+ }
186
202
}
187
203
188
204
// GaugeLabels is the same as Gauge but with additional labels
189
205
func GaugeLabels (name string , labels []metrics.Label , val float32 ) {
190
- metrics . SetGaugeWithLabels ([] string { name } , val , labels )
206
+ Gauge ( name , val , labels ... )
191
207
}
192
208
193
209
func statsdAddr (conf Config ) string {
0 commit comments