-
Notifications
You must be signed in to change notification settings - Fork 1
/
signalrser.go
81 lines (65 loc) · 2.01 KB
/
signalrser.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
package health
import (
"context"
"encoding/json"
"fmt"
"time"
"github.com/mdaxf/iac/com"
"github.com/mdaxf/iac/health/checks"
"github.com/mdaxf/iac/logger"
)
// CheckSystemHealth is a function that checks the health of the system.
// It takes a gin.Context as input and returns a map[string]interface{} and an error.
// The function registers various health checks for different components of the system,
// such as HTTP, MongoDB, MySQL, MQTT, and SignalR.
// It measures the health of the system and returns the result as a JSON-encoded map.
func CheckSignalRServerHealth(Node map[string]interface{}, url string, wc string) (map[string]interface{}, error) {
iLog := logger.Log{ModuleName: logger.Framework, User: "System", ControllerName: "System Status Check"}
startTime := time.Now()
defer func() {
elapsed := time.Since(startTime)
iLog.PerformanceWithDuration("framework.health.CheckSystemHealth", elapsed)
}()
defer func() {
if r := recover(); r != nil {
fmt.Println("Error:", r)
}
}()
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
h, _ := New(WithComponent(Component{
Name: Node["Name"].(string),
Instance: Node["AppID"].(string),
InstanceName: Node["Description"].(string),
InstanceType: Node["Type"].(string),
Version: Node["Version"].(string),
}))
SAddress := url
WcAddress := wc
if WcAddress != "" {
h.Register(Config{
Name: "signalr Websocket Server",
Check: func(ctx context.Context) error {
return checks.CheckSignalRSrvStatus(ctx, SAddress, WcAddress)
},
})
}
if SAddress != "" {
h.Register(Config{
Name: "signalr Http Server",
Check: func(ctx context.Context) error {
return checks.CheckSignalRSrvHttpStatus(ctx, SAddress, WcAddress)
},
})
}
h.systemInfoEnabled = true
m := h.Measure(ctx)
data, err := json.Marshal(m)
if err != nil {
return make(map[string]interface{}), err
}
jdata, err := com.ConvertbytesToMap(data)
if err != nil {
return make(map[string]interface{}), err
}
return jdata, nil
}