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
9 changes: 9 additions & 0 deletions backend.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
2025/04/02 06:06:40 {90 90 90}
2025/04/02 06:06:40 Starting backend server on port 8080...
2025/04/02 06:06:41 Alerts enabled: true
2025/04/02 06:06:43 Alerts enabled: false
2025/04/02 06:07:00 Updated limits - CPU: 5, Memory: 100, Disk: 100
2025/04/02 06:07:01 Alerts enabled: true
2025/04/02 06:07:16 Received shutdown request
2025/04/02 06:07:16 Shutting down the server...
2025/04/02 06:07:16 Server stopped.
File renamed without changes.
58 changes: 58 additions & 0 deletions backend/monitor/monitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package monitor

import (
"fmt"
"log"
"resource-monitor/backend/types"
"resource-monitor/backend/utils"
"sync"
"time"

"github.com/gen2brain/beeep"
)

var (
AlertEnabled bool
Mu sync.Mutex
DefaultLimit = types.SetLimit{CPUThreshold: 90, MemoryThreshold: 90, DiskThreshold: 90}
)

func sendAlert(resource string, usage float64) {
Mu.Lock()
defer Mu.Unlock()

if !AlertEnabled {
return
}

var threshold float64
switch resource {
case "CPU":
threshold = DefaultLimit.CPUThreshold
case "Memory":
threshold = DefaultLimit.MemoryThreshold
case "Disk":
threshold = DefaultLimit.DiskThreshold
}

if usage > threshold {
err := beeep.Alert(fmt.Sprintf("%s Alert", resource), fmt.Sprintf("%s usage is at %.2f%%!", resource, usage), "")
if err != nil {
log.Println("Error sending macOS notification:", err)
}
}
}

func MonitorResources() {
for {
cpuUsage := utils.GetCPUUsage()
memUsage := utils.GetMemoryUsage()
diskUsage := utils.GetDiskUsage()

sendAlert("CPU", cpuUsage)
sendAlert("Memory", memUsage)
sendAlert("Disk", diskUsage)

time.Sleep(5 * time.Second)
}
}
File renamed without changes.
Binary file removed frontend/output
Binary file not shown.
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BINARY_NAME = monitor
BINARY_NAME = image

GO = go
GOFMT = gofmt
Expand Down
Loading