Prometheus and Grafana dashboard for monitoring RabbitMQ

This commit is contained in:
2024-11-23 00:05:22 +02:00
parent 64dbc34a13
commit 7654a92e28
7 changed files with 463 additions and 4 deletions

View File

@@ -42,12 +42,15 @@ public class BrokerConnector {
DeliverCallback deliverCallback = (consumerTag, delivery) -> { DeliverCallback deliverCallback = (consumerTag, delivery) -> {
String message = new String(delivery.getBody(), StandardCharsets.UTF_8); 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(); Thread.currentThread().join();
} }
} }
} }

View File

@@ -49,11 +49,11 @@ public class BrokerConnector {
try { try {
String jsonMessage = generateRandomJson(); String jsonMessage = generateRandomJson();
channel.basicPublish("", QUEUE_NAME, null, jsonMessage.getBytes(StandardCharsets.UTF_8)); channel.basicPublish("", QUEUE_NAME, null, jsonMessage.getBytes(StandardCharsets.UTF_8));
System.out.println("Sent: " + jsonMessage); // System.out.println("Sent: " + jsonMessage);
} catch (IOException e) { } catch (IOException e) {
System.err.println("Failed to send message: " + e.getMessage()); System.err.println("Failed to send message: " + e.getMessage());
} }
}, 0, 10, TimeUnit.SECONDS); }, 0, 1, TimeUnit.NANOSECONDS);
latch.await(); latch.await();
scheduler.shutdown(); scheduler.shutdown();

View File

@@ -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/

View File

@@ -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
}

View File

@@ -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"

View File

@@ -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' ]

View File

@@ -1,5 +1,6 @@
services: services:
symphony-manager: symphony-manager:
container_name: manager
build: build:
context: ./SymphonyManager context: ./SymphonyManager
dockerfile: Dockerfile dockerfile: Dockerfile
@@ -9,6 +10,7 @@ services:
- symphony-network - symphony-network
symphony-producer: symphony-producer:
container_name: producer
build: build:
context: ./SymphonyProducer context: ./SymphonyProducer
dockerfile: Dockerfile dockerfile: Dockerfile
@@ -19,19 +21,65 @@ services:
rabbitmq: rabbitmq:
image: "rabbitmq:management" image: "rabbitmq:management"
container_name: rabbitmq
ports: ports:
- "5672:5672" - "5672:5672"
- "15672:15672" - "15672:15672"
- "15692:15692"
environment: environment:
- RABBITMQ_DEFAULT_USER=symphony - RABBITMQ_DEFAULT_USER=symphony
- RABBITMQ_DEFAULT_PASS=symphony - RABBITMQ_DEFAULT_PASS=symphony
- RABBITMQ_NODENAME=rabbit@rabbitmq - RABBITMQ_NODENAME=rabbit@rabbitmq
- RABBITMQ_PROMETHEUS_RETENTION_POLICY=1h
command: >
sh -c "
rabbitmq-plugins enable --offline rabbitmq_prometheus &&
rabbitmq-server"
volumes: volumes:
- ./config/rabbitmq/rabbit.conf:/etc/rabbitmq/rabbitmq.conf:ro - ./config/rabbitmq/rabbit.conf:/etc/rabbitmq/rabbitmq.conf:ro
networks: networks:
- symphony-network - symphony-network
restart: always 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: networks:
symphony-network: symphony-network:
driver: bridge driver: bridge