From c281b71a5c225cc6bd07e141fc288ea96db41dc3 Mon Sep 17 00:00:00 2001 From: Magnus Albeck Klitmose Date: Tue, 14 Mar 2023 16:12:48 +0100 Subject: [PATCH] Scripts updated for prometheus and grafana, export metrics --- MiniTwit/Dockerfile | 4 +- MiniTwit/application.yml | 19 -------- MiniTwit/pom.xml | 2 +- MiniTwit/src/main/resources/application.yml | 24 ++++++++++ Scripts/docker-compose.yml | 38 +++++++++------- Scripts/prometheus.yml | 50 ++++++++++++--------- 6 files changed, 79 insertions(+), 58 deletions(-) delete mode 100644 MiniTwit/application.yml create mode 100644 MiniTwit/src/main/resources/application.yml diff --git a/MiniTwit/Dockerfile b/MiniTwit/Dockerfile index 1088ff7..92a467e 100644 --- a/MiniTwit/Dockerfile +++ b/MiniTwit/Dockerfile @@ -8,10 +8,10 @@ FROM openjdk:17-oracle -COPY --from=maven-builder app/target/MiniTwit-0.0.4.war /app-service/MiniTwit-0.0.4.war +COPY --from=maven-builder app/target/MiniTwit-0.0.5.war /app-service/MiniTwit-0.0.5.war COPY minitwit.db /app-service/minitwit.db WORKDIR /app-service EXPOSE 8080 -ENTRYPOINT ["java","-jar","MiniTwit-0.0.3.war"] +ENTRYPOINT ["java","-jar","MiniTwit-0.0.5.war"] diff --git a/MiniTwit/application.yml b/MiniTwit/application.yml deleted file mode 100644 index ad181eb..0000000 --- a/MiniTwit/application.yml +++ /dev/null @@ -1,19 +0,0 @@ -spring: - application: - name: minitwit - -management: - endpoints: - web: - base-path: /actuator - exposure: - include: [ "health","prometheus", "metrics" ] - endpoint: - health: - show-details: always - metrics: - enabled: true - prometheus: - enabled: true -server: - port: 8080 \ No newline at end of file diff --git a/MiniTwit/pom.xml b/MiniTwit/pom.xml index 7cb396a..61a80fb 100644 --- a/MiniTwit/pom.xml +++ b/MiniTwit/pom.xml @@ -10,7 +10,7 @@ dk.itu MiniTwit - 0.0.4 + 0.0.5 war MiniTwit MiniTwit diff --git a/MiniTwit/src/main/resources/application.yml b/MiniTwit/src/main/resources/application.yml new file mode 100644 index 0000000..fbe40cd --- /dev/null +++ b/MiniTwit/src/main/resources/application.yml @@ -0,0 +1,24 @@ +#management: +# endpoints: +# web: +# base-path: /actuator +# exposure: +# include: '*' +# endpoint: +# health: +# show-details: always +# metrics: +# enabled: true +# prometheus: +# enabled: true +spring: + application: + name: spring-prometheus-demo +management: + endpoints: + web: + exposure: + include: health, metrics, prometheus + metrics: + tags: + application: ${spring.application.name} \ No newline at end of file diff --git a/Scripts/docker-compose.yml b/Scripts/docker-compose.yml index c194318..21b4be5 100644 --- a/Scripts/docker-compose.yml +++ b/Scripts/docker-compose.yml @@ -1,16 +1,24 @@ -prometheus: - image: prom/prometheus - container_name: prometheus - volumes: - - ./prometheus.yml:/etc/prometheus/prometheus.yml - ports: - - "9090:9090" - networks: - - main +version: '3.5' -grafana: - image: grafana/grafana:4.5.2 - ports: - - "3000:3000" - networks: - - main \ No newline at end of file +services: + prometheus: + image: prom/prometheus + container_name: prometheus + volumes: + - ./prometheus.yml:/etc/prometheus/prometheus.yml + ports: + - "9090:9090" + networks: + - main + + grafana: + image: grafana/grafana:4.5.2 + container_name: grafana + ports: + - "3000:3000" + networks: + - main + +networks: + main: + name: itu-minitwit-network diff --git a/Scripts/prometheus.yml b/Scripts/prometheus.yml index 03e12cf..f92a25c 100644 --- a/Scripts/prometheus.yml +++ b/Scripts/prometheus.yml @@ -1,29 +1,37 @@ -global: - scrape_interval: 15s # By default, scrape targets every 15 seconds. - evaluation_interval: 15s # Evaluate rules every 15 seconds. +scrape_configs: + - job_name: 'minitwit' + metrics_path: '/actuator/prometheus' + scrape_interval: 30s + static_configs: + - targets: ['host.docker.internal:8081'] + labels: + application: 'minitwit' +# global: +# scrape_interval: 15s # By default, scrape targets every 15 seconds. +# evaluation_interval: 15s # Evaluate rules every 15 seconds. - # Attach these extra labels to all timeseries collected by this Prometheus instance. - external_labels: - monitor: 'codelab-monitor' +# # Attach these extra labels to all timeseries collected by this Prometheus instance. +# external_labels: +# monitor: 'codelab-monitor' -rule_files: - - 'prometheus.rules.yml' +# rule_files: +# - 'prometheus.rules.yml' -scrape_configs: - - job_name: 'prometheus' +# scrape_configs: +# - job_name: 'prometheus' - # Override the global default and scrape targets from this job every 5 seconds. - scrape_interval: 60s +# # Override the global default and scrape targets from this job every 5 seconds. +# scrape_interval: 5s - static_configs: - - targets: ['prometheus:9090'] +# static_configs: +# - targets: ['prometheus:9090'] - - job_name: 'itu-minittwit-app' +# - job_name: 'itu-minittwit-app' - # Override the global default and scrape targets from this job every 5 seconds. - scrape_interval: 60s +# # Override the global default and scrape targets from this job every 5 seconds. +# scrape_interval: 5s - static_configs: - - targets: ['minitwit:8081'] - labels: - group: 'production' +# static_configs: +# - targets: ['host.docker.internal:8081'] +# labels: +# group: 'production' \ No newline at end of file