Skip to main content

Add your description here

Project description

pyexporter

Template for a Prometheus exporter for various metrics.

  • Create a repo from this template
  • Change name of the package, Docker image, docs, examples, etc.
  • Implement your own collectors
  • Enjoy!

Installation

The exporter is written in Python. The simplest way to run it is to use the Docker image.

docker run -d -p 9123:9123 weastur/py-exporter:latest

Additionally, as it's a standard Python package, you can install it with pip or pipx:

pip install py-exporter-template

An isolated installation using a virtual environment can be found in the examples.

Usage

Configuring

There are several ways to configure the exporter (in a priority order):

  • Defaults
  • Command line arguments
  • Environment variables
  • .env file in the current directory
  • Configuration file (config.yaml or config.yml) in the current directory

Defaults and command line arguments

The exporter can be run with or without arguments (using defaults). See the full list of parameters with defaults below.

Environment variables

All parameters can be set with environment variables. The environment variables should be in the following format: PY_EXPORTER_<PARAMETER_PATH> using __ as a nested delimeter (replacing . in command line arguments) For example:

export PY_EXPORTER_LOG__LEVEL=debug
export PY_EXPORTER_COLLECTOR__DEFAULT__GC=false

.env file

The .env file should be in the current directory and follow this format:

PY_EXPORTER_LOG__LEVEL=debug
PY_EXPORTER_COLLECTOR__DEFAULT__GC=false

Configuration file

The configuration file should be in the current directory and follow this format:

log:
  level: debug
web:
  port: 9123
  addr: "0.0.0.0"

See the full example here.

P. S. By the way, you can dump json schema for the configuration file with the following command:

py-exporter jsonschema config.schema.json

Full list of command line arguments

usage: py-exporter [-h]
                   [--log.level {trace,debug,info,success,warning,error,critical}]
                   [--web.port int] [--web.addr IPv4Address]
                   [--web.tls.cert Path] [--web.tls.key Path]
                   [--web.tls.protocol int]
                   [--web.tls.mtls.enabled | --no-web.tls.mtls.enabled]
                   [--web.tls.mtls.cafile Path] [--web.tls.mtls.capath Path]
                   [--collector.disable_created_series | --no-collector.disable_created_series]
                   [--collector.default.gc | --no-collector.default.gc]
                   [--collector.default.platform | --no-collector.default.platform]
                   [--collector.default.process | --no-collector.default.process]
                   {jsonschema} ...

optional arguments:
  -h, --help            show this help message and exit

subcommands:
  {jsonschema}
    jsonschema          Dump the JSON schema to a file.

log options:
  --log.level {trace,debug,info,success,warning,error,critical}
                        Log level (default: info)

web options:
  --web.port int        Port to listen on (default: 9123)
  --web.addr IPv4Address
                        Address to listen on (default: 0.0.0.0)

web.tls options:
  --web.tls.cert Path   Path to the TLS certificate (default: None)
  --web.tls.key Path    Path to the TLS key (default: None)
  --web.tls.protocol int
                        TLS protocol number, as described in the ssl python
                        module (default: 17)

web.tls.mtls options:
  --web.tls.mtls.enabled, --no-web.tls.mtls.enabled
                        Enable mTLS (default: False)
  --web.tls.mtls.cafile Path
                        Path to the client CA file (default: None)
  --web.tls.mtls.capath Path
                        Path to the client CA directory (default: None)

collector options:
  --collector.disable_created_series, --no-collector.disable_created_series
                        Disable created series (default: False)

collector.default options:
  --collector.default.gc, --no-collector.default.gc
                        Enable the GC collector (default: True)
  --collector.default.platform, --no-collector.default.platform
                        Enable the platform collector (default: True)
  --collector.default.process, --no-collector.default.process
                        Enable the process collector (default: True)

Examples

In the examples you can find some useful files to look at:

  • Docker Compose file example
  • Prometheus coinfig to scrape the exporter
  • Grafana dashboard
  • VRL program for Vector
  • SystemD service file for running the exporter outside the container
  • Ansible playbook to deploy it in an isolated environment outside the container
  • Full dump (one scrape) of all metrics exporter can generate. You can investigate it with prom2json

Contributing

Credits

Although the license doesn’t require credits, I maintain a list of authors in the CREDITS file in the alphabetical order.

License

MIT, see LICENSE

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

py_exporter_template-0.0.0.dev0.tar.gz (81.6 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file py_exporter_template-0.0.0.dev0.tar.gz.

File metadata

File hashes

Hashes for py_exporter_template-0.0.0.dev0.tar.gz
Algorithm Hash digest
SHA256 48e0642a3d50bd05398380f2dbb0a6cb2c60e5237bc91c6c14e25ffcda77647a
MD5 8c5179578a0bd9851cdbaa52783dc5dc
BLAKE2b-256 96654622d7e56fb3c72a9468edb1c3ec40f2d5f4941fdf048f6bcd4e635a457f

See more details on using hashes here.

File details

Details for the file py_exporter_template-0.0.0.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for py_exporter_template-0.0.0.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 a224c5151412a5a400d32ff04bb19ee83e0ff23d0428670dea466f3940e3fe50
MD5 cce534e5bac7d39f06ed32c2e830ab7f
BLAKE2b-256 ebe8e5ab5647590fb25c48c79013c7f4b3542f0b2f80ab56167ee847427fdc58

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