forked from open-falcon/falcon-plus
/
var.go
76 lines (64 loc) · 1.6 KB
/
var.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
package g
import (
"github.com/open-falcon/falcon-plus/common/model"
"sync"
"time"
)
type SafeStrategyMap struct {
sync.RWMutex
// endpoint:metric => [strategy1, strategy2 ...]
M map[string][]model.Strategy
}
type SafeExpressionMap struct {
sync.RWMutex
// metric:tag1 => [exp1, exp2 ...]
// metric:tag2 => [exp1, exp2 ...]
M map[string][]*model.Expression
}
type SafeEventMap struct {
sync.RWMutex
M map[string]*model.Event
}
var (
HbsClient *SingleConnRpcClient
StrategyMap = &SafeStrategyMap{M: make(map[string][]model.Strategy)}
ExpressionMap = &SafeExpressionMap{M: make(map[string][]*model.Expression)}
LastEvents = &SafeEventMap{M: make(map[string]*model.Event)}
)
func InitHbsClient() {
HbsClient = &SingleConnRpcClient{
RpcServers: Config().Hbs.Servers,
Timeout: time.Duration(Config().Hbs.Timeout) * time.Millisecond,
}
}
func (this *SafeStrategyMap) ReInit(m map[string][]model.Strategy) {
this.Lock()
defer this.Unlock()
this.M = m
}
func (this *SafeStrategyMap) Get() map[string][]model.Strategy {
this.RLock()
defer this.RUnlock()
return this.M
}
func (this *SafeExpressionMap) ReInit(m map[string][]*model.Expression) {
this.Lock()
defer this.Unlock()
this.M = m
}
func (this *SafeExpressionMap) Get() map[string][]*model.Expression {
this.RLock()
defer this.RUnlock()
return this.M
}
func (this *SafeEventMap) Get(key string) (*model.Event, bool) {
this.RLock()
defer this.RUnlock()
event, exists := this.M[key]
return event, exists
}
func (this *SafeEventMap) Set(key string, event *model.Event) {
this.Lock()
defer this.Unlock()
this.M[key] = event
}