Skip to content

johnsonlee/gradle-prometheus-plugin

Repository files navigation

Overview

This project is used for Gradle build performance monitoring, it consist of 2 parts:

  1. Gradle metrics generator - GradlePrometheusPlugin.kt

    Prometheus metrics generator for Gradle project

  2. 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:

Screenshot

Prerequisite

Getting Started

Start Metrics Exporter

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

Integrate Metrics Exporter with Prometheus

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

Integrate with Metrics Generator

The gradle plugin can by easily integrated by Gradle Initialization Scripts with Gradle project, just put init.gradle under one of following directories:

  1. USER_HOME/.gradle/
  2. USER_HOME/.gradle/init.d/
  3. 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

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.