From 946101e995e392433ecafbb295f9bffb65d235f1 Mon Sep 17 00:00:00 2001 From: TwinProduction Date: Mon, 17 Aug 2020 20:25:29 -0400 Subject: [PATCH] Add documentation in watchdog.go --- watchdog/watchdog.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/watchdog/watchdog.go b/watchdog/watchdog.go index d52eaf01..347341c0 100644 --- a/watchdog/watchdog.go +++ b/watchdog/watchdog.go @@ -15,10 +15,12 @@ var ( rwLock sync.RWMutex ) +// GetServiceResults returns a list of the last 20 results for each services func GetServiceResults() *map[string][]*core.Result { return &serviceResults } +// Monitor loops over each services and starts a goroutine to monitor each services separately func Monitor(cfg *config.Config) { for _, service := range cfg.Services { 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) { for { // 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 rwLock.Lock() - log.Printf("[watchdog][Monitor] Monitoring serviceName=%s", service.Name) + log.Printf("[watchdog][monitor] Monitoring serviceName=%s", service.Name) result := service.EvaluateConditions() metric.PublishMetricsForService(service, 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) } 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, len(result.Errors), result.Duration.Round(time.Millisecond), 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) } }