mysql-healthcheck

command module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

README

mysql-healthcheck

Go Go Report Card reviewdog Build Release License Downloads Issues

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
  1. Download and extract the appropriate binary for your architecture to /usr/local/bin/
  2. Make the binary executable with chmod +x /usr/local/bin/mysql-healthcheck
  3. Create a configuration file as instructed below.
  4. For systemd installation:
    1. Place the mysql-healthcheck.service unit file in your systemd system service directory (usually /etc/systemd/system/).
    2. Enable the service with systemd enable mysql-healthcheck.service
  5. Run the application from the command line, or run systemd start mysql-healthcheck to start the service.
Windows
  1. Download and unzip the appropriate binary to any filesystem location.
  2. Create a configuration file as instructed below.
  3. Run the application from the command line, or follow the appropriate steps for your platform to run it as an OS service.
Other Platforms

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

Documentation

Overview

Config.go provides the program configuration using the Viper library.

Database.go provides the connection and health checking logic for the target database.

mysql-healthcheck is a self-contained binary to run health checks on MySQL and MariaDB clusters.

The mysql-healthcheck utility queries a target database to determine the WSREP status of the host and returns a HTTP response based on the outcome. It supports Percona XtraDB, Galera, and other wsrep-based clustering applications.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL