Skip to content

Commit 67148ef

Browse files
committed
Task 23 : Implement docker-compose.yml with Prometheus, Grafana, AlertManager and Sonarqube
1 parent 925aad3 commit 67148ef

File tree

7 files changed

+216
-0
lines changed

7 files changed

+216
-0
lines changed

data/alertmanager/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM prom/alertmanager:latest
2+
3+
# Copy the configuration and entrypoint script into the image
4+
COPY config/alertmanager.yml /etc/alertmanager/alertmanager.yml
5+
COPY entrypoint.sh /entrypoint.sh
6+
7+
# Copy the entrypoint script and set it as executable with octal permissions
8+
COPY --chmod=0755 entrypoint.sh /entrypoint.sh
9+
10+
# Use the custom entrypoint
11+
ENTRYPOINT ["/entrypoint.sh"]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
global:
2+
resolve_timeout: ${ALERT_RESOLVE_TIMEOUT}
3+
smtp_smarthost: ${SMTP_SMARTHOST}
4+
smtp_from: ${SMTP_FROM}
5+
smtp_auth_username: ${SMTP_AUTH_USERNAME}
6+
smtp_auth_password: ${SMTP_AUTH_PASSWORD}
7+
smtp_require_tls: ${SMTP_REQUIRE_TLS}
8+
9+
route:
10+
group_by: ['alertname']
11+
group_wait: 30s
12+
group_interval: 5m
13+
repeat_interval: 5m
14+
receiver: 'default'
15+
16+
receivers:
17+
- name: 'default'
18+
webhook_configs:
19+
- url: 'http://grafana:3000'
20+
email_configs:
21+
- to: ${ALERT_EMAIL_TO}
22+
send_resolved: true

data/alertmanager/entrypoint.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Replace placeholders with environment variable values in the config file
5+
sed -i "s|\${ALERT_RESOLVE_TIMEOUT}|${ALERT_RESOLVE_TIMEOUT}|g" /etc/alertmanager/alertmanager.yml
6+
sed -i "s|\${SMTP_SMARTHOST}|${SMTP_SMARTHOST}|g" /etc/alertmanager/alertmanager.yml
7+
sed -i "s|\${SMTP_FROM}|${SMTP_FROM}|g" /etc/alertmanager/alertmanager.yml
8+
sed -i "s|\${SMTP_AUTH_USERNAME}|${SMTP_AUTH_USERNAME}|g" /etc/alertmanager/alertmanager.yml
9+
sed -i "s|\${SMTP_AUTH_PASSWORD}|${SMTP_AUTH_PASSWORD}|g" /etc/alertmanager/alertmanager.yml
10+
sed -i "s|\${SMTP_REQUIRE_TLS}|${SMTP_REQUIRE_TLS}|g" /etc/alertmanager/alertmanager.yml
11+
sed -i "s|\${ALERT_EMAIL_TO}|${ALERT_EMAIL_TO}|g" /etc/alertmanager/alertmanager.yml
12+
13+
# Start Alertmanager
14+
exec alertmanager --config.file=/etc/alertmanager/alertmanager.yml
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
groups:
2+
- name: example-alerts
3+
rules:
4+
- alert: HighNonHeapUsage
5+
expr: (sum(jvm_memory_used_bytes{application="Live Betting App", area="nonheap"}) * 100)
6+
/ sum(jvm_memory_max_bytes{application="Live Betting App", area="nonheap"}) > 2
7+
for: 2m
8+
labels:
9+
severity: warning
10+
service: livebetting
11+
annotations:
12+
summary: "Live Betting high non-heap usage"
13+
description: "Non-heap usage has exceeded 2% for more than 2 minutes."
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
global:
2+
scrape_interval: 120s # By default, scrape targets every 15 seconds.
3+
evaluation_interval: 120s # By default, scrape targets every 15 seconds.
4+
5+
alerting:
6+
alertmanagers:
7+
- static_configs:
8+
- targets:
9+
- 'alertmanager:9093'
10+
11+
rule_files:
12+
- 'alerts_rules.yml'
13+
14+
15+
# A scrape configuration containing exactly one endpoint to scrape:
16+
# Here it's Prometheus itself.
17+
scrape_configs:
18+
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
19+
- job_name: 'prometheus'
20+
# Override the global default and scrape targets from this job every 5 seconds.
21+
scrape_interval: 5s
22+
# metrics_path defaults to '/metrics'
23+
# scheme defaults to 'http'.
24+
static_configs:
25+
- targets: ['localhost:9090']
26+
27+
- job_name: 'Spring Boot Application input'
28+
metrics_path: '/actuator/prometheus'
29+
scrape_interval: 2s
30+
static_configs:
31+
- targets: [ 'livebetting:5160' ]
32+
labels:
33+
application: 'Live Betting App'

