An open API service indexing awesome lists of open source software.

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

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:

![Screenshot](./art/screenshot.png)

## 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.