diff options
Diffstat (limited to 'vendor/github.com/armon/go-metrics/circonus')
-rw-r--r-- | vendor/github.com/armon/go-metrics/circonus/circonus.go | 27 | ||||
-rw-r--r-- | vendor/github.com/armon/go-metrics/circonus/circonus_test.go | 4 |
2 files changed, 29 insertions, 2 deletions
diff --git a/vendor/github.com/armon/go-metrics/circonus/circonus.go b/vendor/github.com/armon/go-metrics/circonus/circonus.go index c6e3974b5..eb41b9945 100644 --- a/vendor/github.com/armon/go-metrics/circonus/circonus.go +++ b/vendor/github.com/armon/go-metrics/circonus/circonus.go @@ -5,6 +5,7 @@ package circonus import ( "strings" + "github.com/armon/go-metrics" cgm "github.com/circonus-labs/circonus-gometrics" ) @@ -61,6 +62,12 @@ func (s *CirconusSink) SetGauge(key []string, val float32) { s.metrics.SetGauge(flatKey, int64(val)) } +// SetGaugeWithLabels sets value for a gauge metric with the given labels +func (s *CirconusSink) SetGaugeWithLabels(key []string, val float32, labels []metrics.Label) { + flatKey := s.flattenKeyLabels(key, labels) + s.metrics.SetGauge(flatKey, int64(val)) +} + // EmitKey is not implemented in circonus func (s *CirconusSink) EmitKey(key []string, val float32) { // NOP @@ -72,12 +79,24 @@ func (s *CirconusSink) IncrCounter(key []string, val float32) { s.metrics.IncrementByValue(flatKey, uint64(val)) } +// IncrCounterWithLabels increments a counter metric with the given labels +func (s *CirconusSink) IncrCounterWithLabels(key []string, val float32, labels []metrics.Label) { + flatKey := s.flattenKeyLabels(key, labels) + s.metrics.IncrementByValue(flatKey, uint64(val)) +} + // AddSample adds a sample to a histogram metric func (s *CirconusSink) AddSample(key []string, val float32) { flatKey := s.flattenKey(key) s.metrics.RecordValue(flatKey, float64(val)) } +// AddSampleWithLabels adds a sample to a histogram metric with the given labels +func (s *CirconusSink) AddSampleWithLabels(key []string, val float32, labels []metrics.Label) { + flatKey := s.flattenKeyLabels(key, labels) + s.metrics.RecordValue(flatKey, float64(val)) +} + // Flattens key to Circonus metric name func (s *CirconusSink) flattenKey(parts []string) string { joined := strings.Join(parts, "`") @@ -90,3 +109,11 @@ func (s *CirconusSink) flattenKey(parts []string) string { } }, joined) } + +// Flattens the key along with labels for formatting, removes spaces +func (s *CirconusSink) flattenKeyLabels(parts []string, labels []metrics.Label) string { + for _, label := range labels { + parts = append(parts, label.Value) + } + return s.flattenKey(parts) +} diff --git a/vendor/github.com/armon/go-metrics/circonus/circonus_test.go b/vendor/github.com/armon/go-metrics/circonus/circonus_test.go index 234a3cb89..4eb76e411 100644 --- a/vendor/github.com/armon/go-metrics/circonus/circonus_test.go +++ b/vendor/github.com/armon/go-metrics/circonus/circonus_test.go @@ -12,7 +12,7 @@ import ( func TestNewCirconusSink(t *testing.T) { // test with invalid config (nil) - expectedError := errors.New("Invalid check manager configuration (no API token AND no submission url).") + expectedError := errors.New("invalid check manager configuration (no API token AND no submission url)") _, err := NewCirconusSink(nil) if err == nil || err.Error() != expectedError.Error() { t.Errorf("Expected an '%#v' error, got '%#v'", expectedError, err) @@ -87,7 +87,7 @@ func TestSetGauge(t *testing.T) { cs.Flush() }() - expect := "{\"foo`bar\":{\"_type\":\"n\",\"_value\":1}}" + expect := "{\"foo`bar\":{\"_type\":\"n\",\"_value\":\"1\"}}" actual := <-q if actual != expect { |