Add timeout customization
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"threshold": 80,
|
||||
"component_id": 1,
|
||||
"interval": 10,
|
||||
"timeout": 5,
|
||||
"expected_status_code": 200,
|
||||
"strict_tls": true
|
||||
}
|
||||
|
||||
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user