Welcome to p3exporter’s documentation!¶
Python programmable Prometheus exporter¶
PyPI version Codacy Badge Documentation Status
This repo should help any DevOps to quickstart its Prometheus exporter development base on Python. It is a POC which shows how different packages and libraries can be put together to create your own exporter for Prometheus.
The project is based on Flask as web framework and Prometheus python-client. We also provide a simple Dockerfile to enable you to build a Docker container image for your exporter as well as let it run as a simple program.
install and run locally¶
To install the p3exporter
package you simply run the following command inside the project directory:
$ pip install -e .
Obtaining file:///home/nero/Development/p3exporter
...
Installing collected packages: p3exporter
Running setup.py develop for p3exporter
Successfully installed p3exporter
From now you can run it with:
$ p3exporter
INFO:root:Start exporter, listen on 5876
available command line options¶
Do determine the available command line options you can call the online help:
$ p3exporter --help
usage: p3exporter [-h] [-c CONFIG] [-p PORT]
Python programmable Prometheus exporter.
optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
path to configuration file.
-p PORT, --port PORT exporter exposed port
build image and run in docker¶
To let the exporter run in docker you have to do the following:
$ docker build -t codeaffen/p3exporter .
Sending build context to Docker daemon 181.8kB
...
Successfully built a6bdf60489f5
Successfully tagged codeaffen/p3exporter:latest
Now you can start the container. Don’t forget to expose the port to your network.
$ docker run -d -p 5876:5876 --name p3e codeaffen/p3exporter
03e287d50cce595cec6ee66d75a663a094ba7688c761303e7e1e9ad39bde695c
access exporter¶
If your exporter run either as local program or as docker container you can access it with your webbrowser.
metrics in browser
CHANGELOG¶
All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning and Keep a Changelog.
p3exporter¶
p3exporter package¶
Init methods for p3exporter package.
Subpackages¶
p3exporter.collector package¶
Entry point for collector sub module.
-
class
p3exporter.collector.
Collector
(config: p3exporter.collector.CollectorConfig)[source]¶ Bases:
object
Base class to load collectors.
All collectors have to be placed inside the directory collector. You have to follow the naming convention:
Place the collector code in a <name>.py file (e.g. my.py)
Within the file <name>.py` a class <Name>Collector (e.g. MyController) needs to be defined. This is the main collector class which will be imported, instantiate and registered automatically.
-
class
p3exporter.collector.
CollectorConfig
(**kwargs)[source]¶ Bases:
object
Class that provide all the logic needed for configuration handling.
Submodules¶
p3exporter.collector.loadavg module¶
-
class
p3exporter.collector.loadavg.
LoadavgCollector
(config: p3exporter.collector.CollectorConfig)[source]¶ Bases:
object
Submodules¶
p3exporter.web module¶
Web module provide all parts to create the web app.
-
p3exporter.web.
create_app
(config: p3exporter.collector.CollectorConfig)[source]¶ Create the web app.
This Function creates the flask app and dispatch metrics endpoint to prometheus wsgi app.
- Parameters
config (CollectorConfig) – A configuration object with data for template rendering.
- Returns
Created web app object.
- Return type
DispatcherMiddleware
How to contribute to p3exporter¶
Did you found a bug¶
Make sure the bug is not already opened by another user.
If you can’t find an open issue which reflects your observed problem go ahead an open a new bug.
Provide as much information as mentioned in the bug report template.
Did you wrote a patch for an open bug¶
Open new pull request containing the patch.
Provide a clear description which describes the problem and the solution. Link the existing bug to the PR.
Do you want to add a new feature¶
Make sure there isn’t already a feature request.
If you can’t find an open feature request which describe your feature idea or parts of it feel free to open a new feature request.
Suggest your feature idea within the created feature request.
Provide as much discribtion as possible to enable others to have a good understanding of what you are doing.
Point out that you want to start to work on the new feature
Do you wnat to contribute to documentation¶
Write you documentation change.
Open a PR with your change.
Discuss with the team about your changes.
Thank you for any contribution¶
We will thank you for heed the contribution guidelines and we encourage you to contribute and join the team.