-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsdb_test.go
62 lines (49 loc) · 998 Bytes
/
tsdb_test.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
package main
import (
"bytes"
"math/rand"
"net"
"testing"
)
func TestParseTSDBItem(t *testing.T) {
item := &TsdbItem{
Metric: "sys.cpu.nice",
Tags: map[string]string{
"host": "web01",
"host2": "web02",
},
Value: 42.5,
Timestamp: 1365465600,
}
bufferStr := item.TsdbString()
t.Log(bufferStr)
if item, err := ParseTSDBItem(bufferStr); err != nil {
t.Error(err)
} else {
t.Logf("%+v", item)
}
}
func BenchmarkPutMessage(b *testing.B) {
conn, err := net.Dial("tcp", "127.0.0.1:8089")
if err != nil {
b.Fatal(err)
}
defer conn.Close()
item := &TsdbItem{
Metric: "sys.cpu.nice",
Tags: map[string]string{
"host": "web01",
"host2": "web02",
},
Value: 42.5,
Timestamp: 1365465600,
}
for i := 0; i < b.N; i++ {
item.Timestamp = item.Timestamp + int64(i)
item.Value = rand.Float64()
var tsdbBuffer bytes.Buffer
tsdbBuffer.WriteString(item.TsdbString())
tsdbBuffer.WriteString("\n")
conn.Write(tsdbBuffer.Bytes())
}
}