diff --git a/docker-compose.yml b/docker-compose.yml index 4c777b9..61a0955 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,23 @@ version: '1' services: + prometheus: + image: prom/prometheus + ports: + - "9090:9090" + volumes: + - ./prometheus:/etc/prometheus + command: + - --config.file=/etc/prometheus/prometheus.yml + depends_on: + - app + + grafana: + image: grafana/grafana + ports: + - "3000:3000" + depends_on: + - prometheus + db: image: 'postgres:13.1-alpine' container_name: db @@ -46,3 +64,4 @@ services: - SPRING_RABBITMQ_PORT=5672 - SPRING_RABBITMQ_USERNAME=alex - SPRING_RABBITMQ_PASSWORD=alex + - SPRING_PROFILES_ACTIVE=prometheus diff --git a/pom.xml b/pom.xml index 37ff038..ee4d41e 100644 --- a/pom.xml +++ b/pom.xml @@ -103,6 +103,33 @@ spring-rabbit-test test + + io.prometheus + simpleclient + 0.12.0 + + + io.prometheus + simpleclient_common + 0.12.0 + + + io.prometheus + simpleclient_spring_boot + 0.12.0 + + + io.micrometer + micrometer-registry-prometheus + + + io.micrometer + micrometer-core + + + org.springframework.boot + spring-boot-starter-actuator + diff --git a/prometheus/prometheus.yml b/prometheus/prometheus.yml new file mode 100644 index 0000000..c2ba9f5 --- /dev/null +++ b/prometheus/prometheus.yml @@ -0,0 +1,8 @@ +global: + scrape_interval: 3s + +scrape_configs: + - job_name: 'app' + metrics_path: '/actuator/prometheus' + static_configs: + - targets: ['app:8080'] \ No newline at end of file diff --git a/src/main/java/com/archivision/community/metric/MetricsConfiguration.java b/src/main/java/com/archivision/community/metric/MetricsConfiguration.java new file mode 100644 index 0000000..e9f8050 --- /dev/null +++ b/src/main/java/com/archivision/community/metric/MetricsConfiguration.java @@ -0,0 +1,14 @@ +package com.archivision.community.metric; + +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.simple.SimpleMeterRegistry; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class MetricsConfiguration { + @Bean + public MeterRegistry meterRegistry() { + return new SimpleMeterRegistry(); + } +} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 6c47bde..0b4cf51 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -7,6 +7,19 @@ community: likes-queue: like-events payment-queue: payment-events +management: + endpoints: + web: + exposure: + include: info,health,metrics,prometheus + endpoint: + health: + show-details: always + metrics: + enabled: true + prometheus: + enabled: true + spring: app: rabbit: