From 82508a544d88ae4bee09dbdf4c7b576701b4b67a Mon Sep 17 00:00:00 2001
From: xmarek14 <xmarek14@fi.muni.cz>
Date: Thu, 4 May 2023 15:20:56 +0200
Subject: [PATCH] does not work

---
 README.md                                    |  8 +--
 car/pom.xml                                  | 14 +++++
 car/src/main/resources/application.yml       |  9 +++-
 component/pom.xml                            |  9 ++++
 component/src/main/resources/application.yml |  9 +++-
 docker-compose.yaml                          | 30 ++++++++++-
 driver/pom.xml                               |  9 ++++
 driver/src/main/resources/application.yml    |  9 +++-
 prometheus.yml                               | 56 ++++++++++++++++++++
 race/pom.xml                                 |  5 ++
 race/src/main/resources/application.yml      |  9 +++-
 11 files changed, 158 insertions(+), 9 deletions(-)
 create mode 100644 prometheus.yml

diff --git a/README.md b/README.md
index 99c8cdd9..1f3eab6d 100644
--- a/README.md
+++ b/README.md
@@ -61,7 +61,7 @@ WARNING: when putting components or drivers, services component and driver need
 ##### Run component using Docker:
 Create the image: 
 
-`> docker build --no-cache -t pa165-formula-one-team-car`
+`> docker build --no-cache -t pa165-formula-one-team-car .`
 
 Run the image:
 
@@ -77,7 +77,7 @@ Runs on port 8084.
 #### Run component using Docker:
 Create the image:
 
-`> docker build --no-cache -t pa165-formula-one-team-component`
+`> docker build --no-cache -t pa165-formula-one-team-component .`
 
 Run the image:
 
@@ -94,7 +94,7 @@ Runs on port 8083.
 #### Run component using Docker:
 Create the image:
 
-`> docker build --no-cache -t pa165-formula-one-team-driver`
+`> docker build --no-cache -t pa165-formula-one-team-driver .`
 
 Run the image:
 
@@ -119,7 +119,7 @@ Runs on port 8081.
 #### Run component using Docker:
 Create the image:
 
-`> docker build --no-cache -t pa165-formula-one-team-race`
+`> docker build --no-cache -t pa165-formula-one-team-race .`
 
 Run the image:
 
diff --git a/car/pom.xml b/car/pom.xml
index 9ab609ce..a595d130 100644
--- a/car/pom.xml
+++ b/car/pom.xml
@@ -59,6 +59,20 @@
             <scope>test</scope>
         </dependency>
 
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.micrometer</groupId>
+            <artifactId>micrometer-registry-prometheus</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+
     </dependencies>
     <properties>
         <maven.compiler.source>17</maven.compiler.source>
diff --git a/car/src/main/resources/application.yml b/car/src/main/resources/application.yml
index b8ec8994..7ef2e50d 100644
--- a/car/src/main/resources/application.yml
+++ b/car/src/main/resources/application.yml
@@ -24,9 +24,16 @@ spring:
 management:
   endpoints:
     web:
+      base-path: /actuator
       exposure:
-        include: "health,metrics"
+        include: [ "health", "metrics", "prometheus" ]
   endpoint:
+    health:
+      show-details: always
+      probes:
+        enabled: true
+    metrics:
+      enabled: true
     prometheus:
       enabled: true
   metrics:
diff --git a/component/pom.xml b/component/pom.xml
index 2d7b07fe..509617f7 100644
--- a/component/pom.xml
+++ b/component/pom.xml
@@ -54,6 +54,15 @@
             <version>4.12</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>io.micrometer</groupId>
+            <artifactId>micrometer-registry-prometheus</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
+            <groupId>io.micrometer</groupId>
+            <artifactId>micrometer-core</artifactId>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/component/src/main/resources/application.yml b/component/src/main/resources/application.yml
index f146b595..11ee3832 100644
--- a/component/src/main/resources/application.yml
+++ b/component/src/main/resources/application.yml
@@ -24,9 +24,16 @@ spring:
 management:
   endpoints:
     web:
+      base-path: /actuator
       exposure:
-        include: "health,metrics"
+        include: [ "health", "metrics", "prometheus" ]
   endpoint:
+    health:
+      show-details: always
+      probes:
+        enabled: true
+    metrics:
+      enabled: true
     prometheus:
       enabled: true
   metrics:
diff --git a/docker-compose.yaml b/docker-compose.yaml
index 08242ee6..0073f9b9 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -1,19 +1,47 @@
 ---
 version: '3'
 services:
+
   race:
     image: pa165-formula-one-team-race
     ports:
       - "8081:8081"
+
   car:
     image: pa165-formula-one-team-car
     ports:
       - "8082:8082"
+
   driver:
     image: pa165-formula-one-team-driver
     ports:
       - "8083:8083"
+
   component:
     image: pa165-formula-one-team-component
     ports:
