Skip to content

Commit 1e55ccf

Browse files
committed
Add structures for simple metrics.
1 parent 003bec9 commit 1e55ccf

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

info/v2/metric.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
15+
package v2
16+
17+
import (
18+
"time"
19+
)
20+
21+
// Type of metric being exported.
22+
type MetricType string
23+
24+
const (
25+
// Instantaneous value. May increase or decrease.
26+
MetricGauge MetricType = "gauge"
27+
28+
// A counter-like value that is only expected to increase.
29+
MetricCumulative = "cumulative"
30+
31+
// Rate over a time period.
32+
MetricDelta = "delta"
33+
)
34+
35+
// An exported metric.
36+
type Metric struct {
37+
// The name of the metric.
38+
Name string `json:"name"`
39+
40+
// Type of the metric.
41+
Type MetricType `json:"type"`
42+
43+
// Metadata associated with this metric.
44+
Labels map[string]string
45+
46+
// Value of the metric. Only one of these values will be
47+
// available according to the output type of the metric.
48+
// If no values are available, there are no data points.
49+
IntPoints []IntPoint `json:"int_points,omitempty"`
50+
FloatPoints []FloatPoint `json:"float_points,omitempty"`
51+
}
52+
53+
// An integer metric data point.
54+
type IntPoint struct {
55+
// Time at which the metric was queried
56+
Timestamp time.Time `json:"timestamp"`
57+
58+
// The value of the metric at this point.
59+
Value int64 `json:"value"`
60+
}
61+
62+
// A float metric data point.
63+
type FloatPoint struct {
64+
// Time at which the metric was queried
65+
Timestamp time.Time `json:"timestamp"`
66+
67+
// The value of the metric at this point.
68+
Value float64 `json:"value"`
69+
}

0 commit comments

Comments
 (0)