@@ -3,8 +3,8 @@ package telegraf
3
3
import (
4
4
"time"
5
5
6
+ // TODO remove
6
7
"github.com/influxdata/influxdb/client/v2"
7
- "github.com/influxdata/influxdb/models"
8
8
)
9
9
10
10
// ValueType is an enumeration of metric types that represent a simple value.
@@ -19,178 +19,40 @@ const (
19
19
)
20
20
21
21
type Metric interface {
22
- // Name returns the measurement name of the metric
23
- Name () string
22
+ Serialize () []byte
23
+ String () string // convenience function for string(Serialize())
24
+ Copy () Metric
24
25
25
- // Name returns the tags associated with the metric
26
- Tags () map [string ]string
26
+ // Tag functions
27
+ HasTag (key string ) bool
28
+ AddTag (key , value string )
29
+ RemoveTag (key string ) bool
27
30
28
- // Time return the timestamp for the metric
29
- Time () time.Time
31
+ // Field functions
32
+ HasField (key string ) bool
33
+ AddField (key string , value interface {})
34
+ RemoveField (key string ) bool
30
35
31
- // Type returns the metric type. Can be either telegraf.Gauge or telegraf.Counter
32
- Type () ValueType
36
+ // Name functions
37
+ SetName (name string )
38
+ SetPrefix (prefix string )
39
+ SetSuffix (suffix string )
33
40
34
- // UnixNano returns the unix nano time of the metric
41
+ // Getting data structure functions
42
+ Name () string
43
+ Tags () map [string ]string
44
+ Fields () map [string ]interface {}
45
+ Time () time.Time
35
46
UnixNano () int64
36
-
37
- // HashID returns a non-cryptographic hash of the metric (name + tags)
38
- // NOTE: do not persist & depend on this value to disk.
47
+ Type () ValueType
48
+ Len () int // returns the length of the serialized metric, including newline
39
49
HashID () uint64
40
50
41
- // Fields returns the fields for the metric
42
- Fields () map [string ]interface {}
43
-
44
- // String returns a line-protocol string of the metric
45
- String () string
46
-
47
- // PrecisionString returns a line-protocol string of the metric, at precision
48
- PrecisionString (precison string ) string
49
-
50
- // Point returns a influxdb client.Point object
51
- Point () * client.Point
52
-
53
- // SetAggregate sets the metric's aggregate status
54
- // This is so that aggregate metrics don't get re-sent to aggregator plugins
51
+ // aggregator things:
55
52
SetAggregate (bool )
56
- // IsAggregate returns true if the metric is an aggregate
57
53
IsAggregate () bool
58
54
59
- // Copy copies the metric
60
- Copy () Metric
61
- }
62
-
63
- // metric is a wrapper of the influxdb client.Point struct
64
- type metric struct {
65
- pt models.Point
66
-
67
- mType ValueType
68
-
69
- isaggregate bool
70
- }
71
-
72
- func NewMetricFromPoint (pt models.Point ) Metric {
73
- return & metric {
74
- pt : pt ,
75
- mType : Untyped ,
76
- }
77
- }
78
-
79
- // NewMetric returns an untyped metric.
80
- func NewMetric (
81
- name string ,
82
- tags map [string ]string ,
83
- fields map [string ]interface {},
84
- t time.Time ,
85
- ) (Metric , error ) {
86
- pt , err := models .NewPoint (name , models .NewTags (tags ), fields , t )
87
- if err != nil {
88
- return nil , err
89
- }
90
- return & metric {
91
- pt : pt ,
92
- mType : Untyped ,
93
- }, nil
94
- }
95
-
96
- // NewGaugeMetric returns a gauge metric.
97
- // Gauge metrics should be used when the metric is can arbitrarily go up and
98
- // down. ie, temperature, memory usage, cpu usage, etc.
99
- func NewGaugeMetric (
100
- name string ,
101
- tags map [string ]string ,
102
- fields map [string ]interface {},
103
- t time.Time ,
104
- ) (Metric , error ) {
105
- pt , err := models .NewPoint (name , models .NewTags (tags ), fields , t )
106
- if err != nil {
107
- return nil , err
108
- }
109
- return & metric {
110
- pt : pt ,
111
- mType : Gauge ,
112
- }, nil
113
- }
114
-
115
- // NewCounterMetric returns a Counter metric.
116
- // Counter metrics should be used when the metric being created is an
117
- // always-increasing counter. ie, net bytes received, requests served, errors, etc.
118
- func NewCounterMetric (
119
- name string ,
120
- tags map [string ]string ,
121
- fields map [string ]interface {},
122
- t time.Time ,
123
- ) (Metric , error ) {
124
- pt , err := models .NewPoint (name , models .NewTags (tags ), fields , t )
125
- if err != nil {
126
- return nil , err
127
- }
128
- return & metric {
129
- pt : pt ,
130
- mType : Counter ,
131
- }, nil
132
- }
133
-
134
- func (m * metric ) Name () string {
135
- return m .pt .Name ()
136
- }
137
-
138
- func (m * metric ) Tags () map [string ]string {
139
- return m .pt .Tags ().Map ()
140
- }
141
-
142
- func (m * metric ) Time () time.Time {
143
- return m .pt .Time ()
144
- }
145
-
146
- func (m * metric ) Type () ValueType {
147
- return m .mType
148
- }
149
-
150
- func (m * metric ) HashID () uint64 {
151
- return m .pt .HashID ()
152
- }
153
-
154
- func (m * metric ) UnixNano () int64 {
155
- return m .pt .UnixNano ()
156
- }
157
-
158
- func (m * metric ) Fields () map [string ]interface {} {
159
- return m .pt .Fields ()
160
- }
161
-
162
- func (m * metric ) String () string {
163
- return m .pt .String ()
164
- }
165
-
166
- func (m * metric ) PrecisionString (precison string ) string {
167
- return m .pt .PrecisionString (precison )
168
- }
169
-
170
- func (m * metric ) Point () * client.Point {
171
- return client .NewPointFrom (m .pt )
172
- }
173
-
174
- func (m * metric ) IsAggregate () bool {
175
- return m .isaggregate
176
- }
177
-
178
- func (m * metric ) SetAggregate (b bool ) {
179
- m .isaggregate = b
180
- }
181
-
182
- func (m * metric ) Copy () Metric {
183
- t := time .Time (m .Time ())
184
-
185
- tags := make (map [string ]string )
186
- fields := make (map [string ]interface {})
187
- for k , v := range m .Tags () {
188
- tags [k ] = v
189
- }
190
- for k , v := range m .Fields () {
191
- fields [k ] = v
192
- }
193
-
194
- out , _ := NewMetric (m .Name (), tags , fields , t )
195
- return out
55
+ // Point returns a influxdb client.Point object
56
+ // TODO remove this function
57
+ Point () * client.Point
196
58
}
0 commit comments