-
Notifications
You must be signed in to change notification settings - Fork 2
/
apm.go
60 lines (49 loc) · 1.15 KB
/
apm.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
package huaweiapm
import (
"github.com/go-chassis/huawei-apm/api"
"github.com/go-mesh/openlogging"
"gopkg.in/validator.v2"
)
const (
DefaultDiscoveryInterval = "290s"
DefaultTracingBatchInterval = "1m"
DefaultTracingBatchSize = 1000
)
var client api.APM
var tr *TracingReporter
//Switchers
var StopTracing = make(chan bool)
var StopInventory = make(chan bool)
var StopKPI = make(chan bool)
var StartTracing = make(chan bool)
var StartInventory = make(chan bool)
var StartKPI = make(chan bool)
func Start(opts Options) error {
if err := validator.Validate(opts); err != nil {
return err
}
opt := opts
disco, err := BuildTDiscoveryInfo(opts)
if err != nil {
openlogging.Error("can not build discovery info: " + err.Error())
return err
}
client, err = api.GetAPMClient(opts.App, opts.ServiceName)
if err != nil {
return err
}
openlogging.Debug("APM client init success")
go startDiscovery(disco)
go watchConfigs(opt.App, opt.ServiceName)
//watch signal
go func() {
select {
case s := <-StartTracing:
if s && !tr.tracingRunning {
openlogging.Info("restart tracing")
go tr.StartReportSpans()
}
}
}()
return nil
}