github.com/Jeffail/benthos/v3@v3.65.0/lib/metrics/type.go (about)

     1  package metrics
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/Jeffail/benthos/v3/lib/log"
     7  )
     8  
     9  //------------------------------------------------------------------------------
    10  
    11  // StatCounter is a representation of a single counter metric stat. Interactions
    12  // with this stat are thread safe.
    13  type StatCounter interface {
    14  	// Incr increments a counter by an amount.
    15  	Incr(count int64) error
    16  }
    17  
    18  // StatTimer is a representation of a single timer metric stat. Interactions
    19  // with this stat are thread safe.
    20  type StatTimer interface {
    21  	// Timing sets a timing metric.
    22  	Timing(delta int64) error
    23  }
    24  
    25  // StatGauge is a representation of a single gauge metric stat. Interactions
    26  // with this stat are thread safe.
    27  type StatGauge interface {
    28  	// Set sets the value of a gauge metric.
    29  	Set(value int64) error
    30  
    31  	// Incr increments a gauge by an amount.
    32  	Incr(count int64) error
    33  
    34  	// Decr decrements a gauge by an amount.
    35  	Decr(count int64) error
    36  }
    37  
    38  //------------------------------------------------------------------------------
    39  
    40  // StatCounterVec creates StatCounters with dynamic labels.
    41  type StatCounterVec interface {
    42  	// With returns a StatCounter with a set of label values.
    43  	With(labelValues ...string) StatCounter
    44  }
    45  
    46  // StatTimerVec creates StatTimers with dynamic labels.
    47  type StatTimerVec interface {
    48  	// With returns a StatTimer with a set of label values.
    49  	With(labelValues ...string) StatTimer
    50  }
    51  
    52  // StatGaugeVec creates StatGauges with dynamic labels.
    53  type StatGaugeVec interface {
    54  	// With returns a StatGauge with a set of label values.
    55  	With(labelValues ...string) StatGauge
    56  }
    57  
    58  //------------------------------------------------------------------------------
    59  
    60  // Type is an interface for metrics aggregation.
    61  type Type interface {
    62  	// GetCounter returns an editable counter stat for a given path.
    63  	GetCounter(path string) StatCounter
    64  
    65  	// GetCounterVec returns an editable counter stat for a given path with
    66  	// labels, these labels must be consistent with any other metrics registered
    67  	// on the same path.
    68  	GetCounterVec(path string, labelNames []string) StatCounterVec
    69  
    70  	// GetTimer returns an editable timer stat for a given path.
    71  	GetTimer(path string) StatTimer
    72  
    73  	// GetTimerVec returns an editable timer stat for a given path with labels,
    74  	// these labels must be consistent with any other metrics registered on the
    75  	// same path.
    76  	GetTimerVec(path string, labelNames []string) StatTimerVec
    77  
    78  	// GetGauge returns an editable gauge stat for a given path.
    79  	GetGauge(path string) StatGauge
    80  
    81  	// GetGaugeVec returns an editable gauge stat for a given path with labels,
    82  	// these labels must be consistent with any other metrics registered on the
    83  	// same path.
    84  	GetGaugeVec(path string, labelNames []string) StatGaugeVec
    85  
    86  	// SetLogger sets the logging mechanism of the metrics type.
    87  	SetLogger(log log.Modular)
    88  
    89  	// Close stops aggregating stats and cleans up resources.
    90  	Close() error
    91  }
    92  
    93  //------------------------------------------------------------------------------
    94  
    95  // WithHandlerFunc is an interface for metrics types that can expose their
    96  // metrics through an HTTP HandlerFunc endpoint. If a Type can be cast into
    97  // WithHandlerFunc then you should register its endpoint to the an HTTP server.
    98  type WithHandlerFunc interface {
    99  	HandlerFunc() http.HandlerFunc
   100  }
   101  
   102  //------------------------------------------------------------------------------