-      - "8084:8084"
\ No newline at end of file
+      - "8084:8084"
+
+  prometheus:
+    ports:
+      - "9090:9090"
+    volumes:
+      - C:\Users\tomas\Documents\PA165\pa165-formula-one-team\prometheus.yml:/etc/prometheus/prometheus.yml
+    image: prom/prometheus
+    command:
+      - '--config.file=/etc/prometheus/prometheus.yml'
+#
+#  grafana:
+#    image: grafana/grafana-oss
+#    user: "$UID:$GID"
+#    network_mode: host
+#    container_name: grafana-container
+#    depends_on:
+#      - prometheus
+#    ports:
+#      - "3000:3000"
+#    volumes:
+#      - ./grafana/:/var/lib/grafana
+#    environment:
+#      - GF_SECURITY_ADMIN_PASSWORD=admin
+#      - GF_SERVER_DOMAIN=localhost
\ No newline at end of file
diff --git a/driver/pom.xml b/driver/pom.xml
index 881eec2c..b4017f9d 100644
--- a/driver/pom.xml
+++ b/driver/pom.xml
@@ -57,6 +57,15 @@
             <version>4.12</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>io.micrometer</groupId>
+            <artifactId>micrometer-registry-prometheus</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
+            <groupId>io.micrometer</groupId>
+            <artifactId>micrometer-core</artifactId>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/driver/src/main/resources/application.yml b/driver/src/main/resources/application.yml
index 30a7a5ed..0ff647e1 100644
--- a/driver/src/main/resources/application.yml
+++ b/driver/src/main/resources/application.yml
@@ -24,9 +24,16 @@ spring:
 management:
   endpoints:
     web:
+      base-path: /actuator
       exposure:
-        include: "health,metrics"
+        include: [ "health", "metrics", "prometheus" ]
   endpoint:
+    health:
+      show-details: always
+      probes:
+        enabled: true
+    metrics:
+      enabled: true
     prometheus:
       enabled: true
   metrics:
diff --git a/prometheus.yml b/prometheus.yml
new file mode 100644
index 00000000..d7958e54
--- /dev/null
+++ b/prometheus.yml
@@ -0,0 +1,56 @@
+global:
+  scrape_interval: 2s
+
+scrape_configs:
+
+  - job_name: 'race-service-prometheus'
+    metrics_path: '/actuator/prometheus'
+    static_configs:
+      - targets: ['host.docker.internal:8081']
+  - job_name: 'race-service-metrics'
+    metrics_path: '/actuator/metrics'
+    static_configs:
+      - targets: [ 'host.docker.internal:8081' ]
+  - job_name: 'race-service-health'
+    metrics_path: '/actuator/health'
+    static_configs:
+      - targets: [ 'host.docker.internal:8081' ]
+
+  - job_name: 'car-service-prometheus'
+    metrics_path: '/actuator/prometheus'
+    static_configs:
+      - targets: ['host.docker.internal:8082']
+  - job_name: 'car-service-metrics'
+    metrics_path: '/actuator/metrics'
+    static_configs:
+      - targets: [ 'host.docker.internal:8082' ]
+  - job_name: 'car-service-health'
+    metrics_path: '/actuator/health'
+    static_configs:
+      - targets: [ 'host.docker.internal:8082' ]
+
+  - job_name: 'driver-service-prometheus'
+    metrics_path: '/actuator/prometheus'
+    static_configs:
+      - targets: ['host.docker.internal:8083']
+  - job_name: 'driver-service-metrics'
+    metrics_path: '/actuator/metrics'
+    static_configs:
+      - targets: [ 'host.docker.internal:8083' ]
+  - job_name: 'driver-service-health'
+    metrics_path: '/actuator/health'
+    static_configs:
+      - targets: [ 'host.docker.internal:8083' ]
+
+  - job_name: 'component-service-prometheus'
+    metrics_path: '/actuator/prometheus'
+    static_configs:
+      - targets: ['host.docker.internal:8084']
+  - job_name: 'component-service-metrics'
+    metrics_path: '/actuator/metrics'
+    static_configs:
+      - targets: [ 'host.docker.internal:8084' ]
+  - job_name: 'component-service-health'
+    metrics_path: '/actuator/health'
+    static_configs:
+      - targets: [ 'host.docker.internal:8084' ]
\ No newline at end of file
diff --git a/race/pom.xml b/race/pom.xml
index bfe14bec..7846930d 100644
--- a/race/pom.xml
+++ b/race/pom.xml
@@ -53,6 +53,11 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>io.micrometer</groupId>
+            <artifactId>micrometer-registry-prometheus</artifactId>
+            <scope>runtime</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/race/src/main/resources/application.yml b/race/src/main/resources/application.yml
index 9e1d582c..b42a43c0 100644
--- a/race/src/main/resources/application.yml
+++ b/race/src/main/resources/application.yml
@@ -29,9 +29,16 @@ spring:
 management:
   endpoints:
     web:
+      base-path: /actuator
       exposure:
-        include: "health,metrics"
+        include: [ "health", "metrics", "prometheus" ]
   endpoint:
+    health:
+      show-details: always
+      probes:
+        enabled: true
+    metrics:
+      enabled: true
     prometheus:
       enabled: true
   metrics:
-- 
GitLab