Skip to content

Commit

Permalink
Update README file and options descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
larrabee committed Sep 1, 2018
1 parent 264ceca commit 13f17c7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,50 @@ Program to make a proxy (ie HAProxy) capable of monitoring Percona XtraDB Cluste

## Usage

Basic Haproxy config
Basic Haproxy config:
```
listen pxc
bind 127.0.0.1:3306
balance leastconn
option httpchk
option httpchk HEAD /
mode tcp
default-server check port 9200 inter 500 rise 5 fall 5
server node1 1.2.3.4:3306 check port 9200
server node2 1.2.3.5:3306 check port 9200
server node3 1.2.3.6:3306 check port 9200 backup
```

## Setup

1. Create MySQL user:
```sql
create user 'pxc_checker'@'localhost' IDENTIFIED BY 'YourStrongPassword'; GRANT PROCESS ON *.* TO 'pxc_checker'@'localhost';
```
2. Get program binary. You can choose one of the following methods:
- Build it from source code with:
```
go get
go build -o pxc-checker ./...
```
- Download latest compiled binary from [Releases page](https://github.com/larrabee/pxc-checker/releases).
3. Copy binary to `/usr/bin/pxc-checker`
4. Copy systemd unit from `systemd/pxc-check@.service` to `/etc/systemd/system/pxc-checker@.service`
5. Copy example config from `config/example.conf` to `/etc/pxc/checker/cluster.conf` and modify it.
6. Enable and start unit with command: `systemctl enable --now pxc-checker@cluster`
7. Check node status with command: `curl http://127.0.0.1:9200`

## Configuration file options
You can override any of the following values in configuration file:

- `WEB_LISTEN`: Web server listening interface and port in format `{IPADDR}:{PORT}` or `:PORT` for all interfaces. Default: `:9200`
- `WEB_READ_TIMEOUT`: Web server request read timeout in milliseconds. Default: `30000`
- `WEB_WRITE_TIMEOUT`: Web server request write timeout in milliseconds. Default: `30000`
- `CHECK_RO_ENABLED`: Mark 'read_only' node as available. Default: `false`
- `CHECK_FORCE_ENABLE`: Ignoring the status of the checks and always marking the node as available. Default: `false`
- `CHECK_INTERVAL`: Mysql checks interval in milliseconds. Default: `500`
- `CHECK_FAIL_TIMEOUT`: Mark the node inaccessible if for the specified time (in milliseconds) there were no successful checks. Default: `3000`
- `MYSQL_HOST`: MySQL host address. Default: `127.0.0.1`
- `MYSQL_PORT`: MySQL port. Default: `3306`
- `MYSQL_USER`: MySQL username. Default: `pxc_checker`
- `MYSQL_PASS`: Mysql password. Default: no password

17 changes: 9 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,22 @@ func main() {
func getRouter() *fasthttprouter.Router {
router := fasthttprouter.New()
router.GET("/", checkerHandler)
router.HEAD("/", checkerHandler)
return router
}

func parseFlags() (*Config, error) {
config := Config{}
flag.StringVar(&config.WebListen, "WEB_LISTEN", ":9200", "Listen interface and port")
flag.IntVar(&config.WebReadTimeout, "WEB_READ_TIMEOUT", 30000, "Request read timeout, ms")
flag.IntVar(&config.WebWriteTimeout, "WEB_WRITE_TIMEOUT", 30000, "Request write timeout, ms")
flag.BoolVar(&config.CheckROEnabled, "CHECK_RO_ENABLED", false, "Make 'read_only' nodes availible")
flag.BoolVar(&config.CheckForceEnable, "CHECK_FORCE_ENABLE", false, "Ignoring checks status and force enable node")
flag.StringVar(&config.WebListen, "WEB_LISTEN", ":9200", "Web server listening interface and port")
flag.IntVar(&config.WebReadTimeout, "WEB_READ_TIMEOUT", 30000, "Web server request read timeout, ms")
flag.IntVar(&config.WebWriteTimeout, "WEB_WRITE_TIMEOUT", 30000, "Web server request write timeout, ms")
flag.BoolVar(&config.CheckROEnabled, "CHECK_RO_ENABLED", false, "Mark 'read_only' node as available")
flag.BoolVar(&config.CheckForceEnable, "CHECK_FORCE_ENABLE", false, "Ignoring the status of the checks and always marking the node as available")
flag.IntVar(&config.CheckInterval, "CHECK_INTERVAL", 500, "Mysql checks interval, ms")
flag.IntVar(&config.CheckFailTimeout, "CHECK_FAIL_TIMEOUT", 3000, "To count a node inaccessible if for the specified time there were no successful checks, ms")
flag.IntVar(&config.CheckFailTimeout, "CHECK_FAIL_TIMEOUT", 3000, "Mark the node inaccessible if for the specified time there were no successful checks, ms")
flag.StringVar(&config.MysqlHost, "MYSQL_HOST", "127.0.0.1", "MySQL host addr")
flag.IntVar(&config.MysqlPort, "MYSQL_PORT", 3306, "MySQL port addr")
flag.StringVar(&config.MysqlUser, "MYSQL_USER", "monitor", "MySQL username")
flag.IntVar(&config.MysqlPort, "MYSQL_PORT", 3306, "MySQL port")
flag.StringVar(&config.MysqlUser, "MYSQL_USER", "pxc_checker", "MySQL username")
flag.StringVar(&config.MysqlPass, "MYSQL_PASS", "", "MySQL password")

flag.Parse()
Expand Down
1 change: 1 addition & 0 deletions systemd/pxc-check@.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ After=network.target
EnvironmentFile=/etc/pxc/checker/%i.conf
ExecStart=/usr/bin/pxc-checker
KillMode=process
Restart=always
User=mysql
Group=mysql

Expand Down

0 comments on commit 13f17c7

Please sign in to comment.