From 01c0c59467fd0b54e6063f3e9a2004aadcf7bcae Mon Sep 17 00:00:00 2001 From: 7heo <7heo@mail.com> Date: Fri, 24 Mar 2017 05:18:00 +0100 Subject: [PATCH 1/5] REF run.sh: no need for bash, no need for export --- run.sh | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/run.sh b/run.sh index 8f79c1a..a05909e 100755 --- a/run.sh +++ b/run.sh @@ -1,17 +1,17 @@ -#!/bin/bash - -export HOUND_GRAPHITE_BASE="http://nanny.cul.columbia.edu/render/" -export HOUND_CARBON_BASE="nanny.cul.columbia.edu:2003" -export HOUND_METRIC_BASE="ccnmtl.app.gauges.hounddev." -export HOUND_EMAIL_FROM="hound@thraxil.org" -export HOUND_EMAIL_TO="anders@columbia.edu" -export HOUND_CHECK_INTERVAL=1 -export HOUND_GLOBAL_THROTTLE=10 -export HOUND_HTTP_PORT=9998 -export HOUND_TEMPLATE_FILE="index.html" -export HOUND_EMAIL_ON_ERROR=false -export HOUND_SMTP_SERVER=postgres -export HOUND_SMTP_PORT=25 -export HOUND_LOG_LEVEL=DEBUG +#!/bin/sh +HOUND_GRAPHITE_BASE="http://nanny.cul.columbia.edu/render/" \ +HOUND_CARBON_BASE="nanny.cul.columbia.edu:2003" \ +HOUND_METRIC_BASE="ccnmtl.app.gauges.hounddev." \ +HOUND_EMAIL_FROM="hound@thraxil.org" \ +HOUND_EMAIL_TO="anders@columbia.edu" \ +HOUND_CHECK_INTERVAL=1 \ +HOUND_GLOBAL_THROTTLE=10 \ +HOUND_HTTP_PORT=9998 \ +HOUND_TEMPLATE_FILE="index.html" \ +HOUND_EMAIL_ON_ERROR=false \ +HOUND_SMTP_SERVER=postgres \ +HOUND_SMTP_PORT=25 \ +HOUND_LOG_LEVEL=DEBUG \ +\ ./hound -config=config.json From 7c92ecabecd94a765e9f51ffa9500b71915a0b6e Mon Sep 17 00:00:00 2001 From: 7heo <7heo@mail.com> Date: Fri, 24 Mar 2017 06:18:48 +0100 Subject: [PATCH 2/5] FIX Makefile and run.sh: invert logic Hound shouldn't be ran from the makefile, but rather it has to be ensured that hound exists before being ran, in the shell script. That way it is more logical, and people only have to type `./run.sh` --- Makefile | 3 --- run.sh | 6 ++++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index a9f5025..c0718fe 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,6 @@ hound: hound.go smtp.go alert.go alertscollection.go config.go fmt: go fmt *.go -run: hound - ./run.sh - test: go test . diff --git a/run.sh b/run.sh index a05909e..7c61c4d 100755 --- a/run.sh +++ b/run.sh @@ -1,5 +1,11 @@ #!/bin/sh +set -e + +make hound + +echo "Running hound..." + HOUND_GRAPHITE_BASE="http://nanny.cul.columbia.edu/render/" \ HOUND_CARBON_BASE="nanny.cul.columbia.edu:2003" \ HOUND_METRIC_BASE="ccnmtl.app.gauges.hounddev." \ From 17afce0f87c9097976a4514a3dbe948e84570730 Mon Sep 17 00:00:00 2001 From: 7heo <7heo@mail.com> Date: Fri, 24 Mar 2017 06:20:39 +0100 Subject: [PATCH 3/5] REF Makefile: Useless shell use, PHONY rules Also, when creating a file with a rule, it is a good practice to make the rule named after that file, so make can ensure it is up to date. --- Makefile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c0718fe..df6bb2d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) +ROOT_DIR:=$(dir $(realpath $(lastword $(MAKEFILE_LIST)))) all: hound @@ -11,8 +11,12 @@ fmt: test: go test . -coverage: +coverage: coverage.html + +coverage.out: go test . -coverprofile=coverage.out + +coverage.html: coverage.out go tool cover -html=coverage.out -o coverage.html build: @@ -20,3 +24,5 @@ build: push: build docker push ccnmtl/hound + +.PHONY: all fmt run test coverage build push From 1e8274130a5a8faf9113b65d0bd4320bcf856733 Mon Sep 17 00:00:00 2001 From: 7heo <7heo@mail.com> Date: Fri, 24 Mar 2017 06:25:57 +0100 Subject: [PATCH 4/5] FIX README.md: Better instructions --- README.md | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d0ede1e..cbbf933 100644 --- a/README.md +++ b/README.md @@ -12,15 +12,33 @@ minutes after that, one hour after that, 2 hours after that, 4 hours, 8 hours, then every 24 hours thereafter. Finally, you will get an email when the metric has recovered. +### Dependencies + +1. Obviously enough, hound need a running graphite server, accessible via + network. +2. In addition, an SMTP host is necessary (without authentication or + encryption) to send the emails out. + +### Usage + +1. Edit the file `run.sh` with the correct values for your use. +2. run `./run.sh` (preferrably in a detachable session or with `nohup`) + ### Configuration -* `GraphiteBase`, `EmailFrom`, and `EmailTo` should all be obvious +The main configuration happens (as noted above) in `run.sh`. + * `CheckInterval` is how many minutes to wait between checks -* `GlobalThrottle` is the maximum number of alerts that Hound will - send in a cycle. Ie, if there's a major network outage and all the - metrics start failing, you want to stop it once you've figured that - out. Once this threshold is passed, Hound sends just one more message - saying how many metrics are failing. +* `GlobalThrottle` is the maximum number of alerts that Hound will send in a + cycle. Ie, if there's a major network outage and all the metrics start + failing, you want to stop it once you've figured that out. Once this + threshold is passed, Hound sends just one more message saying how many + metrics are failing. + +The rest of the values in this file should be self-explanatory. + +The alerts configuration is set in `config.json` (by default - it is passed as +an argument to `hound` in `run.sh`). Each Alert has: From 1e6a92270da3be05d02e8f5baff244afdbe69df2 Mon Sep 17 00:00:00 2001 From: 7heo <7heo@mail.com> Date: Fri, 24 Mar 2017 06:26:58 +0100 Subject: [PATCH 5/5] FIX run.sh: Use nohup to allow ending the session --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index 7c61c4d..2d4bdd9 100755 --- a/run.sh +++ b/run.sh @@ -20,4 +20,4 @@ HOUND_SMTP_SERVER=postgres \ HOUND_SMTP_PORT=25 \ HOUND_LOG_LEVEL=DEBUG \ \ -./hound -config=config.json +>hound.out 2>hound.err