From b851a9b5253d84248a6df8d5ee0870e77f9e6eb5 Mon Sep 17 00:00:00 2001 From: lamya1baidouri Date: Mon, 3 Feb 2025 09:27:33 +0100 Subject: [PATCH] fix docker configuration --- docker-compose.yml | 66 ++++-- monitoring/grafana/dashboards/pipeline.json | 213 ++++++++++++++++++++ monitoring/prometheus/pipeline-rules.yml | 29 +++ monitoring/prometheus/prometheus.yml | 38 ++++ 4 files changed, 326 insertions(+), 20 deletions(-) create mode 100644 monitoring/grafana/dashboards/pipeline.json create mode 100644 monitoring/prometheus/pipeline-rules.yml create mode 100644 monitoring/prometheus/prometheus.yml diff --git a/docker-compose.yml b/docker-compose.yml index 348c8105b..43068d5b0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,9 @@ version: '3.8' services: + # Database mysql: - image: mysql:9.1 + image: mysql:8.0 ports: - "3306:3306" environment: @@ -13,44 +14,53 @@ services: - MYSQL_DATABASE=petclinic volumes: - "./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: image: prom/prometheus:latest ports: - "9090:9090" 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 command: - '--config.file=/etc/prometheus/prometheus.yml' - '--storage.tsdb.path=/prometheus' - - '--web.console.libraries=/usr/share/prometheus/console_libraries' - - '--web.console.templates=/usr/share/prometheus/consoles' + - '--web.enable-lifecycle' + - '--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: image: grafana/grafana:latest ports: - "3000:3000" volumes: + - ./monitoring/grafana/dashboards:/etc/grafana/provisioning/dashboards - grafana_data:/var/lib/grafana environment: - GF_SECURITY_ADMIN_PASSWORD=admin - GF_USERS_ALLOW_SIGN_UP=false + - GF_INSTALL_PLUGINS=grafana-piechart-panel depends_on: - - prometheus + prometheus: + condition: service_healthy + networks: + - monitoring-network - # PowerAPI pour la mesure de consommation énergétique powerapi: image: powerapi/powerapi:latest privileged: true @@ -61,11 +71,19 @@ services: environment: - POWERAPI_CPU_EVENTS=cpu-cycles,instructions - POWERAPI_PUSH_FREQUENCY=1000 - - POWERAPI_PUSH_URL=http://prometheus:9091/metrics/job/powerapi + - POWERAPI_PUSH_URL=http://pushgateway:9091/metrics/job/powerapi 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: image: prom/node-exporter:latest volumes: @@ -78,7 +96,15 @@ services: - '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)' ports: - "9100:9100" + depends_on: + - prometheus + networks: + - monitoring-network volumes: prometheus_data: grafana_data: + +networks: + monitoring-network: + driver: bridge diff --git a/monitoring/grafana/dashboards/pipeline.json b/monitoring/grafana/dashboards/pipeline.json new file mode 100644 index 000000000..e507c2be8 --- /dev/null +++ b/monitoring/grafana/dashboards/pipeline.json @@ -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": "" +} diff --git a/monitoring/prometheus/pipeline-rules.yml b/monitoring/prometheus/pipeline-rules.yml new file mode 100644 index 000000000..e515bd91a --- /dev/null +++ b/monitoring/prometheus/pipeline-rules.yml @@ -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" diff --git a/monitoring/prometheus/prometheus.yml b/monitoring/prometheus/prometheus.yml new file mode 100644 index 000000000..00988fc3a --- /dev/null +++ b/monitoring/prometheus/prometheus.yml @@ -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']