-
Notifications
You must be signed in to change notification settings - Fork 0
/
metric.go
144 lines (113 loc) · 3.99 KB
/
metric.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package telegraf
import (
"time"
)
// ValueType is an enumeration of metric types that represent a simple value.
type ValueType int
// Possible values for the ValueType enum.
const (
_ ValueType = iota
Counter
Gauge
Untyped
Summary
Histogram
)
// Tag represents a single tag key and value.
type Tag struct {
Key string
Value string
}
// Field represents a single field key and value.
type Field struct {
Key string
Value interface{}
}
// Metric is the type of data that is processed by Telegraf. Input plugins,
// and to a lesser degree, Processor and Aggregator plugins create new Metrics
// and Output plugins write them.
//
//nolint:interfacebloat // conditionally allow to contain more methods
type Metric interface {
// Name is the primary identifier for the Metric and corresponds to the
// measurement in the InfluxDB data model.
Name() string
// Tags returns the tags as a map. This method is deprecated, use TagList instead.
Tags() map[string]string
// TagList returns the tags as a slice ordered by the tag key in lexical
// bytewise ascending order. The returned value should not be modified,
// use the AddTag or RemoveTag methods instead.
TagList() []*Tag
// Fields returns the fields as a map. This method is deprecated, use FieldList instead.
Fields() map[string]interface{}
// FieldList returns the fields as a slice in an undefined order. The
// returned value should not be modified, use the AddField or RemoveField
// methods instead.
FieldList() []*Field
// Time returns the timestamp of the metric.
Time() time.Time
// Type returns a general type for the entire metric that describes how you
// might interpret, aggregate the values. Used by prometheus and statsd.
Type() ValueType
// SetName sets the metric name.
SetName(name string)
// AddPrefix adds a string to the front of the metric name. It is
// equivalent to m.SetName(prefix + m.Name()).
//
// This method is deprecated, use SetName instead.
AddPrefix(prefix string)
// AddSuffix appends a string to the back of the metric name. It is
// equivalent to m.SetName(m.Name() + suffix).
//
// This method is deprecated, use SetName instead.
AddSuffix(suffix string)
// GetTag returns the value of a tag and a boolean to indicate if it was set.
GetTag(key string) (string, bool)
// HasTag returns true if the tag is set on the Metric.
HasTag(key string) bool
// AddTag sets the tag on the Metric. If the Metric already has the tag
// set then the current value is replaced.
AddTag(key, value string)
// RemoveTag removes the tag if it is set.
RemoveTag(key string)
// GetField returns the value of a field and a boolean to indicate if it was set.
GetField(key string) (interface{}, bool)
// HasField returns true if the field is set on the Metric.
HasField(key string) bool
// AddField sets the field on the Metric. If the Metric already has the field
// set then the current value is replaced.
AddField(key string, value interface{})
// RemoveField removes the tag if it is set.
RemoveField(key string)
// SetTime sets the timestamp of the Metric.
SetTime(t time.Time)
// HashID returns an unique identifier for the series.
HashID() uint64
// Copy returns a deep copy of the Metric.
Copy() Metric
// Accept marks the metric as processed successfully and written to an
// output.
Accept()
// Reject marks the metric as processed unsuccessfully.
Reject()
// Drop marks the metric as processed successfully without being written
// to any output.
Drop()
}
// TemplateMetric is an interface to use in templates (e.g text/template)
// to generate complex strings from metric properties
// e.g. '{{.Name}}-{{.Tag "foo"}}-{{.Field "bar"}}'
type TemplateMetric interface {
Name() string
Field(key string) interface{}
Fields() map[string]interface{}
Tag(key string) string
Tags() map[string]string
Time() time.Time
String() string
}
type UnwrappableMetric interface {
// Unwrap allows to access the underlying raw metric if an implementation
// wraps it in the first place.
Unwrap() Metric
}