metric.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. )
  26. // DataType for metric being exported.
  27. type DataType string
  28. const (
  29. IntType DataType = "int"
  30. FloatType DataType = "float"
  31. )
  32. // Spec for custom metric.
  33. type MetricSpec struct {
  34. // The name of the metric.
  35. Name string `json:"name"`
  36. // Type of the metric.
  37. Type MetricType `json:"type"`
  38. // Data Type for the stats.
  39. Format DataType `json:"format"`
  40. // Display Units for the stats.
  41. Units string `json:"units"`
  42. }
  43. // An exported metric.
  44. type MetricValBasic struct {
  45. // Time at which the metric was queried
  46. Timestamp time.Time `json:"timestamp"`
  47. // The value of the metric at this point.
  48. IntValue int64 `json:"int_value,omitempty"`
  49. FloatValue float64 `json:"float_value,omitempty"`
  50. }
  51. // An exported metric.
  52. type MetricVal struct {
  53. // Label associated with a metric
  54. Label string `json:"label,omitempty"`
  55. Labels map[string]string `json:"labels,omitempty"`
  56. // Time at which the metric was queried
  57. Timestamp time.Time `json:"timestamp"`
  58. // The value of the metric at this point.
  59. IntValue int64 `json:"int_value,omitempty"`
  60. FloatValue float64 `json:"float_value,omitempty"`
  61. }