-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs.go
55 lines (48 loc) · 1.24 KB
/
funcs.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
package metrics
import (
client "github.com/influxdata/influxdb1-client"
)
func buildBucketVals(buckets []string, field string) map[string]map[string]interface{} {
var m = make(map[string]map[string]interface{}, len(buckets))
for _, bucket := range buckets {
m[bucket] = map[string]interface{}{
field: 0.0,
}
}
return m
}
func buildBucketTags(buckets []string, tags map[string]string) map[string]map[string]string {
var m = make(map[string]map[string]string, len(buckets))
for _, bucket := range buckets {
m[bucket] = bucketTags(bucket, tags)
}
return m
}
func bucketTags(bucket string, tags map[string]string) map[string]string {
if bucket == "" {
return tags
}
m := make(map[string]string, len(tags)+1)
for tk, tv := range tags {
m[tk] = tv
}
m["bucket"] = bucket
return m
}
func composeTags(reporterTags, metricTags map[string]string) map[string]string {
m := make(map[string]string, len(reporterTags)+len(metricTags))
for k, v := range reporterTags {
m[k] = v
}
for k, v := range metricTags {
m[k] = v
}
return m
}
func getPoint(measurement string, fields map[string]interface{}, tags map[string]string) client.Point {
return client.Point{
Measurement: measurement,
Tags: tags,
Fields: fields,
}
}