forked from thingio/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vars.go
114 lines (96 loc) · 2.42 KB
/
vars.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package vars
import (
"expvar"
"time"
kexpvar "github.com/influxdata/kapacitor/expvar"
"github.com/influxdata/kapacitor/uuid"
)
const (
// List of names for top-level exported vars
ClusterIDVarName = "cluster_id"
ServerIDVarName = "server_id"
HostVarName = "host"
ProductVarName = "product"
VersionVarName = "version"
PlatformVarName = "platform"
NumTasksVarName = "num_tasks"
NumEnabledTasksVarName = "num_enabled_tasks"
NumSubscriptionsVarName = "num_subscriptions"
UptimeVarName = "uptime"
// The name of the product
Product = "kapacitor"
)
var (
// Global expvars
NumTasksVar = &kexpvar.Int{}
NumEnabledTasksVar = &kexpvar.Int{}
NumSubscriptionsVar = kexpvar.NewIntSum()
ClusterIDVar = &kexpvar.UUID{}
ServerIDVar = &kexpvar.UUID{}
HostVar = &kexpvar.String{}
ProductVar = &kexpvar.String{}
VersionVar = &kexpvar.String{}
PlatformVar = &kexpvar.String{}
)
var (
startTime time.Time
)
func init() {
startTime = time.Now().UTC()
expvar.Publish(NumTasksVarName, NumTasksVar)
expvar.Publish(NumEnabledTasksVarName, NumEnabledTasksVar)
expvar.Publish(NumSubscriptionsVarName, NumSubscriptionsVar)
expvar.Publish(ClusterIDVarName, ClusterIDVar)
expvar.Publish(ServerIDVarName, ServerIDVar)
expvar.Publish(HostVarName, HostVar)
expvar.Publish(ProductVarName, ProductVar)
expvar.Publish(VersionVarName, VersionVar)
expvar.Publish(PlatformVarName, PlatformVar)
}
func uptime() time.Duration {
return time.Since(startTime)
}
type Infoer interface {
ClusterID() uuid.UUID
ServerID() uuid.UUID
Hostname() string
Version() string
Product() string
Platform() string
NumTasks() int64
NumEnabledTasks() int64
NumSubscriptions() int64
Uptime() time.Duration
}
var Info = info{}
type info struct{}
func (info) ClusterID() uuid.UUID {
return ClusterIDVar.UUIDValue()
}
func (info) ServerID() uuid.UUID {
return ServerIDVar.UUIDValue()
}
func (info) Hostname() string {
return HostVar.StringValue()
}
func (info) Version() string {
return VersionVar.StringValue()
}
func (info) Product() string {
return ProductVar.StringValue()
}
func (info) Platform() string {
return PlatformVar.StringValue()
}
func (info) NumTasks() int64 {
return NumTasksVar.IntValue()
}
func (info) NumEnabledTasks() int64 {
return NumEnabledTasksVar.IntValue()
}
func (info) NumSubscriptions() int64 {
return NumSubscriptionsVar.IntValue()
}
func (info) Uptime() time.Duration {
return uptime()
}