diff --git a/SymphonyManager/src/main/java/io/github/lumijiez/BrokerConnector.java b/SymphonyManager/src/main/java/io/github/lumijiez/BrokerConnector.java index 445955a..0d18341 100644 --- a/SymphonyManager/src/main/java/io/github/lumijiez/BrokerConnector.java +++ b/SymphonyManager/src/main/java/io/github/lumijiez/BrokerConnector.java @@ -42,12 +42,15 @@ public class BrokerConnector { DeliverCallback deliverCallback = (consumerTag, delivery) -> { String message = new String(delivery.getBody(), StandardCharsets.UTF_8); - System.out.println("Received: " + message); +// System.out.println("Received: " + message); + + channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); }; - channel.basicConsume(QUEUE_NAME, true, deliverCallback, consumerTag -> {}); + channel.basicConsume(QUEUE_NAME, false, deliverCallback, consumerTag -> {}); Thread.currentThread().join(); } } + } diff --git a/SymphonyProducer/src/main/java/io/github/lumijiez/BrokerConnector.java b/SymphonyProducer/src/main/java/io/github/lumijiez/BrokerConnector.java index 5e0cf59..fd50780 100644 --- a/SymphonyProducer/src/main/java/io/github/lumijiez/BrokerConnector.java +++ b/SymphonyProducer/src/main/java/io/github/lumijiez/BrokerConnector.java @@ -49,11 +49,11 @@ public class BrokerConnector { try { String jsonMessage = generateRandomJson(); channel.basicPublish("", QUEUE_NAME, null, jsonMessage.getBytes(StandardCharsets.UTF_8)); - System.out.println("Sent: " + jsonMessage); +// System.out.println("Sent: " + jsonMessage); } catch (IOException e) { System.err.println("Failed to send message: " + e.getMessage()); } - }, 0, 10, TimeUnit.SECONDS); + }, 0, 1, TimeUnit.NANOSECONDS); latch.await(); scheduler.shutdown(); diff --git a/config/grafana/provisioning/dashboards/dashboard.yaml b/config/grafana/provisioning/dashboards/dashboard.yaml new file mode 100644 index 0000000..070aa0d --- /dev/null +++ b/config/grafana/provisioning/dashboards/dashboard.yaml @@ -0,0 +1,10 @@ +apiVersion: 1 +providers: + - name: 'default' + orgId: 1 + folder: '' + type: file + disableDeletion: false + editable: true + options: + path: /etc/grafana/provisioning/dashboards/dashboards/ diff --git a/config/grafana/provisioning/dashboards/dashboards/main.json b/config/grafana/provisioning/dashboards/dashboards/main.json new file mode 100644 index 0000000..c4c0cde --- /dev/null +++ b/config/grafana/provisioning/dashboards/dashboards/main.json @@ -0,0 +1,368 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "description": "Essential RabbitMQ monitoring metrics", + "editable": true, + "graphTooltip": 1, + "links": [], + "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 1, + "panels": [], + "title": "Message Metrics", + "type": "row" + }, + { + "datasource": "Prometheus", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "yellow", + "value": 10000 + }, + { + "color": "red", + "value": 100000 + } + ] + }, + "unit": "short" + } + }, + "gridPos": { + "h": 8, + "w": 8, + "x": 0, + "y": 1 + }, + "id": 2, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + } + }, + "targets": [ + { + "expr": "sum(increase(rabbitmq_channel_messages_acked_total[1h]))", + "interval": "", + "legendFormat": "", + "refId": "A" + } + ], + "title": "Messages Acknowledged (Last Hour)", + "type": "stat" + }, + { + "datasource": "Prometheus", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "smooth", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": true + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "short" + } + }, + "gridPos": { + "h": 8, + "w": 16, + "x": 8, + "y": 1 + }, + "id": 3, + "options": { + "legend": { + "calcs": ["mean", "max"], + "displayMode": "table", + "placement": "right" + }, + "tooltip": { + "mode": "multi" + } + }, + "targets": [ + { + "expr": "rate(rabbitmq_channel_messages_published_total[5m])", + "interval": "", + "legendFormat": "Published", + "refId": "A" + }, + { + "expr": "rate(rabbitmq_channel_messages_delivered_total[5m])", + "interval": "", + "legendFormat": "Delivered", + "refId": "B" + }, + { + "expr": "rate(rabbitmq_channel_messages_acked_total[5m])", + "interval": "", + "legendFormat": "Acknowledged", + "refId": "C" + } + ], + "title": "Message Rate", + "type": "timeseries" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 9 + }, + "id": 4, + "panels": [], + "title": "System Resources", + "type": "row" + }, + { + "datasource": "Prometheus", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "smooth", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": true + }, + "mappings": [], + "max": 100, + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "percent" + } + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 10 + }, + "id": 5, + "options": { + "legend": { + "calcs": ["mean", "max"], + "displayMode": "table", + "placement": "right" + }, + "tooltip": { + "mode": "multi" + } + }, + "targets": [ + { + "expr": "100 - (avg by (instance) (rate(node_cpu_seconds_total{mode=\"idle\"}[5m])) * 100)", + "interval": "", + "legendFormat": "CPU {{instance}}", + "refId": "A" + } + ], + "title": "CPU Usage", + "type": "timeseries" + }, + { + "datasource": "Prometheus", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "smooth", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": true + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "bytes" + } + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 10 + }, + "id": 6, + "options": { + "legend": { + "calcs": ["mean", "max"], + "displayMode": "table", + "placement": "right" + }, + "tooltip": { + "mode": "multi" + } + }, + "targets": [ + { + "expr": "node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes", + "interval": "", + "legendFormat": "Memory Used {{instance}}", + "refId": "A" + }, + { + "expr": "node_memory_MemTotal_bytes", + "interval": "", + "legendFormat": "Memory Total {{instance}}", + "refId": "B" + } + ], + "title": "Memory Usage", + "type": "timeseries" + } + ], + "refresh": "10s", + "schemaVersion": 30, + "style": "dark", + "tags": ["rabbitmq", "monitoring"], + "templating": { + "list": [] + }, + "time": { + "from": "now-1h", + "to": "now" + }, + "timepicker": { + "refresh_intervals": [ + "5s", + "10s", + "30s", + "1m", + "5m", + "15m", + "30m", + "1h", + "2h", + "1d" + ] + }, + "timezone": "browser", + "title": "RabbitMQ Essential Monitoring", + "uid": "rabbitmq-monitoring-simple", + "version": 1 +} \ No newline at end of file diff --git a/config/grafana/provisioning/datasources/datasource.yml b/config/grafana/provisioning/datasources/datasource.yml new file mode 100644 index 0000000..d73068f --- /dev/null +++ b/config/grafana/provisioning/datasources/datasource.yml @@ -0,0 +1,11 @@ +apiVersion: 1 +datasources: + - name: Prometheus + type: prometheus + access: proxy + url: "http://prometheus:9090" + isDefault: true + editable: true + basicAuth: true + basicAuthUser: "symphony" + basicAuthPassword: "symphony" diff --git a/config/prometheus/prometheus.yml b/config/prometheus/prometheus.yml new file mode 100644 index 0000000..9484d71 --- /dev/null +++ b/config/prometheus/prometheus.yml @@ -0,0 +1,19 @@ +global: + scrape_interval: 1s + +scrape_configs: + + - job_name: 'rabbitmq' + static_configs: + - targets: ['rabbitmq:15692'] + basic_auth: + username: "symphony" + password: "symphony" + + - job_name: 'node_exporter' + static_configs: + - targets: ['node-exporter:9100'] + + - job_name: 'prometheus' + static_configs: + - targets: [ 'prometheus:9090' ] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index e9fe6d1..9086b6d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,6 @@ services: symphony-manager: + container_name: manager build: context: ./SymphonyManager dockerfile: Dockerfile @@ -9,6 +10,7 @@ services: - symphony-network symphony-producer: + container_name: producer build: context: ./SymphonyProducer dockerfile: Dockerfile @@ -19,19 +21,65 @@ services: rabbitmq: image: "rabbitmq:management" + container_name: rabbitmq ports: - "5672:5672" - "15672:15672" + - "15692:15692" environment: - RABBITMQ_DEFAULT_USER=symphony - RABBITMQ_DEFAULT_PASS=symphony - RABBITMQ_NODENAME=rabbit@rabbitmq + - RABBITMQ_PROMETHEUS_RETENTION_POLICY=1h + command: > + sh -c " + rabbitmq-plugins enable --offline rabbitmq_prometheus && + rabbitmq-server" volumes: - ./config/rabbitmq/rabbit.conf:/etc/rabbitmq/rabbitmq.conf:ro networks: - symphony-network restart: always + prometheus: + image: prom/prometheus + container_name: prometheus + ports: + - "9090:9090" + volumes: + - ./config/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro + networks: + - symphony-network + + grafana: + image: grafana/grafana + container_name: grafana + ports: + - "3000:3000" + volumes: + - ./config/grafana/provisioning:/etc/grafana/provisioning + - ./config/grafana/provisioning/dashboards:/etc/grafana/provisioning/dashboards + environment: + - GF_SECURITY_ADMIN_USER=symphony + - GF_SECURITY_ADMIN_PASSWORD=symphony + networks: + - symphony-network + + node-exporter: + image: prom/node-exporter:latest + container_name: node-exporter + ports: + - "9100:9100" + command: + - "--no-collector.hwmon" + volumes: + - /proc:/host/proc:ro + - /sys:/host/sys:ro + - /:/rootfs:ro + restart: always + networks: + - symphony-network + networks: symphony-network: driver: bridge \ No newline at end of file