https://github.com/johnsonlee/gradle-prometheus-plugin
Prometheus metrics generator for Gradle
https://github.com/johnsonlee/gradle-prometheus-plugin
Last synced: about 1 year ago
JSON representation
Prometheus metrics generator for Gradle
- Host: GitHub
- URL: https://github.com/johnsonlee/gradle-prometheus-plugin
- Owner: johnsonlee
- License: mit
- Created: 2021-01-24T04:16:20.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-12-12T15:36:20.000Z (over 4 years ago)
- Last Synced: 2025-03-28T23:51:14.579Z (about 1 year ago)
- Language: Kotlin
- Size: 342 KB
- Stars: 11
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Overview
This project is used for Gradle build performance monitoring, it consist of 2 parts:
1. Gradle metrics generator - [GradlePrometheusPlugin.kt](./src/main/kotlin/io/johnsonlee/gradle/metrics/GradlePrometheusPlugin.kt)
[Prometheus](https://prometheus.io) metrics generator for Gradle project
1. Gradle metrics exporter - [exporter/index.js](./exporter/index.js)
Export metrics to [Prometheus](https://prometheus.io) service, the metrics can be visualized by [Grafana](https://grafana.com)
Using this project, we can build a pretty dashboard:

## Prerequisite
- Docker
- Docker Compose
- Prometheus
You can refer [dockerify/prometheus](https://github.com/johnsonlee/dockerify/tree/main/prometheus) to deploy your own Prometheus service.
- Grafana
You can refer [dockerify/grafana](https://github.com/johnsonlee/dockerify/tree/main/grafana) to deploy your own Grafana service
## Getting Started
### Start Metrics Exporter
The metrics exporter can be easily started from local:
```bash
cd exporter && docker-compose up -d
```
or started from docker hub
```bash
docker run -p 9300:3000 johnsonlee/gradle-prometheus-exporter
```
Then check the metrics exporter by accessing: http://localhost:9300/metrics
### Integrate Metrics Exporter with Prometheus
To make the metrics exporter service discoverable by Prometheus service, you have to update [prometheus.yml](https://github.com/johnsonlee/dockerify/blob/main/prometheus/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:
- :9300
```
After updated, restart prometheus service by executing the following command:
```bash
docker-compose restart promethues
```
### Integrate with Metrics Generator
The gradle plugin can by easily integrated by [Gradle Initialization Scripts](https://docs.gradle.org/current/userguide/init_scripts.html) with Gradle project, just put [init.gradle](https://github.com/johnsonlee/gradle-prometheus-plugin/blob/main/src/main/resources/init.gradle) under one of following directories:
1. *USER_HOME/.gradle/*
1. *USER_HOME/.gradle/init.d/*
1. *GRADLE_HOME/init.d/*
Then config system property `metrics.endpoint` in `gradle.properties`:
```properties
systemProp.metrics.endpoint=http://localhost:9300/metrics
```
Then build your project:
```bash
./gradlew build
```
After build finished, check the metrics from http://localhost:9300/metrics
### Create Dashboard for Gradle 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.