This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
stats.go
175 lines (137 loc) · 4.51 KB
/
stats.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package incus
import (
"github.com/PagerDuty/godspeed"
"net"
)
type RuntimeStats interface {
LogStartup()
LogClientCount(int64)
LogGoroutines(int)
LogCommand(from, cmdType string)
LogPageMessage()
LogUserMessage()
LogBroadcastMessage()
LogReadMessage()
LogWriteMessage()
LogInvalidJSON()
LogWebsocketConnection()
LogWebsocketDisconnection()
LogLongpollConnect()
LogLongpollDisconnect()
LogAPNSPush()
LogAPNSError()
LogGCMPush()
LogGCMError()
LogGCMFailure()
LogPendingRedisActivityCommandsListLength(int)
}
type DiscardStats struct{}
func (d *DiscardStats) LogStartup() {}
func (d *DiscardStats) LogClientCount(int64) {}
func (d *DiscardStats) LogGoroutines(int) {}
func (d *DiscardStats) LogCommand(from, cmdType string) {}
func (d *DiscardStats) LogPageMessage() {}
func (d *DiscardStats) LogUserMessage() {}
func (d *DiscardStats) LogBroadcastMessage() {}
func (d *DiscardStats) LogWebsocketConnection() {}
func (d *DiscardStats) LogWebsocketDisconnection() {}
func (d *DiscardStats) LogReadMessage() {}
func (d *DiscardStats) LogWriteMessage() {}
func (d *DiscardStats) LogLongpollConnect() {}
func (d *DiscardStats) LogLongpollDisconnect() {}
func (d *DiscardStats) LogAPNSPush() {}
func (d *DiscardStats) LogGCMPush() {}
func (d *DiscardStats) LogAPNSError() {}
func (d *DiscardStats) LogGCMError() {}
func (d *DiscardStats) LogGCMFailure() {}
func (d *DiscardStats) LogInvalidJSON() {}
func (d *DiscardStats) LogPendingRedisActivityCommandsListLength(int) {}
type DatadogStats struct {
dog *godspeed.Godspeed
}
func NewDatadogStats(datadogHost string) (*DatadogStats, error) {
var ip net.IP = nil
var err error = nil
// Assume datadogHost is an IP and try to parse it
ip = net.ParseIP(datadogHost)
// Parsing failed
if ip == nil {
ips, _ := net.LookupIP(datadogHost)
if len(ips) > 0 {
ip = ips[0]
}
}
if ip != nil {
gdsp, err := godspeed.New(ip.String(), godspeed.DefaultPort, false)
if err == nil {
return &DatadogStats{gdsp}, nil
}
}
return nil, err
}
func (d *DatadogStats) LogStartup() {
d.dog.Incr("incus.startup", nil)
}
func (d *DatadogStats) LogClientCount(clients int64) {
d.dog.Gauge("incus.client_count", float64(clients), nil)
}
func (d *DatadogStats) LogGoroutines(goroutines int) {
d.dog.Gauge("incus.goroutines", float64(goroutines), nil)
}
func (d *DatadogStats) LogCommand(from, cmdType string) {
d.dog.Incr("incus.command", nil)
d.dog.Incr("incus.command."+from, nil)
d.dog.Incr("incus.command."+cmdType, nil)
d.dog.Incr("incus.command."+from+"."+cmdType, nil)
}
func (d *DatadogStats) LogPageMessage() {
d.dog.Incr("incus.message", nil)
d.dog.Incr("incus.message.page", nil)
}
func (d *DatadogStats) LogUserMessage() {
d.dog.Incr("incus.message", nil)
d.dog.Incr("incus.message.user", nil)
}
func (d *DatadogStats) LogBroadcastMessage() {
d.dog.Incr("incus.message", nil)
d.dog.Incr("incus.message.all", nil)
}
func (d *DatadogStats) LogWebsocketConnection() {
d.dog.Incr("incus.websocket.connect", nil)
}
func (d *DatadogStats) LogWebsocketDisconnection() {
d.dog.Incr("incus.websocket.disconnect", nil)
}
func (d *DatadogStats) LogReadMessage() {
d.dog.Incr("incus.read", nil)
}
func (d *DatadogStats) LogWriteMessage() {
d.dog.Incr("incus.write", nil)
}
func (d *DatadogStats) LogLongpollConnect() {
d.dog.Incr("incus.longpoll.connect", nil)
}
func (d *DatadogStats) LogLongpollDisconnect() {
d.dog.Incr("incus.longpoll.disconnect", nil)
}
func (d *DatadogStats) LogAPNSPush() {
d.dog.Incr("incus.apns.push", nil)
}
func (d *DatadogStats) LogGCMPush() {
d.dog.Incr("incus.gcm.push", nil)
}
func (d *DatadogStats) LogAPNSError() {
d.dog.Incr("incus.apns.error", nil)
}
func (d *DatadogStats) LogGCMError() {
d.dog.Incr("incus.gcm.error", nil)
}
func (d *DatadogStats) LogGCMFailure() {
d.dog.Incr("incus.gcm.fail", nil)
}
func (d *DatadogStats) LogInvalidJSON() {
d.dog.Incr("incus.jsonerror", nil)
}
func (d *DatadogStats) LogPendingRedisActivityCommandsListLength(length int) {
d.dog.Gauge("incus.pendingactivityredislen", float64(length), nil)
}