sink.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package metrics
  2. // The MetricSink interface is used to transmit metrics information
  3. // to an external system
  4. type MetricSink interface {
  5. // A Gauge should retain the last value it is set to
  6. SetGauge(key []string, val float32)
  7. // Should emit a Key/Value pair for each call
  8. EmitKey(key []string, val float32)
  9. // Counters should accumulate values
  10. IncrCounter(key []string, val float32)
  11. // Samples are for timing information, where quantiles are used
  12. AddSample(key []string, val float32)
  13. }
  14. // BlackholeSink is used to just blackhole messages
  15. type BlackholeSink struct{}
  16. func (*BlackholeSink) SetGauge(key []string, val float32) {}
  17. func (*BlackholeSink) EmitKey(key []string, val float32) {}
  18. func (*BlackholeSink) IncrCounter(key []string, val float32) {}
  19. func (*BlackholeSink) AddSample(key []string, val float32) {}
  20. // FanoutSink is used to sink to fanout values to multiple sinks
  21. type FanoutSink []MetricSink
  22. func (fh FanoutSink) SetGauge(key []string, val float32) {
  23. for _, s := range fh {
  24. s.SetGauge(key, val)
  25. }
  26. }
  27. func (fh FanoutSink) EmitKey(key []string, val float32) {
  28. for _, s := range fh {
  29. s.EmitKey(key, val)
  30. }
  31. }
  32. func (fh FanoutSink) IncrCounter(key []string, val float32) {
  33. for _, s := range fh {
  34. s.IncrCounter(key, val)
  35. }
  36. }
  37. func (fh FanoutSink) AddSample(key []string, val float32) {
  38. for _, s := range fh {
  39. s.AddSample(key, val)
  40. }
  41. }