Implement CheckCle Microservice Operation

A Go-based microservice for service operations including ICMP ping, DNS resolution, and TCP connectivity
This commit is contained in:
Tola Leng
2025-06-19 17:49:30 +07:00
parent 89572c44b7
commit d3ea5dc77c
36 changed files with 2895 additions and 0 deletions
@@ -0,0 +1,52 @@
package monitoring
import (
"log"
"time"
"service-operation/pocketbase"
)
type ServiceMonitor struct {
service pocketbase.Service
ticker *time.Ticker
stopChan chan bool
}
func (ms *MonitoringService) startMonitor(service pocketbase.Service) {
if service.HeartbeatInterval <= 0 {
service.HeartbeatInterval = 60 // Default to 60 seconds
}
monitor := &ServiceMonitor{
service: service,
ticker: time.NewTicker(time.Duration(service.HeartbeatInterval) * time.Second),
stopChan: make(chan bool),
}
ms.activeServices[service.ID] = monitor
log.Printf("Starting monitor for service: %s (%s)", service.Name, service.ServiceType)
go func() {
// Perform initial check
ms.performCheck(service)
for {
select {
case <-monitor.ticker.C:
ms.performCheck(service)
case <-monitor.stopChan:
monitor.ticker.Stop()
return
}
}
}()
}
func (ms *MonitoringService) stopMonitor(serviceID string, monitor *ServiceMonitor) {
log.Printf("Stopping monitor for service: %s", serviceID)
monitor.stopChan <- true
delete(ms.activeServices, serviceID)
}