-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.go
More file actions
76 lines (60 loc) · 1.38 KB
/
dashboard.go
File metadata and controls
76 lines (60 loc) · 1.38 KB
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
// Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree.
package collider
import (
"sync"
"time"
)
const maxErrLogLen = 128
type errEvent struct {
Time time.Time `json:"t"`
Err string `json:"e"`
}
type dashboard struct {
lock sync.Mutex
startTime time.Time
totalWs int
totalRecvMsgs int
totalSendMsgs int
wsErrs int
httpErrs int
}
type statusReport struct {
UpTimeSec float64 `json:"upsec"`
OpenWs int `json:"openws"`
TotalWs int `json:"totalws"`
WsErrs int `json:"wserrors"`
HttpErrs int `json:"httperrors"`
}
func newDashboard() *dashboard {
return &dashboard{startTime: time.Now()}
}
func (db *dashboard) getReport(rs *roomTable) statusReport {
db.lock.Lock()
defer db.lock.Unlock()
upTime := time.Since(db.startTime)
return statusReport{
UpTimeSec: upTime.Seconds(),
OpenWs: rs.wsCount(),
TotalWs: db.totalWs,
WsErrs: db.wsErrs,
HttpErrs: db.httpErrs,
}
}
func (db *dashboard) incrWs() {
db.lock.Lock()
defer db.lock.Unlock()
db.totalWs += 1
}
func (db *dashboard) onWsErr(err error) {
db.lock.Lock()
defer db.lock.Unlock()
db.wsErrs += 1
}
func (db *dashboard) onHttpErr(err error) {
db.lock.Lock()
defer db.lock.Unlock()
db.httpErrs += 1
}