@@ -14,36 +14,36 @@ import (
14
14
"github.com/uozi-tech/cosy/logger"
15
15
)
16
16
17
- // NginxPerformanceClient represents a WebSocket client for Nginx performance monitoring
18
- type NginxPerformanceClient struct {
17
+ // PerformanceClient represents a WebSocket client for Nginx performance monitoring
18
+ type PerformanceClient struct {
19
19
conn * websocket.Conn
20
20
send chan interface {}
21
21
ctx context.Context
22
22
cancel context.CancelFunc
23
23
mutex sync.RWMutex
24
24
}
25
25
26
- // NginxPerformanceHub manages WebSocket connections for Nginx performance monitoring
27
- type NginxPerformanceHub struct {
28
- clients map [* NginxPerformanceClient ]bool
29
- register chan * NginxPerformanceClient
30
- unregister chan * NginxPerformanceClient
26
+ // PerformanceHub manages WebSocket connections for Nginx performance monitoring
27
+ type PerformanceHub struct {
28
+ clients map [* PerformanceClient ]bool
29
+ register chan * PerformanceClient
30
+ unregister chan * PerformanceClient
31
31
mutex sync.RWMutex
32
32
ticker * time.Ticker
33
33
}
34
34
35
35
var (
36
- performanceHub * NginxPerformanceHub
36
+ performanceHub * PerformanceHub
37
37
performanceHubOnce sync.Once
38
38
)
39
39
40
40
// GetNginxPerformanceHub returns the singleton hub instance
41
- func GetNginxPerformanceHub () * NginxPerformanceHub {
41
+ func GetNginxPerformanceHub () * PerformanceHub {
42
42
performanceHubOnce .Do (func () {
43
- performanceHub = & NginxPerformanceHub {
44
- clients : make (map [* NginxPerformanceClient ]bool ),
45
- register : make (chan * NginxPerformanceClient ),
46
- unregister : make (chan * NginxPerformanceClient ),
43
+ performanceHub = & PerformanceHub {
44
+ clients : make (map [* PerformanceClient ]bool ),
45
+ register : make (chan * PerformanceClient ),
46
+ unregister : make (chan * PerformanceClient ),
47
47
ticker : time .NewTicker (5 * time .Second ),
48
48
}
49
49
go performanceHub .run ()
@@ -52,7 +52,7 @@ func GetNginxPerformanceHub() *NginxPerformanceHub {
52
52
}
53
53
54
54
// run handles the main hub loop
55
- func (h * NginxPerformanceHub ) run () {
55
+ func (h * PerformanceHub ) run () {
56
56
defer h .ticker .Stop ()
57
57
58
58
for {
@@ -80,7 +80,7 @@ func (h *NginxPerformanceHub) run() {
80
80
h .broadcastPerformanceData ()
81
81
82
82
case <- kernel .Context .Done ():
83
- logger .Debug ("NginxPerformanceHub : Context cancelled, closing WebSocket" )
83
+ logger .Debug ("PerformanceHub : Context cancelled, closing WebSocket" )
84
84
// Shutdown all clients
85
85
h .mutex .Lock ()
86
86
for client := range h .clients {
@@ -94,7 +94,7 @@ func (h *NginxPerformanceHub) run() {
94
94
}
95
95
96
96
// sendPerformanceDataToClient sends performance data to a specific client
97
- func (h * NginxPerformanceHub ) sendPerformanceDataToClient (client * NginxPerformanceClient ) {
97
+ func (h * PerformanceHub ) sendPerformanceDataToClient (client * PerformanceClient ) {
98
98
response := performance .GetPerformanceData ()
99
99
100
100
select {
@@ -106,7 +106,7 @@ func (h *NginxPerformanceHub) sendPerformanceDataToClient(client *NginxPerforman
106
106
}
107
107
108
108
// broadcastPerformanceData sends performance data to all connected clients
109
- func (h * NginxPerformanceHub ) broadcastPerformanceData () {
109
+ func (h * PerformanceHub ) broadcastPerformanceData () {
110
110
h .mutex .RLock ()
111
111
112
112
// Check if there are any connected clients
@@ -151,7 +151,7 @@ func StreamDetailStatusWS(c *gin.Context) {
151
151
ctx , cancel := context .WithCancel (context .Background ())
152
152
defer cancel ()
153
153
154
- client := & NginxPerformanceClient {
154
+ client := & PerformanceClient {
155
155
conn : ws ,
156
156
send : make (chan interface {}, 1024 ), // Increased buffer size
157
157
ctx : ctx ,
@@ -167,7 +167,7 @@ func StreamDetailStatusWS(c *gin.Context) {
167
167
}
168
168
169
169
// writePump pumps messages from the hub to the websocket connection
170
- func (c * NginxPerformanceClient ) writePump () {
170
+ func (c * PerformanceClient ) writePump () {
171
171
ticker := time .NewTicker (30 * time .Second )
172
172
defer func () {
173
173
ticker .Stop ()
@@ -201,14 +201,14 @@ func (c *NginxPerformanceClient) writePump() {
201
201
return
202
202
203
203
case <- kernel .Context .Done ():
204
- logger .Debug ("NginxPerformanceClient : Context cancelled, closing WebSocket" )
204
+ logger .Debug ("PerformanceClient : Context cancelled, closing WebSocket" )
205
205
return
206
206
}
207
207
}
208
208
}
209
209
210
210
// readPump pumps messages from the websocket connection to the hub
211
- func (c * NginxPerformanceClient ) readPump () {
211
+ func (c * PerformanceClient ) readPump () {
212
212
defer func () {
213
213
hub := GetNginxPerformanceHub ()
214
214
hub .unregister <- c
0 commit comments