fix docker configuration

This commit is contained in:
lamya1baidouri 2025-02-03 09:27:33 +01:00
parent fb7353d702
commit b851a9b525
4 changed files with 326 additions and 20 deletions

View file

@ -1,8 +1,9 @@
version: '3.8' version: '3.8'
services: services:
# Database
mysql: mysql:
image: mysql:9.1 image: mysql:8.0
ports: ports:
- "3306:3306" - "3306:3306"
environment: environment:
@ -13,44 +14,53 @@ services:
- MYSQL_DATABASE=petclinic - MYSQL_DATABASE=petclinic
volumes: volumes:
- "./conf.d:/etc/mysql/conf.d:ro" - "./conf.d:/etc/mysql/conf.d:ro"
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5
networks:
- monitoring-network
postgres:
image: postgres:17.0
ports:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=petclinic
- POSTGRES_USER=petclinic
- POSTGRES_DB=petclinic
# Ajout de Prometheus pour la collecte des métriques
prometheus: prometheus:
image: prom/prometheus:latest image: prom/prometheus:latest
ports: ports:
- "9090:9090" - "9090:9090"
volumes: volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml - ./monitoring/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- ./monitoring/prometheus/pipeline-rules.yml:/etc/prometheus/pipeline-rules.yml:ro
- prometheus_data:/prometheus - prometheus_data:/prometheus
command: command:
- '--config.file=/etc/prometheus/prometheus.yml' - '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus' - '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/usr/share/prometheus/console_libraries' - '--web.enable-lifecycle'
- '--web.console.templates=/usr/share/prometheus/consoles' - '--log.level=debug'
user: root # Added this line
healthcheck:
test: [ "CMD", "wget", "-q", "--spider", "http://localhost:9090/-/healthy" ]
interval: 10s
timeout: 5s
retries: 3
networks:
- monitoring-network
# Ajout de Grafana pour la visualisation
grafana: grafana:
image: grafana/grafana:latest image: grafana/grafana:latest
ports: ports:
- "3000:3000" - "3000:3000"
volumes: volumes:
- ./monitoring/grafana/dashboards:/etc/grafana/provisioning/dashboards
- grafana_data:/var/lib/grafana - grafana_data:/var/lib/grafana
environment: environment:
- GF_SECURITY_ADMIN_PASSWORD=admin - GF_SECURITY_ADMIN_PASSWORD=admin
- GF_USERS_ALLOW_SIGN_UP=false - GF_USERS_ALLOW_SIGN_UP=false
- GF_INSTALL_PLUGINS=grafana-piechart-panel
depends_on: depends_on:
- prometheus prometheus:
condition: service_healthy
networks:
- monitoring-network
# PowerAPI pour la mesure de consommation énergétique
powerapi: powerapi:
image: powerapi/powerapi:latest image: powerapi/powerapi:latest
privileged: true privileged: true
@ -61,11 +71,19 @@ services:
environment: environment:
- POWERAPI_CPU_EVENTS=cpu-cycles,instructions - POWERAPI_CPU_EVENTS=cpu-cycles,instructions
- POWERAPI_PUSH_FREQUENCY=1000 - POWERAPI_PUSH_FREQUENCY=1000
- POWERAPI_PUSH_URL=http://prometheus:9091/metrics/job/powerapi - POWERAPI_PUSH_URL=http://pushgateway:9091/metrics/job/powerapi
depends_on: depends_on:
- prometheus - pushgateway
networks:
- monitoring-network
pushgateway:
image: prom/pushgateway
ports:
- "9091:9091"
networks:
- monitoring-network
# Node exporter pour les métriques système
node-exporter: node-exporter:
image: prom/node-exporter:latest image: prom/node-exporter:latest
volumes: volumes:
@ -78,7 +96,15 @@ services:
- '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)' - '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'
ports: ports:
- "9100:9100" - "9100:9100"
depends_on:
- prometheus
networks:
- monitoring-network
volumes: volumes:
prometheus_data: prometheus_data:
grafana_data: grafana_data:
networks:
monitoring-network:
driver: bridge

View file

@ -0,0 +1,213 @@
{
"annotations": {
"list": []
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 20,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "smooth",
"lineWidth": 2,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": true,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unit": "ms"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
},
"id": 1,
"options": {
"legend": {
"calcs": ["mean", "max", "min"],
"displayMode": "table",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"editorMode": "code",
"expr": "pipeline_build_duration_ms",
"legendFormat": "Build Duration",
"range": true,
"refId": "A"
}
],
"title": "Pipeline Build Duration",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 20,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "smooth",
"lineWidth": 2,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": true,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unit": "watts"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 0
},
"id": 2,
"options": {
"legend": {
"calcs": ["mean", "max"],
"displayMode": "table",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"editorMode": "code",
"expr": "power_consumption_watts",
"legendFormat": "Power Consumption",
"range": true,
"refId": "A"
}
],
"title": "Power Consumption",
"type": "timeseries"
}
],
"refresh": "5s",
"schemaVersion": 38,
"style": "dark",
"tags": ["pipeline", "performance"],
"templating": {
"list": []
},
"time": {
"from": "now-1h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "Pipeline Performance",
"weekStart": ""
}

View file

@ -0,0 +1,29 @@
groups:
- name: pipeline_performance
rules:
# Durée moyenne du build
- record: pipeline:build_duration:avg_5m
expr: avg_over_time(pipeline_build_duration_ms[5m])
# Consommation énergétique totale
- record: pipeline:power_consumption:total
expr: sum(power_consumption_watts{job="powerapi"})
# Alertes
- alert: HighBuildTime
expr: pipeline_build_duration_ms > 300000
for: 1m
labels:
severity: warning
annotations:
summary: "Build duration too high"
description: "Build is taking more than 5 minutes"
- alert: HighPowerConsumption
expr: power_consumption_watts > 100
for: 2m
labels:
severity: warning
annotations:
summary: "High power consumption detected"
description: "Power consumption is above 100W for more than 2 minutes"

View file

@ -0,0 +1,38 @@
global:
scrape_interval: 15s
evaluation_interval: 15s
rule_files:
- "pipeline-rules.yml"
scrape_configs:
# Pipeline metrics
- job_name: 'petclinic-pipeline'
static_configs:
- targets: ['pushgateway:9091'] # Changé de localhost:9091 à pushgateway:9091
labels:
application: 'petclinic'
type: 'pipeline'
# PowerAPI metrics
- job_name: 'powerapi'
static_configs:
- targets: ['powerapi:9091']
metrics_path: '/metrics'
# Node Exporter metrics
- job_name: 'node'
static_configs:
- targets: ['node-exporter:9100']
# Application metrics
- job_name: 'spring-petclinic'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['host.docker.internal:8080']
# Database metrics
- job_name: 'mysql'
metrics_path: '/metrics' # Ajouté le chemin des métriques
static_configs:
- targets: ['mysql:3306']