diff --git a/cli/main.go b/cli/main.go index 3a03906..35a4c0d 100644 --- a/cli/main.go +++ b/cli/main.go @@ -53,7 +53,7 @@ func main() { wg := &sync.WaitGroup{} for _, mon := range cfg.Monitors { - cfg.Logger.Printf(" Starting %s: %d seconds check interval\n - %v %s", mon.Name, mon.CheckInterval, mon.Method, mon.URL) + cfg.Logger.Printf(" Starting %s: %d seconds check interval\n - %v %s (%d second/s timeout)", mon.Name, mon.CheckInterval, mon.Method, mon.URL, mon.HttpTimeout) // print features if mon.ExpectedStatusCode > 0 { diff --git a/example.config.json b/example.config.json index 8b663cf..15d5882 100644 --- a/example.config.json +++ b/example.config.json @@ -9,6 +9,7 @@ "threshold": 80, "component_id": 1, "interval": 10, + "timeout": 5, "expected_status_code": 200, "strict_tls": true } diff --git a/monitor.go b/monitor.go index d28d6f4..593bf5d 100644 --- a/monitor.go +++ b/monitor.go @@ -13,8 +13,8 @@ import ( "time" ) -const HttpTimeout = time.Duration(time.Second) const DefaultInterval = 60 +const DefaultTimeout = 1 const DefaultTimeFormat = "15:04:05 Jan 2 MST" // Monitor data model @@ -24,6 +24,7 @@ type Monitor struct { Method string `json:"method"` StrictTLS bool `json:"strict_tls"` CheckInterval time.Duration `json:"interval"` + HttpTimeout time.Duration `json:"timeout"` MetricID int `json:"metric_id"` ComponentID int `json:"component_id"` @@ -100,7 +101,7 @@ func (monitor *Monitor) Tick() { func (monitor *Monitor) doRequest() bool { client := &http.Client{ - Timeout: HttpTimeout, + Timeout: time.Duration(monitor.HttpTimeout * time.Second), } if monitor.StrictTLS == false { client.Transport = &http.Transport{ @@ -213,6 +214,10 @@ func (monitor *Monitor) ValidateConfiguration() error { monitor.CheckInterval = DefaultInterval } + if monitor.HttpTimeout < 1 { + monitor.HttpTimeout = DefaultTimeout + } + monitor.Method = strings.ToUpper(monitor.Method) switch monitor.Method { case "GET", "POST", "DELETE", "OPTIONS", "HEAD": diff --git a/readme.md b/readme.md index 1a9f1aa..b273079 100644 --- a/readme.md +++ b/readme.md @@ -32,6 +32,8 @@ Configuration "strict_tls": true, // seconds between checks "interval": 10, + // seconds for http timeout + "timeout": 5, // post lag to cachet metric (graph) // note either metric ID or component ID are required "metric_id": ,