Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script checks #12

Merged
merged 9 commits into from
Jan 11, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# health-checker

A simple HTTP server that will return `200 OK` if the given TCP ports are all successfully accepting connections.
A simple HTTP server that will return `200 OK` if the configured checks are all successful. If any of the checks fail,
it will return `HTTP 504 Gateway Not Found`.

## Motivation

Expand All @@ -14,15 +15,23 @@ a single TCP port, or an HTTP(S) endpoint. As a result, our use case just isn't
We wrote health-checker so that we could run a daemon on the server that reports the true health of the server by
attempting to open a TCP connection to more than one port when it receives an inbound HTTP request on the given listener.

Using the `--script` -option, the `health-checker` can be extended to check many other targets. One concrete exeample is monitoring
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/exeample/example/

`ZooKeeper` node status during rolling deployment. Just polling the `ZooKeeper`'s TCP client port doesn't necessarily guarantee
that the node has (re-)joined the cluster. Using the `health-check` with a custom script target, we can
[monitor ZooKeeper](https://zookeeper.apache.org/doc/r3.4.8/zookeeperAdmin.html#sc_monitoring) using the
[4 letter words](https://zookeeper.apache.org/doc/r3.4.8/zookeeperAdmin.html#sc_zkCommands), ensuring we report health back to the
[Load Balancer](https://aws.amazon.com/documentation/elastic-load-balancing/) correctly.

## How It Works

When health-checker is started, it will listen for inbound HTTP requests for any URL on the IP address and port specified
by `--listener`. When it receives a request, it will attempt to open TCP connections to each of the ports specified by
an instance of `--port`. If all TCP connections succeed, it will return `HTTP 200 OK`. If any TCP connection fails, it
will return `HTTP 504 Gateway Not Found`.
an instance of `--port` and/or execute the script target specified by `--script`. If all configured checks - all TCP
connections and zero exit status for the script - succeed, it will return `HTTP 200 OK`. If any of the checks fail,
it will return `HTTP 504 Gateway Not Found`.

Configure your AWS Health Check to only pass the Health Check on `HTTP 200 OK`. Now when an HTTP Health Check request
comes in, all desired TCP ports will be checked.
comes in, all desired TCP ports will be checked and the script target executed.

For stability, we recommend running health-checker under a process supervisor such as [supervisord](http://supervisord.org/)
or [systemd](https://www.freedesktop.org/wiki/Software/systemd/) to automatically restart health-checker in the unlikely
Expand All @@ -46,9 +55,10 @@ health-checker [options]
| `--listener` | The IP address and port on which inbound HTTP connections will be accepted. | `0.0.0.0:5000`
| `--log-level` | Set the log level to LEVEL. Must be one of: `panic`, `fatal`, `error,` `warning`, `info`, or `debug` | `info`
| `--help` | Show the help screen | |
| `--script` | Path to script to run - will PASS if it completes within 5s with a zero exit status | |
autero1 marked this conversation as resolved.
Show resolved Hide resolved
| `--version` | Show the program's version | |

#### Example
#### Example 1

Run a listener on port 6000 that accepts all inbound HTTP connections for any URL. When the request is received,
attempt to open TCP connections to port 5432 and 3306. If both succeed, return `HTTP 200 OK`. If any fails, return `HTTP
Expand All @@ -58,3 +68,23 @@ attempt to open TCP connections to port 5432 and 3306. If both succeed, return `
health-checker --listener "0.0.0.0:6000" --port 5432 --port 3306
```

#### Example 2

Run a listener on port 6000 that accepts all inbound HTTP connections for any URL. When the request is received,
attempt to run the script. If exit code is zero, return `HTTP 200 OK`. If any other exit code, return `HTTP
504 Gateway Not Found`.

```
health-checker --listener "0.0.0.0:6000" --script /path/to/script.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you show an example of how you'd pass args to the script?

```

#### Example 3

Run a listener on port 6000 that accepts all inbound HTTP connections for any URL. When the request is received,
attempt to open TCP connection to port 8000 and run the script. If both succeed, return `HTTP 200 OK`. If either fails, return `HTTP
504 Gateway Not Found`.

```
health-checker --listener "0.0.0.0:6000" --port 8000 --script /usr/local/bin/zk-health-check.sh
```