Skip to main content

MySQL query Prometheus exporter

Project description

Prometheus MySQL Exporter

This Prometheus exporter periodically runs configured queries against a MySQL server and exports the results as Prometheus gauge metrics.

Source Code | Python Package | Docker Image | Helm Chart

Installation

The exporter requires Python 3 and Pip 3 to be installed.

To install the latest published version via Pip, run:

> pip3 install prometheus-mysql-exporter

Note that you may need to add the start script location (see pip output) to your PATH.

Usage

Once installed, you can run the exporter with the prometheus-mysql-exporter command.

By default, it will bind to port 9207, query MySQL on localhost:3306 using the root user (with no password) and run queries configured in a file exporter.cfg in the working directory. You can change any defaults or other settings as required by passing in options:

> prometheus-mysql-exporter -p <port> -s <mysql server> -u <mysql username> -P <mysql password> -z <local timezone> -c <path to query config file>

Run with the -h flag to see details on all the available options.

Note that all options can be set via environment variables. The environment variable names are prefixed with MYSQL_EXPORTER, e.g. MYSQL_EXPORTER_MYSQL_USER=fred is equivalent to --mysql-user fred. CLI options take precidence over environment variables.

Command line options can also be set from a configuration file, by passing --config FILE. The format of the file should be Configobj's unrepre mode, so instead of --mysql-user fred you could use a configuration file config_file with mysql-user="fred" in it, and pass --config config_file. CLI options and environment variables take precedence over configuration files.

CLI options, environment variables, and configuration files all override any default options. The full resolution order for a given option is: CLI > Environment > Configuration file > Default.

See the provided exporter.cfg file for query configuration examples and explanation.

Docker

Docker images for released versions can be found on Docker Hub (note that no latest version is provided):

> sudo docker pull braedon/prometheus-mysql-exporter:<version>

To run a container successfully, you will need to mount a query config file to /usr/src/app/exporter.cfg and map container port 9207 to a port on the host. Any options placed after the image name (prometheus-mysql-exporter) will be passed to the process inside the container. For example, you will need to use this to configure the MySQL server using -s.

> sudo docker run --rm --name exporter \
    -v <path to query config file>:/usr/src/app/exporter.cfg \
    -p <host port>:9207 \
    braedon/prometheus-mysql-exporter:<version> -s <mysql server>

If you don't want to mount the query config file in at run time, you could extend an existing image with your own Dockerfile that copies the config file in at build time.

Helm

A Helm chart is available from the Helm repo at https://braedon.github.io/helm.

> helm repo add braedon https://braedon.github.io/helm
> helm repo update

> helm install braedon/prometheus-mysql-exporter --name <release name> \
                                                 --set mysql.server=<mysql server address> \
                                                 --set image.tag=<image tag>

See the prometheus-mysql-exporter chart README for more details on how to configure the chart.

Development

To install directly from the git repo, run the following in the root project directory:

> pip3 install .

The exporter can be installed in "editable" mode, using pip's -e flag. This allows you to test out changes without having to re-install.

> pip3 install -e .

To build a docker image directly from the git repo, run the following in the root project directory:

> sudo docker build -t <your repository name and tag> .

Send me a PR if you have a change you want to contribute!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prometheus-mysql-exporter-0.5.0.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

prometheus_mysql_exporter-0.5.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file prometheus-mysql-exporter-0.5.0.tar.gz.

File metadata

  • Download URL: prometheus-mysql-exporter-0.5.0.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.1

File hashes

Hashes for prometheus-mysql-exporter-0.5.0.tar.gz
Algorithm Hash digest
SHA256 d1bfba7c51f42c7ccd18e7e9a4ee11ed52389d9d335cb9eb724b73c2198f8490
MD5 dd2d9356b678c1a5bcd5a551d39238f3
BLAKE2b-256 afcd5828d422a3bfd089ebfa39cad30fce48f777958123920cd57059b35205b3

See more details on using hashes here.

File details

Details for the file prometheus_mysql_exporter-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: prometheus_mysql_exporter-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.1

File hashes

Hashes for prometheus_mysql_exporter-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 319266a89b2bb448fb320582304f703a5d1eba406876fe4275545c2551890395
MD5 190f0ecad28e1cf0b5838e909a771777
BLAKE2b-256 ee49adada29d92adb44cf918346f88439690758ed84d680e7935240527f06773

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page