Skip to content

Commit d8216f4

Browse files
authored
Merge pull request #15 from Hamzenium/Routing-Fic
Fixed Routing & Binaries
2 parents 13fcae6 + a8c6083 commit d8216f4

6 files changed

Lines changed: 68 additions & 1 deletion

File tree

backend.log

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2025/04/02 06:06:40 {90 90 90}
2+
2025/04/02 06:06:40 Starting backend server on port 8080...
3+
2025/04/02 06:06:41 Alerts enabled: true
4+
2025/04/02 06:06:43 Alerts enabled: false
5+
2025/04/02 06:07:00 Updated limits - CPU: 5, Memory: 100, Disk: 100
6+
2025/04/02 06:07:01 Alerts enabled: true
7+
2025/04/02 06:07:16 Received shutdown request
8+
2025/04/02 06:07:16 Shutting down the server...
9+
2025/04/02 06:07:16 Server stopped.
File renamed without changes.

backend/monitor/monitor.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package monitor
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"resource-monitor/backend/types"
7+
"resource-monitor/backend/utils"
8+
"sync"
9+
"time"
10+
11+
"github.com/gen2brain/beeep"
12+
)
13+
14+
var (
15+
AlertEnabled bool
16+
Mu sync.Mutex
17+
DefaultLimit = types.SetLimit{CPUThreshold: 90, MemoryThreshold: 90, DiskThreshold: 90}
18+
)
19+
20+
func sendAlert(resource string, usage float64) {
21+
Mu.Lock()
22+
defer Mu.Unlock()
23+
24+
if !AlertEnabled {
25+
return
26+
}
27+
28+
var threshold float64
29+
switch resource {
30+
case "CPU":
31+
threshold = DefaultLimit.CPUThreshold
32+
case "Memory":
33+
threshold = DefaultLimit.MemoryThreshold
34+
case "Disk":
35+
threshold = DefaultLimit.DiskThreshold
36+
}
37+
38+
if usage > threshold {
39+
err := beeep.Alert(fmt.Sprintf("%s Alert", resource), fmt.Sprintf("%s usage is at %.2f%%!", resource, usage), "")
40+
if err != nil {
41+
log.Println("Error sending macOS notification:", err)
42+
}
43+
}
44+
}
45+
46+
func MonitorResources() {
47+
for {
48+
cpuUsage := utils.GetCPUUsage()
49+
memUsage := utils.GetMemoryUsage()
50+
diskUsage := utils.GetDiskUsage()
51+
52+
sendAlert("CPU", cpuUsage)
53+
sendAlert("Memory", memUsage)
54+
sendAlert("Disk", diskUsage)
55+
56+
time.Sleep(5 * time.Second)
57+
}
58+
}
File renamed without changes.

frontend/output

-28.3 MB
Binary file not shown.

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
BINARY_NAME = monitor
1+
BINARY_NAME = image
22

33
GO = go
44
GOFMT = gofmt

0 commit comments

Comments
 (0)