fgaugedelta.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package event
  2. import "fmt"
  3. // FGaugeDelta - Gauges are a constant data type. They are not subject to averaging,
  4. // and they don’t change unless you change them. That is, once you set a gauge value,
  5. // it will be a flat line on the graph until you change it again
  6. type FGaugeDelta struct {
  7. Name string
  8. Value float64
  9. }
  10. // Update the event with metrics coming from a new one of the same type and with the same key
  11. func (e *FGaugeDelta) Update(e2 Event) error {
  12. if e.Type() != e2.Type() {
  13. return fmt.Errorf("statsd event type conflict: %s vs %s ", e.String(), e2.String())
  14. }
  15. e.Value += e2.Payload().(float64)
  16. return nil
  17. }
  18. // Payload returns the aggregated value for this event
  19. func (e FGaugeDelta) Payload() interface{} {
  20. return e.Value
  21. }
  22. // Stats returns an array of StatsD events as they travel over UDP
  23. func (e FGaugeDelta) Stats() []string {
  24. return []string{fmt.Sprintf("%s:%+g|g", e.Name, e.Value)}
  25. }
  26. // Key returns the name of this metric
  27. func (e FGaugeDelta) Key() string {
  28. return e.Name
  29. }
  30. // SetKey sets the name of this metric
  31. func (e *FGaugeDelta) SetKey(key string) {
  32. e.Name = key
  33. }
  34. // Type returns an integer identifier for this type of metric
  35. func (e FGaugeDelta) Type() int {
  36. return EventFGaugeDelta
  37. }
  38. // TypeString returns a name for this type of metric
  39. func (e FGaugeDelta) TypeString() string {
  40. return "FGaugeDelta"
  41. }
  42. // String returns a debug-friendly representation of this metric
  43. func (e FGaugeDelta) String() string {
  44. return fmt.Sprintf("{Type: %s, Key: %s, Value: %g}", e.TypeString(), e.Name, e.Value)
  45. }