diff --git a/Dockerfile b/Dockerfile index fb375c58b..9b27efd64 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,4 @@ # Use an official OpenJDK runtime as a parent image -# FROM openjdk:17-jdk-alpine - FROM openjdk # Set the working directory inside the container diff --git a/grafana/provisioning/datasources/datasource.yaml b/grafana/provisioning/datasources/datasource.yaml new file mode 100644 index 000000000..f88db84c4 --- /dev/null +++ b/grafana/provisioning/datasources/datasource.yaml @@ -0,0 +1,9 @@ +apiVersion: 1 + +datasources: + - name: Prometheus + type: prometheus + access: proxy + url: http://prometheus:9090 + isDefault: true + editable: true \ No newline at end of file diff --git a/pom.xml b/pom.xml index a9bbd2959..975db3da4 100644 --- a/pom.xml +++ b/pom.xml @@ -139,6 +139,11 @@ jakarta.xml.bind-api + + + io.micrometer + micrometer-registry-prometheus + diff --git a/prometheus.yml b/prometheus.yml new file mode 100644 index 000000000..92143a72b --- /dev/null +++ b/prometheus.yml @@ -0,0 +1,8 @@ +global: + scrape_interval: 15s + +scrape_configs: + - job_name: 'spring-boot-app' + metrics_path: '/actuator/prometheus' + static_configs: + - targets: ['petclinic:8080'] \ No newline at end of file diff --git a/spring-petclinic.yml b/spring-petclinic.yml new file mode 100644 index 000000000..d79190c4b --- /dev/null +++ b/spring-petclinic.yml @@ -0,0 +1,41 @@ +services: + petclinic: + build: + context: . + dockerfile: Dockerfile + ports: + - "8080:8080" + networks: + - custom-network + + prometheus: + image: prom/prometheus:latest + ports: + - "9090:9090" + volumes: + - prometheus_data:/prometheus + - ./prometheus.yml:/etc/prometheus/prometheus.yml + networks: + - custom-network + depends_on: + - petclinic + + grafana: + image: grafana/grafana:latest + ports: + - "3000:3000" + volumes: + - grafana_data:/var/lib/grafana + networks: + - custom-network + environment: + - GF_SECURITY_ADMIN_PASSWORD=admin + depends_on: + - prometheus + +volumes: + prometheus_data: + grafana_data: + +networks: + custom-network: \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 5d3eeed32..11113c06a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -23,3 +23,9 @@ logging.level.org.springframework=INFO # Maximum time static resources should be cached spring.web.resources.cache.cachecontrol.max-age=12h + +# Configure the Prometheus endpoint +management.endpoint.prometheus.enabled=true + +# Enable Prometheus metrics export +management.metrics.export.prometheus.enabled=true \ No newline at end of file