Skip to main content

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!

Release files for prometheus-mysql-exporter 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prometheus-mysql-exporter 0.5.0
File Size Uploaded
prometheus-mysql-exporter-0.5.0.tar.gz 12.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for prometheus-mysql-exporter 0.5.0
File Interpreter ABI Platform
prometheus_mysql_exporter-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.2 kB

Release files / prometheus-mysql-exporter-0.5.0.tar.gz

Download URL prometheus-mysql-exporter-0.5.0.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d1bfba7c51f42c7ccd18e7e9a4ee11ed52389d9d335cb9eb724b73c2198f8490
BLAKE2b-256 checksum
How to use checksums
afcd5828d422a3bfd089ebfa39cad30fce48f777958123920cd57059b35205b3
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / prometheus_mysql_exporter-0.5.0-py3-none-any.whl

Download URL prometheus_mysql_exporter-0.5.0-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
319266a89b2bb448fb320582304f703a5d1eba406876fe4275545c2551890395
BLAKE2b-256 checksum
How to use checksums
ee49adada29d92adb44cf918346f88439690758ed84d680e7935240527f06773
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page