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

     1  package metrics
     2  
     3  import "github.com/Jeffail/benthos/v3/lib/log"
     4  
     5  //------------------------------------------------------------------------------
     6  
     7  // namespacedWrapper wraps an existing Type under a namespace. The full path of
     8  // subsequent metrics under this type will be:
     9  //
    10  // Underlying prefix + this namespace + path of metric
    11  type namespacedWrapper struct {
    12  	ns string
    13  	t  Type
    14  }
    15  
    16  // Namespaced embeds an existing metrics aggregator under a new namespace. The
    17  // prefix of the embedded aggregator is still the ultimate prefix of metrics.
    18  func Namespaced(t Type, ns string) Type {
    19  	return namespacedWrapper{
    20  		ns: ns,
    21  		t:  t,
    22  	}
    23  }
    24  
    25  // Unwrap to the underlying metrics type.
    26  // TODO: V4 make this standard for Type
    27  func (d namespacedWrapper) Unwrap() Type {
    28  	return unwrapMetric(d.t)
    29  }
    30  
    31  //------------------------------------------------------------------------------
    32  
    33  func (d namespacedWrapper) GetCounter(path string) StatCounter {
    34  	return d.t.GetCounter(d.ns + "." + path)
    35  }
    36  
    37  func (d namespacedWrapper) GetCounterVec(path string, labelNames []string) StatCounterVec {
    38  	return d.t.GetCounterVec(d.ns+"."+path, labelNames)
    39  }
    40  
    41  func (d namespacedWrapper) GetTimer(path string) StatTimer {
    42  	return d.t.GetTimer(d.ns + "." + path)
    43  }
    44  
    45  func (d namespacedWrapper) GetTimerVec(path string, labelNames []string) StatTimerVec {
    46  	return d.t.GetTimerVec(d.ns+"."+path, labelNames)
    47  }
    48  
    49  func (d namespacedWrapper) GetGauge(path string) StatGauge {
    50  	return d.t.GetGauge(d.ns + "." + path)
    51  }
    52  
    53  func (d namespacedWrapper) GetGaugeVec(path string, labelNames []string) StatGaugeVec {
    54  	return d.t.GetGaugeVec(d.ns+"."+path, labelNames)
    55  }
    56  
    57  func (d namespacedWrapper) SetLogger(log log.Modular) {
    58  	d.t.SetLogger(log.NewModule(d.ns))
    59  }
    60  
    61  func (d namespacedWrapper) Close() error {
    62  	return d.t.Close()
    63  }
    64  
    65  //------------------------------------------------------------------------------