docker-compose.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
services:
2+
3+
database:
4+
container_name: database
5+
image: mysql:8.0.33
6+
restart: always
7+
env_file:
8+
- .env # Use the .env file for environment variables
9+
environment:
10+
MYSQL_DATABASE: livebettingdatabase
11+
MYSQL_PASSWORD: ${DATABASE_PASSWORD}
12+
MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD}
13+
MYSQL_ROOT_HOST: '%'
14+
MYSQL_PORT: 3307
15+
volumes:
16+
- ./db:/var/lib/mysql
17+
ports:
18+
- "3307:3306"
19+
networks:
20+
- livebettingNetwork
21+
22+
livebetting:
23+
image: 'livebetting:latest'
24+
build:
25+
context: .
26+
dockerfile: Dockerfile
27+
container_name: livebetting
28+
restart: on-failure
29+
env_file:
30+
- .env # Use the .env file for environment variables
31+
ports:
32+
- "5160:5160"
33+
environment:
34+
- server.port=5160
35+
- spring.datasource.username=${DATABASE_USERNAME}
36+
- spring.datasource.password=${DATABASE_PASSWORD}
37+
- LIVE_BETTING_SERVICE_DB_IP=database
38+
- LIVE_BETTING_DB_PORT=3307
39+
- spring.datasource.url=jdbc:mysql://host.docker.internal:3307/livebettingdatabase
40+
depends_on:
41+
- database
42+
- sonarqube
43+
networks:
44+
- livebettingNetwork
45+
46+
prometheus:
47+
image: prom/prometheus:latest
48+
container_name: prometheus
49+
restart: unless-stopped
50+
ports:
51+
- "9090:9090"
52+
volumes:
53+
- ./data/prometheus/config:/etc/prometheus/
54+
command:
55+
- '--config.file=/etc/prometheus/prometheus.yml'
56+
networks:
57+
- livebettingNetwork
58+
59+
grafana:
60+
image: "grafana/grafana-oss:latest"
61+
pull_policy: always
62+
container_name: grafana
63+
restart: unless-stopped
64+
ports:
65+
- "3000:3000"
66+
volumes:
67+
- ./data/grafana:/var/lib/grafana
68+
environment:
69+
- GF_SECURITY_ADMIN_PASSWORD=admin
70+
- GF_SERVER_DOMAIN=localhost
71+
- GF_SMTP_ENABLED=${GF_SMTP_ENABLED}
72+
- GF_SMTP_HOST=${GF_SMTP_HOST}
73+
- GF_SMTP_USER=${GF_SMTP_USER}
74+
- GF_SMTP_PASSWORD=${GF_SMTP_PASSWORD}
75+
- GF_SMTP_SKIP_VERIFY=${GF_SMTP_SKIP_VERIFY}
76+
- GF_SMTP_FROM_ADDRESS=${GF_SMTP_FROM_ADDRESS}
77+
networks:
78+
- livebettingNetwork
79+
80+
sonarqube:
81+
image: sonarqube:latest
82+
container_name: sonarqube
83+
restart: always
84+
ports:
85+
- "9000:9000"
86+
volumes:
87+
- sonarqube_data:/opt/sonarqube/data
88+
- sonarqube_extensions:/opt/sonarqube/extensions
89+
- sonarqube_logs:/opt/sonarqube/logs
90+
depends_on:
91+
- database
92+
networks:
93+
- livebettingNetwork
94+
95+
alertmanager:
96+
build:
97+
context: ./data/alertmanager
98+
dockerfile: Dockerfile
99+
container_name: alertmanager
100+
restart: unless-stopped
101+
ports:
102+
- "9093:9093"
103+
env_file:
104+
- .env
105+
networks:
106+
- livebettingNetwork
107+
108+
volumes:
109+
sonarqube_data:
110+
sonarqube_extensions:
111+
sonarqube_logs:
112+
113+
networks:
114+
livebettingNetwork:

pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@
3737
<maven-surefire-plugin-version>3.5.2</maven-surefire-plugin-version>
3838
<maven-failsafe-plugin-version>3.5.2</maven-failsafe-plugin-version>
3939

40+
<sonar.host.url>http://localhost:9000</sonar.host.url> <!-- Changed to localhost if running locally -->
41+
<sonar.login>sqp_c1444193b0e63bb25f346222163872992d646208</sonar.login> <!-- Authentication Token -->
42+
<sonar.projectKey>livebetting</sonar.projectKey>
43+
<sonar.projectName>livebetting</sonar.projectName>
44+
<sonar.projectVersion>1.0</sonar.projectVersion>
45+
<sonar.sources>src/main</sonar.sources>
46+
<sonar.tests>src/test</sonar.tests>
47+
<sonar.sourceEncoding>UTF-8</sonar.sourceEncoding>
48+
<sonar.java.binaries>target/classes</sonar.java.binaries>
4049

4150
</properties>
4251
<dependencies>

0 commit comments

Comments
 (0)