Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions snaptrack-backend/internal/socket/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func FetchStats() (*SystemStats, error) {
}


func MonitorAndBroadcast(broadcast chan []byte, interval time.Duration) {
func MonitorAndBroadcastSystemStats(broadcast chan []byte, interval time.Duration) {
for {
stats, err := FetchStats()
if err != nil {
Expand All @@ -150,7 +150,15 @@ func MonitorAndBroadcast(broadcast chan []byte, interval time.Duration) {
continue
}

data, err := json.Marshal(stats)
payload := struct {
Type string `json:"type"`
Stats *SystemStats `json:"stats"`
}{
Type: "metrics",
Stats: stats,
}

data, err := json.Marshal(payload)
if err != nil {
log.Printf("Error marshalling stats: %v", err)
time.Sleep(interval)
Expand All @@ -160,4 +168,4 @@ func MonitorAndBroadcast(broadcast chan []byte, interval time.Duration) {
broadcast <- data
time.Sleep(interval)
}
}
}
Loading
Loading