1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
///Internal macro to register metric description when provided by metric creation macro
};
}
/// Registers a counter.
///
/// Counters represent a single monotonic value, which means the value can only be incremented, not decremented, and
/// always starts out with an initial value of zero.
///
/// A handle to the counter -- [`Counter`](crate::Counter) -- is returned by this macro and can be held on to in order
/// to amortize the cost of registration.
///
/// # Usage
///
/// `counter!([named_param: value,] <$name,> [$labels,])`
///
/// Only a name is required to initialize a counter.
///
/// Named parameters must always come before the counter name, and the counter name must come before any labels.
///
/// ## Required parameters
///
/// - `$name` - Name of the counter. Must be a string literal or an expression that results in `String` or `&'static str`.
///
/// ## Named Parameters
///
/// The following parameters can be provided in any order relative to other named parameters:
///
/// - `target:` - Module path of the counter. Defaults to `::core::module_path!()`.
/// - `level:` - Verbosity level of the counter. Defaults to `INFO`.
/// - `description:` - Description of the counter. If specified, `$name` will be used twice.
/// - `unit:` - Unit of measurement of the counter. Description must be provided in order to specify units.
///
/// ## Labels
///
/// Labels can be passed as _one_ of following:
///
/// - Arbitrary number of `<key> => <value>` where `key` and `value` can be a string literal or an expression that results in `String` or `&'static str`.
/// - Static reference to collection of **Label**.
/// - Collection/iterator that implements [IntoLabels](trait.IntoLabels.html).
///
/// # Example
/// ```
/// # #![no_implicit_prelude]
/// # use ::std::convert::From;
/// # use ::std::format;
/// # use ::std::string::String;
/// # use metrics::counter;
/// # fn main() {
/// // A basic counter:
/// let counter = counter!("some_metric_name");
/// counter.increment(1);
///
/// // Specifying labels inline, including using constants for either the key or value:
/// let counter = counter!("some_metric_name", "service" => "http");
/// counter.absolute(42);
///
/// const SERVICE_LABEL: &'static str = "service";
/// const SERVICE_HTTP: &'static str = "http";
/// let counter = counter!("some_metric_name", SERVICE_LABEL => SERVICE_HTTP);
/// counter.increment(123);
///
/// // We can also pass labels by giving a vector or slice of key/value pairs. In this scenario,
/// // a unit or description can still be passed in their respective positions:
/// let dynamic_val = "woo";
/// let labels = [("dynamic_key", format!("{}!", dynamic_val))];
/// let counter = counter!("some_metric_name", &labels);
///
/// // As mentioned in the documentation, metric names also can be owned strings, including ones
/// // generated at the callsite via things like `format!`:
/// let name = String::from("some_owned_metric_name");
/// let counter = counter!(name);
///
/// let counter = counter!(format!("{}_via_format", "name"));
///
/// // Using all of the above, we can customize the counter's description, unit, target, and level:
/// let counter = counter!(
/// description: "super counter",
/// unit: metrics::Unit::Bytes,
/// target: ::core::module_path!(),
/// level: metrics::Level::INFO,
/// "super_counter",
/// "label1" => "value1",
/// "label2" => "value2"
/// );
/// # }
/// ```
/// Registers a gauge.
///
/// Gauges represent a single value that can go up or down over time, and always starts out with an initial value of
/// zero.
///
/// A handle to the gauge -- [`Gauge`](crate::Gauge) -- is returned by this macro and can be held on to in order to
/// amortize the cost of registration.
///
/// # Usage
///
/// `gauge!([named_param: value,] <$name,> [$labels,])`
///
/// Only a name is required to initialize a gauge.
///
/// Named parameters must always come before the gauge name, and the gauge name must come before any labels.
///
/// ## Required parameters
///
/// - `$name` - Name of the gauge. Must be a string literal or an expression that results in `String` or `&'static str`.
///
/// ## Named Parameters
///
/// The following parameters can be provided in any order relative to other named parameters:
///
/// - `target:` - Module path of the gauge. Defaults to `::core::module_path!()`.
/// - `level:` - Verbosity level of the gauge. Defaults to `INFO`.
/// - `description:` - Description of the gauge. If specified, `$name` will be used twice.
/// - `unit:` - Unit of measurement of the gauge. Description must be provided in order to specify units.
///
/// ## Labels
///
/// Labels can be passed as _one_ of following:
///
/// - Arbitrary number of `<key> => <value>` where `key` and `value` can be a string literal or an expression that results in `String` or `&'static str`.
/// - Static reference to collection of **Label**.
/// - Collection/iterator that implements [IntoLabels](trait.IntoLabels.html).
///
/// # Example
/// ```
/// # #![no_implicit_prelude]
/// # use ::std::string::String;
/// # use ::std::format;
/// # use ::std::convert::From;
/// # use metrics::gauge;
/// # fn main() {
/// // A basic gauge:
/// let gauge = gauge!("some_metric_name");
/// gauge.increment(1.0);
///
/// // Specifying labels inline, including using constants for either the key or value:
/// let gauge = gauge!("some_metric_name", "service" => "http");
/// gauge.decrement(42.0);
///
/// const SERVICE_LABEL: &'static str = "service";
/// const SERVICE_HTTP: &'static str = "http";
/// let gauge = gauge!("some_metric_name", SERVICE_LABEL => SERVICE_HTTP);
/// gauge.increment(3.14);
///
/// // We can also pass labels by giving a vector or slice of key/value pairs. In this scenario,
/// // a unit or description can still be passed in their respective positions:
/// let dynamic_val = "woo";
/// let labels = [("dynamic_key", format!("{}!", dynamic_val))];
/// let gauge = gauge!("some_metric_name", &labels);
/// gauge.set(1337.0);
///
/// // As mentioned in the documentation, metric names also can be owned strings, including ones
/// // generated at the callsite via things like `format!`:
/// let name = String::from("some_owned_metric_name");
/// let gauge = gauge!(name);
///
/// let gauge = gauge!(format!("{}_via_format", "name"));
///
/// // Using all of the above, we can customize the gauge's description, unit, target, and level:
/// let gauge = gauge!(
/// description: "super gauge",
/// unit: metrics::Unit::Bytes,
/// target: ::core::module_path!(),
/// level: metrics::Level::INFO,
/// "super_gauge",
/// "label1" => "value1",
/// "label2" => "value2"
/// );
/// # }
/// ```
/// Registers a histogram.
///
/// Histograms measure the distribution of values for a given set of measurements, and start with no initial values.
///
/// A handle to the histogram -- [`Histogram`](crate::Histogram) -- is returned by this macro and can be held on to in
/// order to amortize the cost of registration.
///
/// # Usage
///
/// `histogram!([named_param: value,] <$name,> [$labels,])`
///
/// Only a name is required to initialize a histogram.
///
/// Named parameters must always come before the histogram name, and the histogram name must come before any labels.
///
/// ## Required parameters
///
/// - `$name` - Name of the histogram. Must be a string literal or an expression that results in `String` or `&'static str`.
///
/// ## Named Parameters
///
/// The following parameters can be provided in any order relative to other named parameters:
///
/// - `target:` - Module path of the histogram. Defaults to `::core::module_path!()`.
/// - `level:` - Verbosity level of the histogram. Defaults to `INFO`.
/// - `description:` - Description of the histogram. If specified, `$name` will be used twice.
/// - `unit:` - Unit of measurement of the histogram. Description must be provided in order to specify units.
///
/// ## Labels
///
/// Labels can be passed as _one_ of following:
///
/// - Arbitrary number of `<key> => <value>` where `key` and `value` can be a string literal or an expression that results in `String` or `&'static str`.
/// - Static reference to collection of **Label**.
/// - Collection/iterator that implements [IntoLabels](trait.IntoLabels.html).
///
/// # Example
/// ```
/// # #![no_implicit_prelude]
/// # use ::std::string::String;
/// # use ::std::format;
/// # use ::std::convert::From;
/// # use metrics::histogram;
/// # fn main() {
/// // A basic histogram:
/// let histogram = histogram!("some_metric_name");
/// histogram.record(1.0);
///
/// // Specifying labels inline, including using constants for either the key or value:
/// let histogram = histogram!("some_metric_name", "service" => "http");
///
/// const SERVICE_LABEL: &'static str = "service";
/// const SERVICE_HTTP: &'static str = "http";
/// let histogram = histogram!("some_metric_name", SERVICE_LABEL => SERVICE_HTTP);
///
/// // We can also pass labels by giving a vector or slice of key/value pairs. In this scenario,
/// // a unit or description can still be passed in their respective positions:
/// let dynamic_val = "woo";
/// let labels = [("dynamic_key", format!("{}!", dynamic_val))];
/// let histogram = histogram!("some_metric_name", &labels);
///
/// // As mentioned in the documentation, metric names also can be owned strings, including ones
/// // generated at the callsite via things like `format!`:
/// let name = String::from("some_owned_metric_name");
/// let histogram = histogram!(name);
///
/// let histogram = histogram!(format!("{}_via_format", "name"));
///
/// // Using all of the above, we can customize the histogram's description, unit, target, and level:
/// let histogram = histogram!(
/// description: "super histogram",
/// unit: metrics::Unit::Bytes,
/// target: ::core::module_path!(),
/// level: metrics::Level::INFO,
/// "super_histogram",
/// "label1" => "value1",
/// "label2" => "value2"
/// );
/// # }
/// ```
/// Describes a counter.
///
/// Counters represent a single monotonic value, which means the value can only be incremented, not decremented, and
/// always starts out with an initial value of zero.
///
/// Counters can be described with a free-form string, and optionally, a unit can be provided to describe the value
/// and/or rate of the measurements. Whether or not the installed recorder does anything with the description, or
/// optional unit, is implementation defined.
///
/// # Example
/// ```
/// # #![no_implicit_prelude]
/// # use ::std::convert::From;
/// # use ::std::format;
/// # use ::std::string::String;
/// # use metrics::describe_counter;
/// # use metrics::Unit;
/// # fn main() {
/// // A basic counter:
/// describe_counter!("some_metric_name", "my favorite counter");
///
/// // Providing a unit for a counter:
/// describe_counter!("some_metric_name", Unit::Bytes, "my favorite counter");
///
/// // As mentioned in the documentation, metric names also can be owned strings, including ones
/// // generated at the callsite via things like `format!`:
/// let name = String::from("some_owned_metric_name");
/// describe_counter!(name, "my favorite counter");
///
/// describe_counter!(format!("{}_via_format", "name"), "my favorite counter");
/// # }
/// ```
/// Describes a gauge.
///
/// Gauges represent a single value that can go up or down over time, and always starts out with an
/// initial value of zero.
///
/// Gauges can be described with a free-form string, and optionally, a unit can be provided to describe the value
/// and/or rate of the measurements. Whether or not the installed recorder does anything with the description, or
/// optional unit, is implementation defined.
///
/// # Example
/// ```
/// # #![no_implicit_prelude]
/// # use ::std::convert::From;
/// # use ::std::format;
/// # use ::std::string::String;
/// # use metrics::describe_gauge;
/// # use metrics::Unit;
/// # fn main() {
/// // A basic gauge:
/// describe_gauge!("some_metric_name", "my favorite gauge");
///
/// // Providing a unit for a gauge:
/// describe_gauge!("some_metric_name", Unit::Bytes, "my favorite gauge");
///
/// // As mentioned in the documentation, metric names also can be owned strings, including ones
/// // generated at the callsite via things like `format!`:
/// let name = String::from("some_owned_metric_name");
/// describe_gauge!(name, "my favorite gauge");
///
/// describe_gauge!(format!("{}_via_format", "name"), "my favorite gauge");
/// # }
/// ```
/// Describes a histogram.
///
/// Histograms measure the distribution of values for a given set of measurements, and start with no
/// initial values.
///
/// Histograms can be described with a free-form string, and optionally, a unit can be provided to describe the value
/// and/or rate of the measurements. Whether or not the installed recorder does anything with the description, or
/// optional unit, is implementation defined.
///
/// # Example
/// ```
/// # #![no_implicit_prelude]
/// # use ::std::convert::From;
/// # use ::std::format;
/// # use ::std::string::String;
/// # use metrics::describe_histogram;
/// # use metrics::Unit;
/// # fn main() {
/// // A basic histogram:
/// describe_histogram!("some_metric_name", "my favorite histogram");
///
/// // Providing a unit for a histogram:
/// describe_histogram!("some_metric_name", Unit::Bytes, "my favorite histogram");
///
/// // As mentioned in the documentation, metric names also can be owned strings, including ones
/// // generated at the callsite via things like `format!`:
/// let name = String::from("some_owned_metric_name");
/// describe_histogram!(name, "my favorite histogram");
///
/// describe_histogram!(format!("{}_via_format", "name"), "my favorite histogram");
/// # }
/// ```