metrics.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Package metrics provides both a means of generating metrics and the ability
  2. // to send metric data to a graphite endpoint.
  3. // The usage of this package without providing a graphite_addr when calling
  4. // NewBucket results in NOP metric objects. No data will be collected.
  5. package metrics
  6. import (
  7. "io"
  8. gometrics "github.com/coreos/etcd/third_party/github.com/rcrowley/go-metrics"
  9. )
  10. type Timer gometrics.Timer
  11. type Gauge gometrics.Gauge
  12. type Bucket interface {
  13. // If a timer exists in this Bucket, return it. Otherwise, create
  14. // a new timer with the given name and store it in this Bucket.
  15. // The returned object will fulfull the Timer interface.
  16. Timer(name string) Timer
  17. // This acts similarly to Timer, but with objects that fufill the
  18. // Gauge interface.
  19. Gauge(name string) Gauge
  20. // Write the current state of all Metrics in a human-readable format
  21. // to the provide io.Writer.
  22. Dump(io.Writer)
  23. // Instruct the Bucket to periodically push all metric data to the
  24. // provided graphite endpoint.
  25. Publish(string) error
  26. }
  27. // Create a new Bucket object that periodically
  28. func NewBucket(name string) Bucket {
  29. if name == "" {
  30. return nilBucket{}
  31. }
  32. return newStandardBucket(name)
  33. }