This project is used for Gradle build performance monitoring, it consist of 2 parts:
-
Gradle metrics generator - GradlePrometheusPlugin.kt
Prometheus metrics generator for Gradle project
-
Gradle metrics exporter - exporter/index.js
Export metrics to Prometheus service, the metrics can be visualized by Grafana
Using this project, we can build a pretty dashboard:
-
Docker
-
Docker Compose
-
Prometheus
You can refer dockerify/prometheus to deploy your own Prometheus service.
-
Grafana
You can refer dockerify/grafana to deploy your own Grafana service
The metrics exporter can be easily started from local:
cd exporter && docker-compose up -d
or started from docker hub
docker run -p 9300:3000 johnsonlee/gradle-prometheus-exporter
Then check the metrics exporter by accessing: http://localhost:9300/metrics
To make the metrics exporter service discoverable by Prometheus service, you have to update prometheus.yml:
scrape_configs:
- job_name: cadvisor
scrape_interval: 5s
static_configs:
- targets:
- cadvisor:8080
- job_name: gradle-prometheus-exporter
scrape_interval: 5s
static_configs:
- targets:
- <the-ip-address-of-exporter>:9300
After updated, restart prometheus service by executing the following command:
docker-compose restart promethues
The gradle plugin can by easily integrated by Gradle Initialization Scripts with Gradle project, just put init.gradle under one of following directories:
- USER_HOME/.gradle/
- USER_HOME/.gradle/init.d/
- GRADLE_HOME/init.d/
Then config system property metrics.endpoint
in gradle.properties
:
systemProp.metrics.endpoint=http://localhost:9300/metrics
Then build your project:
./gradlew build
After build finished, check the metrics from http://localhost:9300/metrics
If everything works well, the metrics generated by Gradle plugin are supposed to be discovered by Prometheus as following:
- gradle_project_evaluation_duration_ms
- gradle_settings_duration_ms
- gradle_task_execution_duration_ms
- gradle_build_duration_ms
Then, we can create dashboard with those metrics.