Skip to content

Commit 28909ac

Browse files
author
Mikalai Alimenkou
committed
Added Prometheus + Grafana for metrics collection
1 parent 649c687 commit 28909ac

File tree

4 files changed

+70
-3
lines changed

4 files changed

+70
-3
lines changed

compose.yaml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,33 @@ services:
5959
- "4316:4318" # OTLP HTTP
6060
depends_on:
6161
elastic:
62-
condition: service_healthy
62+
condition: service_healthy
63+
64+
prometheus:
65+
image: prom/prometheus:v3.7.1
66+
container_name: library-prometheus
67+
command:
68+
- '--config.file=/etc/prometheus/prometheus.yml'
69+
- '--storage.tsdb.path=/prometheus'
70+
- '--web.console.libraries=/etc/prometheus/console_libraries'
71+
- '--web.console.templates=/etc/prometheus/consoles'
72+
volumes:
73+
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
74+
ports:
75+
- "9090:9090"
76+
extra_hosts:
77+
- "host.docker.internal:host-gateway"
78+
79+
grafana:
80+
image: grafana/grafana:12.2.1
81+
container_name: library-grafana
82+
environment:
83+
- GF_SECURITY_ADMIN_USER=admin
84+
- GF_SECURITY_ADMIN_PASSWORD=xpinjection
85+
- GF_USERS_ALLOW_SIGN_UP=false
86+
volumes:
87+
- ./grafana/datasources:/etc/grafana/provisioning/datasources:ro
88+
ports:
89+
- "3000:3000"
90+
depends_on:
91+
- prometheus

grafana/datasources/prometheus.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: 1
2+
3+
datasources:
4+
- name: Prometheus
5+
type: prometheus
6+
access: proxy
7+
url: http://prometheus:9090
8+
isDefault: true
9+
editable: true
10+
jsonData:
11+
timeInterval: 5s
12+
queryTimeout: 60s

prometheus/prometheus.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
global:
2+
scrape_interval: 15s
3+
evaluation_interval: 15s
4+
external_labels:
5+
monitor: 'library-monitor'
6+
7+
scrape_configs:
8+
- job_name: 'library-application'
9+
metrics_path: '/admin/prometheus'
10+
scrape_interval: 5s
11+
basic_auth:
12+
username: admin
13+
password: xpinjection
14+
static_configs:
15+
- targets: ['host.docker.internal:8080']
16+
labels:
17+
application: 'library'
18+
environment: 'local-dev'

src/main/resources/application-admin.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ spring:
1111
enabled: true
1212

1313
management:
14+
prometheus:
15+
metrics:
16+
export:
17+
enabled: true
1418
observations:
1519
annotations:
1620
enabled: true
@@ -61,7 +65,11 @@ management:
6165
enabled: true
6266
process:
6367
enabled: true
64-
metrics:
6568
distribution:
6669
percentiles-histogram:
67-
http.server.requests: true
70+
http.server.requests: true
71+
72+
server:
73+
tomcat:
74+
mbeanregistry:
75+
enabled: true

0 commit comments

Comments
 (0)