metric.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2015 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package v1
  15. import (
  16. "time"
  17. )
  18. // Type of metric being exported.
  19. type MetricType string
  20. const (
  21. // Instantaneous value. May increase or decrease.
  22. MetricGauge MetricType = "gauge"
  23. // A counter-like value that is only expected to increase.
  24. MetricCumulative MetricType = "cumulative"
  25. // Rate over a time period.
  26. MetricDelta MetricType = "delta"
  27. )
  28. // DataType for metric being exported.
  29. type DataType string
  30. const (
  31. IntType DataType = "int"
  32. FloatType DataType = "float"
  33. )
  34. // Spec for custom metric.
  35. type MetricSpec struct {
  36. // The name of the metric.
  37. Name string `json:"name"`
  38. // Type of the metric.
  39. Type MetricType `json:"type"`
  40. // Data Type for the stats.
  41. Format DataType `json:"format"`
  42. // Display Units for the stats.
  43. Units string `json:"units"`
  44. }
  45. // An exported metric.
  46. type MetricValBasic struct {
  47. // Time at which the metric was queried
  48. Timestamp time.Time `json:"timestamp"`
  49. // The value of the metric at this point.
  50. IntValue int64 `json:"int_value,omitempty"`
  51. FloatValue float64 `json:"float_value,omitempty"`
  52. }
  53. // An exported metric.
  54. type MetricVal struct {
  55. // Label associated with a metric
  56. Label string `json:"label,omitempty"`
  57. // Time at which the metric was queried
  58. Timestamp time.Time `json:"timestamp"`
  59. // The value of the metric at this point.
  60. IntValue int64 `json:"int_value,omitempty"`
  61. FloatValue float64 `json:"float_value,omitempty"`
  62. }