This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
tests.go
94 lines (76 loc) · 2.84 KB
/
tests.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
package main
import (
"fmt"
"math/rand"
"os"
"time"
metrics "github.com/rcrowley/go-metrics"
"github.com/wavefronthq/go-metrics-wavefront/reporting"
"github.com/wavefronthq/wavefront-sdk-go/application"
"github.com/wavefronthq/wavefront-sdk-go/senders"
)
func main() {
//Tags we'll add to the metric
tags := map[string]string{
"key2": "val2",
"key1": "val1",
"key0": "val0",
"key4": "val4",
"key3": "val3",
}
counter := metrics.NewCounter() //Create a counter
metrics.Register("foo2", counter) // will create a 'some.prefix.foo2.count' metric with no tags
reporting.RegisterMetric("foo", counter, tags) // will create a 'some.prefix.foo.count' metric with tags
counter.Inc(47)
histogram := reporting.NewHistogram()
reporting.RegisterMetric("duration", histogram, tags) // will create a 'some.prefix.duration' histogram metric with tags
histogram2 := reporting.NewHistogram()
metrics.Register("duration2", histogram2) // will create a 'some.prefix.duration2' histogram metric with no tags
deltaCounter := metrics.NewCounter()
reporting.RegisterMetric(reporting.DeltaCounterName("delta.metric"), deltaCounter, tags)
deltaCounter.Inc(10)
directCfg := &senders.DirectConfiguration{
Server: "https://" + os.Getenv("WF_INSTANCE") + ".reporting.com",
Token: os.Getenv("WF_TOKEN"),
BatchSize: 10000,
MaxBufferSize: 50000,
FlushIntervalSeconds: 1,
}
sender, err := senders.NewDirectSender(directCfg)
if err != nil {
panic(err)
}
// start: send golang runtime metric
rtm_counter := metrics.NewCounter() //Create a counter
metrics.Register("golangruntime", rtm_counter) // will create a 'some.prefix.golangruntime.count' metric with no tags
report_rtm := reporting.NewMetricsReporter(
sender,
reporting.ApplicationTag(application.New("app", "srv")),
reporting.Source("go-metrics-test"),
reporting.Prefix("some.prefix"),
reporting.RuntimeMetric(true),
)
report_rtm.RegisterMetric("golangruntime", rtm_counter, tags) // will create a 'some.prefix.golangruntime.count' metric with tags
fmt.Println("Search wavefront: ts(\"some.prefix.golangruntime.count\")")
fmt.Println("Entering loop to simulate metrics flushing. Hit ctrl+c to cancel")
for i := 0; i <= 1000; i++ {
time.Sleep(time.Second * 10)
}
// end: send golang runtime metric
reporting.NewMetricsReporter(
sender,
reporting.ApplicationTag(application.New("app", "srv")),
reporting.Source("go-metrics-test"),
reporting.Prefix("some.prefix"),
reporting.LogErrors(true),
)
fmt.Println("Search wavefront: ts(\"some.prefix.foo.count\")")
fmt.Println("Entering loop to simulate metrics flushing. Hit ctrl+c to cancel")
for {
counter.Inc(rand.Int63())
histogram.Update(rand.Int63())
histogram2.Update(rand.Int63())
deltaCounter.Inc(10)
time.Sleep(time.Second * 10)
}
}