Add documentation in watchdog.go
This commit is contained in:
parent
f930687b4a
commit
946101e995
@ -15,10 +15,12 @@ var (
|
|||||||
rwLock sync.RWMutex
|
rwLock sync.RWMutex
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetServiceResults returns a list of the last 20 results for each services
|
||||||
func GetServiceResults() *map[string][]*core.Result {
|
func GetServiceResults() *map[string][]*core.Result {
|
||||||
return &serviceResults
|
return &serviceResults
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Monitor loops over each services and starts a goroutine to monitor each services separately
|
||||||
func Monitor(cfg *config.Config) {
|
func Monitor(cfg *config.Config) {
|
||||||
for _, service := range cfg.Services {
|
for _, service := range cfg.Services {
|
||||||
go monitor(service)
|
go monitor(service)
|
||||||
@ -27,12 +29,13 @@ func Monitor(cfg *config.Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// monitor monitors a single service in a loop
|
||||||
func monitor(service *core.Service) {
|
func monitor(service *core.Service) {
|
||||||
for {
|
for {
|
||||||
// By placing the lock here, we prevent multiple services from being monitored at the exact same time, which
|
// By placing the lock here, we prevent multiple services from being monitored at the exact same time, which
|
||||||
// could cause performance issues and return inaccurate results
|
// could cause performance issues and return inaccurate results
|
||||||
rwLock.Lock()
|
rwLock.Lock()
|
||||||
log.Printf("[watchdog][Monitor] Monitoring serviceName=%s", service.Name)
|
log.Printf("[watchdog][monitor] Monitoring serviceName=%s", service.Name)
|
||||||
result := service.EvaluateConditions()
|
result := service.EvaluateConditions()
|
||||||
metric.PublishMetricsForService(service, result)
|
metric.PublishMetricsForService(service, result)
|
||||||
serviceResults[service.Name] = append(serviceResults[service.Name], result)
|
serviceResults[service.Name] = append(serviceResults[service.Name], result)
|
||||||
@ -45,13 +48,13 @@ func monitor(service *core.Service) {
|
|||||||
extra = fmt.Sprintf("responseBody=%s", result.Body)
|
extra = fmt.Sprintf("responseBody=%s", result.Body)
|
||||||
}
|
}
|
||||||
log.Printf(
|
log.Printf(
|
||||||
"[watchdog][Monitor] Finished monitoring serviceName=%s; errors=%d; requestDuration=%s; %s",
|
"[watchdog][monitor] Finished monitoring serviceName=%s; errors=%d; requestDuration=%s; %s",
|
||||||
service.Name,
|
service.Name,
|
||||||
len(result.Errors),
|
len(result.Errors),
|
||||||
result.Duration.Round(time.Millisecond),
|
result.Duration.Round(time.Millisecond),
|
||||||
extra,
|
extra,
|
||||||
)
|
)
|
||||||
log.Printf("[watchdog][Monitor] Waiting interval=%s before monitoring serviceName=%s", service.Interval, service.Name)
|
log.Printf("[watchdog][monitor] Waiting for interval=%s before monitoring serviceName=%s", service.Interval, service.Name)
|
||||||
time.Sleep(service.Interval)
|
time.Sleep(service.Interval)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user