fix: correct Grafana dashboard JSON format

- Remove dashboard wrapper from JSON files
- Dashboards now load successfully
- Update monitoring guide with correct instructions
This commit is contained in:
roma-dxunvrs
2026-10-03 22:59:11 +03:00
parent 96af109f6d
commit 91d54f4ef0
3 changed files with 474 additions and 376 deletions
+22 -5
View File
@@ -2,14 +2,31 @@
## Быстрый старт ## Быстрый старт
1. **Доступ к сервисам:** 1. **Запуск:**
```bash
docker compose up -d
```
2. **Доступ к сервисам:**
- Приложение: http://localhost:8080 - Приложение: http://localhost:8080
- Prometheus: http://localhost:9090 - Prometheus: http://localhost:9090
- Grafana: http://localhost:3000 (admin/admin) - Grafana: http://localhost:3000 (логин: admin, пароль: admin)
2. **Дашборды автоматически загружены:** 3. **Дашборды:**
- Spring Boot Application Metrics - Открой Grafana → Home → Dashboards
- PostgreSQL & HikariCP Monitoring - Два дашборда загружены автоматически:
- **Spring Boot Application Metrics** — HTTP, JVM, CPU, GC
- **PostgreSQL & HikariCP Monitoring** — connection pool, база данных
4. **Создай нагрузку для проверки:**
```bash
# Создать задачу
curl -X POST http://localhost:8080/api/tasks \
-H "Content-Type: application/json" \
-d '{"title":"Test","description":"Load test","completed":false}'
# Посмотреть метрики появятся в Grafana через 5-15 секунд
```
## Основные метрики ## Основные метрики
+102 -67
View File
@@ -1,195 +1,230 @@
{ {
"dashboard": {
"title": "Spring Boot Application Metrics", "title": "Spring Boot Application Metrics",
"tags": ["spring-boot", "todo-app"], "tags": ["spring-boot", "todo-app"],
"timezone": "browser", "timezone": "browser",
"schemaVersion": 16,
"version": 0,
"refresh": "5s",
"panels": [ "panels": [
{ {
"id": 1, "id": 1,
"title": "HTTP Request Rate", "title": "HTTP Request Rate",
"type": "graph", "type": "timeseries",
"gridPos": {"x": 0, "y": 0, "w": 12, "h": 8}, "gridPos": {"x": 0, "y": 0, "w": 12, "h": 8},
"targets": [ "targets": [
{ {
"expr": "rate(http_server_requests_seconds_count{application=\"todo\"}[1m])", "expr": "rate(http_server_requests_seconds_count{application=\"todo\"}[1m])",
"legendFormat": "{{method}} {{uri}} - {{status}}" "legendFormat": "{{method}} {{uri}} - {{status}}",
"refId": "A"
} }
], ],
"yaxes": [ "fieldConfig": {
{"format": "reqps", "label": "Requests/sec"}, "defaults": {
{"format": "short"} "unit": "reqps",
] "custom": {}
}
}
}, },
{ {
"id": 2, "id": 2,
"title": "HTTP Request Duration (p95, p99)", "title": "HTTP Request Duration (p95, p99)",
"type": "graph", "type": "timeseries",
"gridPos": {"x": 12, "y": 0, "w": 12, "h": 8}, "gridPos": {"x": 12, "y": 0, "w": 12, "h": 8},
"targets": [ "targets": [
{ {
"expr": "histogram_quantile(0.95, sum(rate(http_server_requests_seconds_bucket{application=\"todo\"}[5m])) by (le, uri))", "expr": "histogram_quantile(0.95, sum(rate(http_server_requests_seconds_bucket{application=\"todo\"}[5m])) by (le, uri))",
"legendFormat": "p95 - {{uri}}" "legendFormat": "p95 - {{uri}}",
"refId": "A"
}, },
{ {
"expr": "histogram_quantile(0.99, sum(rate(http_server_requests_seconds_bucket{application=\"todo\"}[5m])) by (le, uri))", "expr": "histogram_quantile(0.99, sum(rate(http_server_requests_seconds_bucket{application=\"todo\"}[5m])) by (le, uri))",
"legendFormat": "p99 - {{uri}}" "legendFormat": "p99 - {{uri}}",
"refId": "B"
} }
], ],
"yaxes": [ "fieldConfig": {
{"format": "s", "label": "Duration"}, "defaults": {
{"format": "short"} "unit": "s",
] "custom": {}
}
}
}, },
{ {
"id": 3, "id": 3,
"title": "HTTP Status Codes", "title": "HTTP Status Codes",
"type": "graph", "type": "timeseries",
"gridPos": {"x": 0, "y": 8, "w": 12, "h": 8}, "gridPos": {"x": 0, "y": 8, "w": 12, "h": 8},
"targets": [ "targets": [
{ {
"expr": "sum(rate(http_server_requests_seconds_count{application=\"todo\"}[1m])) by (status)", "expr": "sum(rate(http_server_requests_seconds_count{application=\"todo\"}[1m])) by (status)",
"legendFormat": "{{status}}" "legendFormat": "{{status}}",
"refId": "A"
} }
], ],
"yaxes": [ "fieldConfig": {
{"format": "reqps"}, "defaults": {
{"format": "short"} "unit": "reqps",
] "custom": {}
}
}
}, },
{ {
"id": 4, "id": 4,
"title": "JVM Memory Used", "title": "JVM Memory Used",
"type": "graph", "type": "timeseries",
"gridPos": {"x": 12, "y": 8, "w": 12, "h": 8}, "gridPos": {"x": 12, "y": 8, "w": 12, "h": 8},
"targets": [ "targets": [
{ {
"expr": "jvm_memory_used_bytes{application=\"todo\", area=\"heap\"}", "expr": "jvm_memory_used_bytes{application=\"todo\", area=\"heap\"}",
"legendFormat": "Heap" "legendFormat": "Heap",
"refId": "A"
}, },
{ {
"expr": "jvm_memory_used_bytes{application=\"todo\", area=\"nonheap\"}", "expr": "jvm_memory_used_bytes{application=\"todo\", area=\"nonheap\"}",
"legendFormat": "Non-Heap" "legendFormat": "Non-Heap",
"refId": "B"
}, },
{ {
"expr": "jvm_memory_max_bytes{application=\"todo\", area=\"heap\"}", "expr": "jvm_memory_max_bytes{application=\"todo\", area=\"heap\"}",
"legendFormat": "Heap Max" "legendFormat": "Heap Max",
"refId": "C"
} }
], ],
"yaxes": [ "fieldConfig": {
{"format": "bytes"}, "defaults": {
{"format": "short"} "unit": "bytes",
] "custom": {}
}
}
}, },
{ {
"id": 5, "id": 5,
"title": "Database Connection Pool", "title": "Database Connection Pool",
"type": "graph", "type": "timeseries",
"gridPos": {"x": 0, "y": 16, "w": 12, "h": 8}, "gridPos": {"x": 0, "y": 16, "w": 12, "h": 8},
"targets": [ "targets": [
{ {
"expr": "hikaricp_connections_active{application=\"todo\"}", "expr": "hikaricp_connections_active{application=\"todo\"}",
"legendFormat": "Active" "legendFormat": "Active",
"refId": "A"
}, },
{ {
"expr": "hikaricp_connections_idle{application=\"todo\"}", "expr": "hikaricp_connections_idle{application=\"todo\"}",
"legendFormat": "Idle" "legendFormat": "Idle",
"refId": "B"
}, },
{ {
"expr": "hikaricp_connections{application=\"todo\"}", "expr": "hikaricp_connections{application=\"todo\"}",
"legendFormat": "Total" "legendFormat": "Total",
"refId": "C"
}, },
{ {
"expr": "hikaricp_connections_max{application=\"todo\"}", "expr": "hikaricp_connections_max{application=\"todo\"}",
"legendFormat": "Max" "legendFormat": "Max",
"refId": "D"
} }
], ],
"yaxes": [ "fieldConfig": {
{"format": "short", "label": "Connections"}, "defaults": {
{"format": "short"} "unit": "short",
] "custom": {}
}
}
}, },
{ {
"id": 6, "id": 6,
"title": "Database Connection Acquire Time", "title": "Database Connection Acquire Time",
"type": "graph", "type": "timeseries",
"gridPos": {"x": 12, "y": 16, "w": 12, "h": 8}, "gridPos": {"x": 12, "y": 16, "w": 12, "h": 8},
"targets": [ "targets": [
{ {
"expr": "rate(hikaricp_connections_acquire_seconds_sum{application=\"todo\"}[1m]) / rate(hikaricp_connections_acquire_seconds_count{application=\"todo\"}[1m])", "expr": "rate(hikaricp_connections_acquire_seconds_sum{application=\"todo\"}[1m]) / rate(hikaricp_connections_acquire_seconds_count{application=\"todo\"}[1m])",
"legendFormat": "Avg Acquire Time" "legendFormat": "Avg Acquire Time",
"refId": "A"
} }
], ],
"yaxes": [ "fieldConfig": {
{"format": "s"}, "defaults": {
{"format": "short"} "unit": "s",
] "custom": {}
}
}
}, },
{ {
"id": 7, "id": 7,
"title": "JVM Threads", "title": "JVM Threads",
"type": "graph", "type": "timeseries",
"gridPos": {"x": 0, "y": 24, "w": 8, "h": 8}, "gridPos": {"x": 0, "y": 24, "w": 8, "h": 8},
"targets": [ "targets": [
{ {
"expr": "jvm_threads_live_threads{application=\"todo\"}", "expr": "jvm_threads_live_threads{application=\"todo\"}",
"legendFormat": "Live" "legendFormat": "Live",
"refId": "A"
}, },
{ {
"expr": "jvm_threads_daemon_threads{application=\"todo\"}", "expr": "jvm_threads_daemon_threads{application=\"todo\"}",
"legendFormat": "Daemon" "legendFormat": "Daemon",
"refId": "B"
}, },
{ {
"expr": "jvm_threads_peak_threads{application=\"todo\"}", "expr": "jvm_threads_peak_threads{application=\"todo\"}",
"legendFormat": "Peak" "legendFormat": "Peak",
"refId": "C"
} }
], ],
"yaxes": [ "fieldConfig": {
{"format": "short", "label": "Threads"}, "defaults": {
{"format": "short"} "unit": "short",
] "custom": {}
}
}
}, },
{ {
"id": 8, "id": 8,
"title": "GC Pause Time", "title": "GC Pause Time",
"type": "graph", "type": "timeseries",
"gridPos": {"x": 8, "y": 24, "w": 8, "h": 8}, "gridPos": {"x": 8, "y": 24, "w": 8, "h": 8},
"targets": [ "targets": [
{ {
"expr": "rate(jvm_gc_pause_seconds_sum{application=\"todo\"}[1m])", "expr": "rate(jvm_gc_pause_seconds_sum{application=\"todo\"}[1m])",
"legendFormat": "{{action}} - {{cause}}" "legendFormat": "{{action}} - {{cause}}",
"refId": "A"
} }
], ],
"yaxes": [ "fieldConfig": {
{"format": "s", "label": "GC Time"}, "defaults": {
{"format": "short"} "unit": "s",
] "custom": {}
}
}
}, },
{ {
"id": 9, "id": 9,
"title": "System CPU Usage", "title": "System CPU Usage",
"type": "graph", "type": "timeseries",
"gridPos": {"x": 16, "y": 24, "w": 8, "h": 8}, "gridPos": {"x": 16, "y": 24, "w": 8, "h": 8},
"targets": [ "targets": [
{ {
"expr": "system_cpu_usage{application=\"todo\"}", "expr": "system_cpu_usage{application=\"todo\"}",
"legendFormat": "System" "legendFormat": "System",
"refId": "A"
}, },
{ {
"expr": "process_cpu_usage{application=\"todo\"}", "expr": "process_cpu_usage{application=\"todo\"}",
"legendFormat": "Process" "legendFormat": "Process",
"refId": "B"
} }
], ],
"yaxes": [ "fieldConfig": {
{"format": "percentunit", "label": "CPU"}, "defaults": {
{"format": "short"} "unit": "percentunit",
] "custom": {}
}
}
} }
], ],
"refresh": "5s",
"time": { "time": {
"from": "now-15m", "from": "now-15m",
"to": "now" "to": "now"
} }
},
"overwrite": true
} }
+96 -50
View File
@@ -1,23 +1,31 @@
{ {
"dashboard": {
"title": "PostgreSQL & HikariCP Monitoring", "title": "PostgreSQL & HikariCP Monitoring",
"tags": ["database", "postgres", "hikaricp"], "tags": ["database", "postgres", "hikaricp"],
"timezone": "browser", "timezone": "browser",
"schemaVersion": 16,
"version": 0,
"refresh": "5s",
"panels": [ "panels": [
{ {
"id": 1, "id": 1,
"title": "Connection Pool Status", "title": "Connection Pool Status - Active",
"type": "stat", "type": "stat",
"gridPos": {"x": 0, "y": 0, "w": 6, "h": 4}, "gridPos": {"x": 0, "y": 0, "w": 6, "h": 4},
"targets": [ "targets": [
{ {
"expr": "hikaricp_connections_active{application=\"todo\"}", "expr": "hikaricp_connections_active{application=\"todo\"}",
"legendFormat": "Active" "legendFormat": "Active",
"refId": "A"
} }
], ],
"options": { "options": {
"colorMode": "value", "colorMode": "value",
"graphMode": "area" "graphMode": "area"
},
"fieldConfig": {
"defaults": {
"unit": "short"
}
} }
}, },
{ {
@@ -28,12 +36,18 @@
"targets": [ "targets": [
{ {
"expr": "hikaricp_connections_idle{application=\"todo\"}", "expr": "hikaricp_connections_idle{application=\"todo\"}",
"legendFormat": "Idle" "legendFormat": "Idle",
"refId": "A"
} }
], ],
"options": { "options": {
"colorMode": "value", "colorMode": "value",
"graphMode": "area" "graphMode": "area"
},
"fieldConfig": {
"defaults": {
"unit": "short"
}
} }
}, },
{ {
@@ -44,12 +58,18 @@
"targets": [ "targets": [
{ {
"expr": "hikaricp_connections{application=\"todo\"}", "expr": "hikaricp_connections{application=\"todo\"}",
"legendFormat": "Total" "legendFormat": "Total",
"refId": "A"
} }
], ],
"options": { "options": {
"colorMode": "value", "colorMode": "value",
"graphMode": "area" "graphMode": "area"
},
"fieldConfig": {
"defaults": {
"unit": "short"
}
} }
}, },
{ {
@@ -60,128 +80,154 @@
"targets": [ "targets": [
{ {
"expr": "hikaricp_connections_pending{application=\"todo\"}", "expr": "hikaricp_connections_pending{application=\"todo\"}",
"legendFormat": "Pending" "legendFormat": "Pending",
"refId": "A"
} }
], ],
"options": { "options": {
"colorMode": "value", "colorMode": "value",
"graphMode": "area" "graphMode": "area"
},
"fieldConfig": {
"defaults": {
"unit": "short"
}
} }
}, },
{ {
"id": 5, "id": 5,
"title": "Connection Pool Utilization (%)", "title": "Connection Pool Utilization (%)",
"type": "graph", "type": "timeseries",
"gridPos": {"x": 0, "y": 4, "w": 12, "h": 8}, "gridPos": {"x": 0, "y": 4, "w": 12, "h": 8},
"targets": [ "targets": [
{ {
"expr": "(hikaricp_connections_active{application=\"todo\"} / hikaricp_connections_max{application=\"todo\"}) * 100", "expr": "(hikaricp_connections_active{application=\"todo\"} / hikaricp_connections_max{application=\"todo\"}) * 100",
"legendFormat": "Active %" "legendFormat": "Active %",
"refId": "A"
}, },
{ {
"expr": "(hikaricp_connections{application=\"todo\"} / hikaricp_connections_max{application=\"todo\"}) * 100", "expr": "(hikaricp_connections{application=\"todo\"} / hikaricp_connections_max{application=\"todo\"}) * 100",
"legendFormat": "Total %" "legendFormat": "Total %",
"refId": "B"
} }
], ],
"yaxes": [ "fieldConfig": {
{"format": "percent", "label": "Utilization", "min": 0, "max": 100}, "defaults": {
{"format": "short"} "unit": "percent",
] "min": 0,
"max": 100,
"custom": {}
}
}
}, },
{ {
"id": 6, "id": 6,
"title": "Connection Acquire Time", "title": "Connection Acquire Time",
"type": "graph", "type": "timeseries",
"gridPos": {"x": 12, "y": 4, "w": 12, "h": 8}, "gridPos": {"x": 12, "y": 4, "w": 12, "h": 8},
"targets": [ "targets": [
{ {
"expr": "histogram_quantile(0.5, rate(hikaricp_connections_acquire_seconds_bucket{application=\"todo\"}[1m]))", "expr": "histogram_quantile(0.5, rate(hikaricp_connections_acquire_seconds_bucket{application=\"todo\"}[1m]))",
"legendFormat": "p50" "legendFormat": "p50",
"refId": "A"
}, },
{ {
"expr": "histogram_quantile(0.95, rate(hikaricp_connections_acquire_seconds_bucket{application=\"todo\"}[1m]))", "expr": "histogram_quantile(0.95, rate(hikaricp_connections_acquire_seconds_bucket{application=\"todo\"}[1m]))",
"legendFormat": "p95" "legendFormat": "p95",
"refId": "B"
}, },
{ {
"expr": "histogram_quantile(0.99, rate(hikaricp_connections_acquire_seconds_bucket{application=\"todo\"}[1m]))", "expr": "histogram_quantile(0.99, rate(hikaricp_connections_acquire_seconds_bucket{application=\"todo\"}[1m]))",
"legendFormat": "p99" "legendFormat": "p99",
"refId": "C"
} }
], ],
"yaxes": [ "fieldConfig": {
{"format": "s", "label": "Time"}, "defaults": {
{"format": "short"} "unit": "s",
] "custom": {}
}
}
}, },
{ {
"id": 7, "id": 7,
"title": "Connection Timeout Count", "title": "Connection Timeout Count",
"type": "graph", "type": "timeseries",
"gridPos": {"x": 0, "y": 12, "w": 12, "h": 8}, "gridPos": {"x": 0, "y": 12, "w": 12, "h": 8},
"targets": [ "targets": [
{ {
"expr": "rate(hikaricp_connections_timeout_total{application=\"todo\"}[1m])", "expr": "rate(hikaricp_connections_timeout_total{application=\"todo\"}[1m])",
"legendFormat": "Timeouts/sec" "legendFormat": "Timeouts/sec",
"refId": "A"
} }
], ],
"yaxes": [ "fieldConfig": {
{"format": "short"}, "defaults": {
{"format": "short"} "unit": "short",
] "custom": {}
}
}
}, },
{ {
"id": 8, "id": 8,
"title": "Connection Creation Time", "title": "Connection Creation Time",
"type": "graph", "type": "timeseries",
"gridPos": {"x": 12, "y": 12, "w": 12, "h": 8}, "gridPos": {"x": 12, "y": 12, "w": 12, "h": 8},
"targets": [ "targets": [
{ {
"expr": "rate(hikaricp_connections_creation_seconds_sum{application=\"todo\"}[1m]) / rate(hikaricp_connections_creation_seconds_count{application=\"todo\"}[1m])", "expr": "rate(hikaricp_connections_creation_seconds_sum{application=\"todo\"}[1m]) / rate(hikaricp_connections_creation_seconds_count{application=\"todo\"}[1m])",
"legendFormat": "Avg Creation Time" "legendFormat": "Avg Creation Time",
"refId": "A"
} }
], ],
"yaxes": [ "fieldConfig": {
{"format": "s"}, "defaults": {
{"format": "short"} "unit": "s",
] "custom": {}
}
}
}, },
{ {
"id": 9, "id": 9,
"title": "Connection Usage Time", "title": "Connection Usage Time",
"type": "graph", "type": "timeseries",
"gridPos": {"x": 0, "y": 20, "w": 12, "h": 8}, "gridPos": {"x": 0, "y": 20, "w": 12, "h": 8},
"targets": [ "targets": [
{ {
"expr": "rate(hikaricp_connections_usage_seconds_sum{application=\"todo\"}[1m]) / rate(hikaricp_connections_usage_seconds_count{application=\"todo\"}[1m])", "expr": "rate(hikaricp_connections_usage_seconds_sum{application=\"todo\"}[1m]) / rate(hikaricp_connections_usage_seconds_count{application=\"todo\"}[1m])",
"legendFormat": "Avg Usage Time" "legendFormat": "Avg Usage Time",
"refId": "A"
} }
], ],
"yaxes": [ "fieldConfig": {
{"format": "s"}, "defaults": {
{"format": "short"} "unit": "s",
] "custom": {}
}
}
}, },
{ {
"id": 10, "id": 10,
"title": "JDBC Queries Rate", "title": "Active Connections Timeline",
"type": "graph", "type": "timeseries",
"gridPos": {"x": 12, "y": 20, "w": 12, "h": 8}, "gridPos": {"x": 12, "y": 20, "w": 12, "h": 8},
"targets": [ "targets": [
{ {
"expr": "rate(jdbc_connections_active{application=\"todo\"}[1m])", "expr": "hikaricp_connections_active{application=\"todo\"}",
"legendFormat": "Active JDBC Connections" "legendFormat": "Active Connections",
"refId": "A"
} }
], ],
"yaxes": [ "fieldConfig": {
{"format": "short"}, "defaults": {
{"format": "short"} "unit": "short",
] "custom": {}
}
}
} }
], ],
"refresh": "5s",
"time": { "time": {
"from": "now-15m", "from": "now-15m",
"to": "now" "to": "now"
} }
},
"overwrite": true
} }