The GitLab Prometheus Exporter is a FastAPI application that exposes GitLab access metrics for Prometheus. It retrieves access data from GitLab and provides it in a format that can be scraped by Prometheus for monitoring purposes.
To run the GitLab Prometheus Exporter locally for development, follow these steps:
-
Clone the repository:
git clone https://github.com/CodeWithEmad/gitlab-prometheus-exporter.git cd gitlab-prometheus-exporter -
Create a virtual environment and activate it:
python -m venv .venv source .venv/bin/activate # On Windows use `.venv\Scripts\activate`
-
Install the required dependencies:
pip install -r requirements.txt
-
Set the necessary environment variables.
GITLAB_URLURL of the GitLab instance (e.g., "https://gitlab.com")GITLAB_TOKENPersonal access token for GitLab API authenticationGITLAB_GROUP_IDID of the GitLab group to monitor (e.g., "123456")REFRESH_INTERVALInterval in seconds for refreshing the metrics (default: "300")EXPORTER_PORTPort on which the exporter will run (default: "8000")EXPORTER_USERUsername for accessing the exporter (default: "user")EXPORTER_PASSPassword for accessing the exporter (default: "pass")LOG_LEVELLogging level for the application (default: "INFO")
-
Run the application:
docker compose up -d
Alternatively, you can run the application directly using Uvicorn:
uvicorn app.main:app --host 0.0.0.0 --port 8080
The GitLab Access Exporter will be available at http://localhost:8080/metrics and can be scraped by Prometheus for monitoring GitLab access metrics.
Note that when configuring Grafana, you should use http://prometheus:9090 as the Prometheus data source URL if you are running Grafana and Prometheus in Docker containers, as they will be on the same network.
Grafana is up and running at http://localhost:3000 with the default credentials (admin/admin). You can configure Grafana to use Prometheus as a data source and create dashboards to visualize the GitLab access metrics.
After setting up the data source in Grafana, you can import or create dashboards to visualize the metrics collected by the GitLab Access Exporter. Just import the provided Grafana dashboard JSON file in config/grafana-dashboard.json or create your own custom dashboards to monitor GitLab access metrics effectively.
For production deployment, you can use Docker to containerize the application. There's no Grafana and Prometheus in production deployment; you need to set up your own Prometheus and Grafana instances and configure them to scrape the metrics from the GitLab Access Exporter.
-
Build the Docker image:
docker compose build -t gitlab-access-exporter:latest . -
Set the necessary environment variables in the
docker-compose.ymlfile or use a.envfile to provide the required configuration. -
Run the Docker container:
docker compose up -d
The GitLab Access Exporter will be available at http://localhost:8080/metrics and can be scraped by Prometheus for monitoring GitLab access metrics.
This project is licensed under the AGPL-3.0 License. See the LICENSE file for details.

