This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
/
write.go
63 lines (58 loc) · 2.19 KB
/
write.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
package stats
import (
"strconv"
"time"
)
// Write* functions append a graphite metric line to the given buffer.
// `buf` is the incoming buffer to be appended to
// `prefix` is an optional prefix to the metric name which must have a trailing '.' if present
// `name` is the required name of the metric. It should not have a leading or trailing '.' or a trailing ';'
// `suffix` is an optional suffix to the metric name which must have a leading '.' if present. It should not have a trailing ';'
// `tags` is an optional list of tags which must have a leading ';' if present.
// `val` is the value of the metric
// `now` is the time that the metrics should be reported at
// returns `buf` with the new metric line appended
func WriteFloat64(buf, prefix, name, suffix, tags []byte, val float64, now time.Time) []byte {
buf = append(buf, prefix...)
buf = append(buf, name...)
buf = append(buf, suffix...)
buf = append(buf, tags...)
buf = append(buf, ' ')
buf = strconv.AppendFloat(buf, val, 'f', -1, 64)
buf = append(buf, ' ')
buf = strconv.AppendInt(buf, now.Unix(), 10)
return append(buf, '\n')
}
func WriteUint32(buf, prefix, name, suffix, tags []byte, val uint32, now time.Time) []byte {
buf = append(buf, prefix...)
buf = append(buf, name...)
buf = append(buf, suffix...)
buf = append(buf, tags...)
buf = append(buf, ' ')
buf = strconv.AppendUint(buf, uint64(val), 10)
buf = append(buf, ' ')
buf = strconv.AppendInt(buf, now.Unix(), 10)
return append(buf, '\n')
}
func WriteUint64(buf, prefix, name, suffix, tags []byte, val uint64, now time.Time) []byte {
buf = append(buf, prefix...)
buf = append(buf, name...)
buf = append(buf, suffix...)
buf = append(buf, tags...)
buf = append(buf, ' ')
buf = strconv.AppendUint(buf, val, 10)
buf = append(buf, ' ')
buf = strconv.AppendInt(buf, now.Unix(), 10)
return append(buf, '\n')
}
func WriteInt32(buf, prefix, name, suffix, tags []byte, val int32, now time.Time) []byte {
buf = append(buf, prefix...)
buf = append(buf, name...)
buf = append(buf, suffix...)
buf = append(buf, tags...)
buf = append(buf, ' ')
buf = strconv.AppendInt(buf, int64(val), 10)
buf = append(buf, ' ')
buf = strconv.AppendInt(buf, now.Unix(), 10)
return append(buf, '\n')
}