diff --git a/http.go b/http.go index 602d9d1..3391174 100644 --- a/http.go +++ b/http.go @@ -36,8 +36,8 @@ func (monitor *CachetMonitor) makeRequest(requestType string, url string, reqBod } // SendMetric sends lag metric point -func (monitor *CachetMonitor) SendMetric(metricID int, delay int64) error { - if metricID <= 0 { +func (monitor *Monitor) SendMetric(delay int64) error { + if monitor.MetricID == 0 { return nil } @@ -45,7 +45,7 @@ func (monitor *CachetMonitor) SendMetric(metricID int, delay int64) error { "value": delay, }) - resp, _, err := monitor.makeRequest("POST", "/metrics/"+strconv.Itoa(metricID)+"/points", jsonBytes) + resp, _, err := monitor.config.makeRequest("POST", "/metrics/"+strconv.Itoa(monitor.MetricID)+"/points", jsonBytes) if err != nil || resp.StatusCode != 200 { return fmt.Errorf("Could not log data point!\n%v\n", err) } diff --git a/monitor.go b/monitor.go index 93b3de5..b556d0b 100644 --- a/monitor.go +++ b/monitor.go @@ -112,7 +112,7 @@ func (monitor *Monitor) Tick() { monitor.AnalyseData() if isUp == true && monitor.MetricID > 0 { - monitor.config.SendMetric(monitor.MetricID, lag) + monitor.SendMetric(lag) } } diff --git a/readme.md b/readme.md index b2fd71d..aa0a9fb 100644 --- a/readme.md +++ b/readme.md @@ -14,34 +14,50 @@ Configuration ``` { + // URL for the API. Note: Must end with /api/v1 "api_url": "https:///api/v1", + // Your API token for Cachet "api_token": "", - "insecure_api": false, // optional, false default, set if your certificate is self-signed/untrusted + // optional, false default, set if your certificate is self-signed/untrusted + "insecure_api": false, "monitors": [{ - "name": "Name of your monitor", // required, friendly name for your monitor - "url": "Ping URL", // required, url to probe - "method": "get", // optional, http method (defaults GET) - "strict_tls": true, // self-signed ssl certificate - "interval": 10, // seconds between checks - "metric_id": , // post lag to cachet metric (graph) - "component_id": , // post incidents to this component - "threshold": 80, // If % of downtime is over this threshold, open an incident - "expected_status_code": 200, // optional, expected status code (either status code or body must be supplied) - "expected_body": "P.*NG" // optional, regular expression + // required, friendly name for your monitor + "name": "Name of your monitor", + // required, url to probe + "url": "Ping URL", + // optional, http method (defaults GET) + "method": "get", + // self-signed ssl certificate + "strict_tls": true, + // seconds between checks + "interval": 10, + // post lag to cachet metric (graph) + // note either metric ID or component ID are required + "metric_id": , + // post incidents to this component + "component_id": , + // If % of downtime is over this threshold, open an incident + "threshold": 80, + // optional, expected status code (either status code or body must be supplied) + "expected_status_code": 200, + // optional, regular expression to match body content + "expected_body": "P.*NG" }], - "system_name": "", // optional, system name to identify bot - "log_path": "" // optional, defaults to stdout + // optional, system name to identify bot (uses hostname by default) + "system_name": "", + // optional, defaults to stdout + "log_path": "" } ``` Installation ------------ -1. Download binary from release page +1. Download binary from [release page](https://github.com/CastawayLabs/cachet-monitor/releases) 2. Create your configuration ([example](https://raw.githubusercontent.com/CastawayLabs/cachet-monitor/master/example.config.json)) 3. `cachet-monitor -c /etc/cachet-monitor.config.json` -tip: run in background using `nohup cachet-monitor 2>&1 > /var/log/cachet-monitor.log &` +pro tip: run in background using `nohup cachet-monitor 2>&1 > /var/log/cachet-monitor.log &` ``` Usage of cachet-monitor: