A resource-friendly, highly efficient, and minimal Prometheus exporter to track Memory, CPU, Disk and Network I/O usage of Docker containers along with their lifecycle (up/down) state used for alerting.
Check out the web page for more information.
see a sample of the metrics page here.
- Port 8000 must be open (default port)
- Docker & Docker Compose should be installed (optional)
- The presence of Git and Python3.10
- fork the repository.
- go to the fork repository and switch to
Action
tab. - click the
I understand my workflows, go ahead and enable them
button. - now you have access to all of the workflows, however make sure you change the secrets listed below accordingly:
secretes.DOCKER_TOKEN
: the personal access token docker hub of your(or your organization) account.secretes.GHCR_TOKEN
: github classic access token with (packages read:write permissions) or just simply use${{github.token}}
. help
here's how workflows work:
- on push to
master
the project will bebuilt
,deployed
andreleased
. since deploying to your servers requires runner configuration it must be triggered manually, you can modify its behavior oncd.yml
workflow. - on push to any branch except for
master
code will bebuilt
andhealthchecked
- on pr the project will be
healthchecked
andbuilt
.
double check the required variables and secrets to prevent any unexpected failures
- clone and checkout to the repository using the following commands:
git clone https://github.com/Shayan-Ghani/Container-exporter.git
cd Container-Exporter
- Deploy the docker-compose file that suits you the best for instance :
# Make the file executable
chmod +x ./start.sh
# With docker compose v1
docker-compose -f container-exporter.yml up -d
# Or using v2
docker compose -f container-exporter.yml up -d
# build from base with Dockerfile
docker-compose -f container-exporter-local.yml up --build -d
# No need if done already
chmod +x ./start.sh
# Set up virtualenv
python3 -m venv venv
source venv/bin/activate
pip install -U pip
# Install the required python packages
pip install -r requirements.txt
# start the initializer script.
./start.sh &
You can use nohup as well :
nohup ./start.sh -out ./nohup.out
# to stop cxp without docker use this command
kill -9 <PID>
Replace <PID>
with the pid of ./start.sh script.
- adjust the following settings for
uvicorn
as environment variables:- HOST (Default: 0.0.0.0)
- PORT (Default: 8000)
- WORKERS (Default : 1)
- LOG_LEVEL (Default : warning)
Example:
PORT="8000" ./start.sh <your custome port> &
- Edit your
prometheus.yml
file and add the address of container-exporter in scrape_configs:
- Reload or restart your Prometheus server and reach out to
http://127.0.0.1:8000/metrics
Check out dashboards directory for Json files. including CPU & Memory usage + containers status (uptime).
Change Your Prometheus data source uid
with the uid of Prometheus data source uid. you can find it this way:
-
Reach out to Grafana then enter
Home > Administration > Data sources
then click on your Prometheus data source. -
the characters after
datasources/edit/
are your uid. (e.g datasources/edit/c8e586ac-4262-4aad5-a103-1240ss826424) -
alternatively, use
dashboard-gen.sh
script to change the dashboards' uid by providing the uid as the first argument of the script. do the following steps:
cd scripts && bash dashboard-gen.sh <your uid>
-
replace
<your uid>
with your Prometheus datasource uid. -
now head to Grafana dashboards and hit
new > import
then copy the dashboard Json file and paste it intoImport via panel json
-
hit the
load
button and Done!
- Disk I/O usage
- Network I/O Usage
- Add metrics in units of byte
- Check and Unregister stat metrics for containers that are not running
- Design and develop a static website to showcase Documentation, new features, etc.
- Enable functionality and smoke testing in ci
- Add
clear_metrics
functionality to switch on clearing the labels or setting them to 0 to maintain time series data, on user's demand. - Design grafana dashboards and share them on grafana cloud
- Add unit tests
Welcome to CXP! This project is production-ready now, and we encourage contributions to enhance its functionality, optimize code, and add new features
Feel free to contribute in any wacacy you can. If you come across a bug or have a suggestion, please don't hesitate to file an issue. Your input is valuable and helps us improve CXP for everyone; Therefore, add any desired function or feature to TO DO section. We appreciate your contribution to making CXP even better! If you have any questions or need assistance, feel free to reach out. Thank you!
- If you want to add metrics to cxp, make sure the naming convention is conformed to. (
cxp_metric_name
)