├── prom-config ├── .gitignore ├── docker-compose.yml └── prometheus.yml ├── src └── main │ ├── resources │ └── application.yml │ └── java │ └── me │ └── aboullaite │ └── springbootprometheus │ └── SpringBootPrometheusApplication.java ├── .gitignore ├── README.md └── pom.xml /prom-config/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | management: 2 | security: 3 | enabled: false -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ 25 | 26 | .mvn/ 27 | mvn* -------------------------------------------------------------------------------- /prom-config/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | grafana: 4 | ports: 5 | - "3000:3000" 6 | volumes: 7 | - /var/lib/grafana 8 | links: 9 | - prometheus 10 | image: grafana/grafana 11 | prometheus: 12 | ports: 13 | - "9090:9090" 14 | volumes: 15 | - ./prometheus.yml:/etc/prometheus/prometheus.yml 16 | command: 17 | - '--config.file=/etc/prometheus/prometheus.yml' 18 | image: prom/prometheus -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-prometheus 2 | a very minimalist example, that show how to configure Grapahana to scrap Spring Boot app metrics and shows them in grafana dashboards. 3 | for more details, check out: https://aboullaite.me/spring-boot-monitoring-prometheus-grafana/ 4 | 5 | ### How to run 6 | to run the examole use `docker compose up -d --build`, this will start 2 containers: Prometheus and Grafana. Next on, run Spring boot app! 7 | 8 | ![](https://aboullaite.me/content/images/2018/01/Screen-Shot-2018-01-11-at-7.13.14-PM.png) 9 | -------------------------------------------------------------------------------- /src/main/java/me/aboullaite/springbootprometheus/SpringBootPrometheusApplication.java: -------------------------------------------------------------------------------- 1 | package me.aboullaite.springbootprometheus; 2 | 3 | import io.prometheus.client.spring.boot.EnablePrometheusEndpoint; 4 | import io.prometheus.client.spring.boot.EnableSpringBootMetricsCollector; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @SpringBootApplication 9 | @EnablePrometheusEndpoint 10 | @EnableSpringBootMetricsCollector 11 | public class SpringBootPrometheusApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SpringBootPrometheusApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /prom-config/prometheus.yml: -------------------------------------------------------------------------------- 1 | # my global config 2 | global: 3 | scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. 4 | evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. 5 | # scrape_timeout is set to the global default (10s). 6 | 7 | # Alertmanager configuration 8 | alerting: 9 | alertmanagers: 10 | - static_configs: 11 | - targets: 12 | # - alertmanager:9093 13 | 14 | # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. 15 | rule_files: 16 | # - "first_rules.yml" 17 | # - "second_rules.yml" 18 | 19 | # A scrape configuration containing exactly one endpoint to scrape: 20 | # Here it's Prometheus itself. 21 | scrape_configs: 22 | # The job name is added as a label `job=` to any timeseries scraped from this config. 23 | - job_name: 'prometheus' 24 | 25 | # metrics_path defaults to '/metrics' 26 | # scheme defaults to 'http'. 27 | 28 | static_configs: 29 | - targets: ['localhost:9090'] 30 | 31 | - job_name: 'spring-boot' 32 | 33 | metrics_path: '/prometheus' 34 | scrape_interval: 5s 35 | static_configs: 36 | - targets: ['docker.for.mac.localhost:8080'] -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | me.aboullaite 7 | spring-boot-prometheus 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-prometheus 12 | Spring Boot and prometheus demo 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | io.prometheus 35 | simpleclient_spring_boot 36 | 0.1.0 37 | 38 | 39 | 40 | io.prometheus 41 | simpleclient_hotspot 42 | 0.1.0 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-maven-plugin 53 | 54 | 55 | 56 | 57 | 58 | 59 | --------------------------------------------------------------------------------