1+ //! This module contains wrapper to prometheus metrics for use in a metrics service.
2+
13use prometheus:: { core:: Collector , Counter , Gauge , Opts } ;
24use slog:: { debug, Logger } ;
35
@@ -26,6 +28,7 @@ pub struct MetricCounter {
2628}
2729
2830impl MetricCounter {
31+ /// Create a new metric counter.
2932 pub fn new ( logger : Logger , name : & str , help : & str ) -> StdResult < Self > {
3033 let counter = MetricCounter :: create_metric_counter ( name, help) ?;
3134 Ok ( Self {
@@ -35,11 +38,13 @@ impl MetricCounter {
3538 } )
3639 }
3740
41+ /// Increment the counter.
3842 pub fn increment ( & self ) {
3943 debug ! ( self . logger, "Incrementing '{}' counter" , self . name) ;
4044 self . counter . inc ( ) ;
4145 }
4246
47+ /// Get the counter value.
4348 pub fn get ( & self ) -> CounterValue {
4449 self . counter . get ( ) . round ( ) as CounterValue
4550 }
@@ -70,6 +75,7 @@ pub struct MetricGauge {
7075}
7176
7277impl MetricGauge {
78+ /// Create a new metric gauge.
7379 pub fn new ( logger : Logger , name : & str , help : & str ) -> StdResult < Self > {
7480 let gauge = MetricGauge :: create_metric_gauge ( name, help) ?;
7581 Ok ( Self {
@@ -79,6 +85,7 @@ impl MetricGauge {
7985 } )
8086 }
8187
88+ /// Record a value in the gauge.
8289 pub fn record < T : Into < f64 > + Copy > ( & self , value : T ) {
8390 debug ! (
8491 self . logger,
@@ -89,6 +96,7 @@ impl MetricGauge {
8996 self . gauge . set ( value. into ( ) ) ;
9097 }
9198
99+ /// Get the gauge value.
92100 pub fn get ( & self ) -> f64 {
93101 self . gauge . get ( ) . round ( )
94102 }
0 commit comments