mysql-healthcheck
A self-contained binary to run health checks on MySQL and MariaDB clusters. Supports Percona XtraDB, Galera, and other wsrep-based clustering applications.
Installation
Linux
- Download and extract the appropriate binary for your architecture to
/usr/local/bin/
- Make the binary executable with
chmod +x /usr/local/bin/mysql-healthcheck
- Create a configuration file as instructed below.
- For systemd installation:
- Place the
mysql-healthcheck.service
unit file in your systemd system service directory (usually /etc/systemd/system/
).
- Enable the service with
systemd enable mysql-healthcheck.service
- Run the application from the command line, or run
systemd start mysql-healthcheck
to start the service.
Windows
- Download and unzip the appropriate binary to any filesystem location.
- Create a configuration file as instructed below.
- Run the application from the command line, or follow the appropriate steps for your platform to run it as an OS service.
Compile a binary for your target OS and architecture with go build -ldflags="-X 'main.version=custom'"
.
Usage
-V Print version and exit
-d Run as a daemon and listen for HTTP connections on a socket
-v Verbose (debug) logging
The application will default to standalone mode, running one check and sending the result to stdout and setting the exit code accordingly. This can be used for non-HTTP-based health checking needs, or to test changes to your config file.
Example:
root@database01:~# mysql-healthcheck
time="2020-04-26T05:00:30Z" level=info msg="MySQL cluster node is ready."
root@database01:~# mysql-healthcheck -v
time="2020-04-26T05:00:31Z" level=debug msg="Config loaded from /etc/default/mysql-healthcheck.yaml"
time="2020-04-26T05:00:31Z" level=debug msg="Constructed DSN for MySQL: testuser:<redacted>@tcp(database01.mydomain.net:3306)/?timeout=1s&tls=true"
time="2020-04-26T05:00:31Z" level=debug msg="Running standalone health check."
time="2020-04-26T05:00:31Z" level=info msg="MySQL cluster node is ready."
Configuration
Location
Config files must be located in one of the following locations:
- Linux
/etc/sysconfig/
/etc/default/
/etc/
$HOME/.config/
- Windows
%PROGRAMFILES%
%LOCALAPPDATA%
- All Platforms
- Current working directory of the application
Syntax
Config files can be stored in any format supported by Viper, including JSON, TOML, YAML, and more.
The config file must be named mysql-healthcheck
followed by the appropriate suffix for the file format (e.g. .yaml
, .json
)
Parameters
- connection: Parameters pertaining to the database connection
- host: The hostname or IP address of the database server (default:
localhost
)
- port: The port to connect to MySQL (default:
3306
)
- user: A username to authenticate to the database server (optional)
- password: The password of the configured user (optional)
- tls: Parameters pertaining to connection-level encryption
- required: If
true
, require TLS encryption on the connection (default: false
)
- skip-verify: If
true
, accept any certificate without question (default: false
)
- ca: File path to a trusted CA certificate in PEM format (optional)
- cert: File path to a client certificate in PEM format (optional)
- key: File path to a client private key in PEM format (optional)
- http: Parameters pertaining to running mysql-healthcheck as a service with the
-d
flag
- addr: Address to listen on (default:
::
(All v4/v6 addresses))
- port: Port to bind to (default:
5678
)
- path: URI path to serve health checks at - for example,
/status
or /health
(default: /
)
- options: Parameters pertaining to health checks
- available_when_donor: If
true
, nodes that are donors for SST will be reported as available (default: false
)
- available_when_readonly: If
true
, nodes that are in read-only mode due to donor activities will be reported as available (default: false
)
Example
connection:
host: database01.mydomain.net
user: testuser
password: WA68fARS1TZz2NkK
tls:
required: true
skip-verify: false
ca: /etc/ssl/certs/my_ca.pem
cert: /etc/ssl/certs/client_cert.pem
key: /etc/ssl/private/client_key.pem
http:
addr: 10.24.20.48
port: 8080
path: /status
options:
available_when_donor: false
available_when_readonly: false