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 секунд
```
## Основные метрики ## Основные метрики
+226 -191
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,
"panels": [ "version": 0,
{ "refresh": "5s",
"id": 1, "panels": [
"title": "HTTP Request Rate", {
"type": "graph", "id": 1,
"gridPos": {"x": 0, "y": 0, "w": 12, "h": 8}, "title": "HTTP Request Rate",
"targets": [ "type": "timeseries",
{ "gridPos": {"x": 0, "y": 0, "w": 12, "h": 8},
"expr": "rate(http_server_requests_seconds_count{application=\"todo\"}[1m])", "targets": [
"legendFormat": "{{method}} {{uri}} - {{status}}" {
} "expr": "rate(http_server_requests_seconds_count{application=\"todo\"}[1m])",
], "legendFormat": "{{method}} {{uri}} - {{status}}",
"yaxes": [ "refId": "A"
{"format": "reqps", "label": "Requests/sec"}, }
{"format": "short"} ],
] "fieldConfig": {
}, "defaults": {
{ "unit": "reqps",
"id": 2, "custom": {}
"title": "HTTP Request Duration (p95, p99)", }
"type": "graph", }
"gridPos": {"x": 12, "y": 0, "w": 12, "h": 8}, },
"targets": [ {
{ "id": 2,
"expr": "histogram_quantile(0.95, sum(rate(http_server_requests_seconds_bucket{application=\"todo\"}[5m])) by (le, uri))", "title": "HTTP Request Duration (p95, p99)",
"legendFormat": "p95 - {{uri}}" "type": "timeseries",
}, "gridPos": {"x": 12, "y": 0, "w": 12, "h": 8},
{ "targets": [
"expr": "histogram_quantile(0.99, sum(rate(http_server_requests_seconds_bucket{application=\"todo\"}[5m])) by (le, uri))", {
"legendFormat": "p99 - {{uri}}" "expr": "histogram_quantile(0.95, sum(rate(http_server_requests_seconds_bucket{application=\"todo\"}[5m])) by (le, uri))",
} "legendFormat": "p95 - {{uri}}",
], "refId": "A"
"yaxes": [ },
{"format": "s", "label": "Duration"}, {
{"format": "short"} "expr": "histogram_quantile(0.99, sum(rate(http_server_requests_seconds_bucket{application=\"todo\"}[5m])) by (le, uri))",
] "legendFormat": "p99 - {{uri}}",
}, "refId": "B"
{ }
"id": 3, ],
"title": "HTTP Status Codes", "fieldConfig": {
"type": "graph", "defaults": {
"gridPos": {"x": 0, "y": 8, "w": 12, "h": 8}, "unit": "s",
"targets": [ "custom": {}
{ }
"expr": "sum(rate(http_server_requests_seconds_count{application=\"todo\"}[1m])) by (status)", }
"legendFormat": "{{status}}" },
} {
], "id": 3,
"yaxes": [ "title": "HTTP Status Codes",
{"format": "reqps"}, "type": "timeseries",
{"format": "short"} "gridPos": {"x": 0, "y": 8, "w": 12, "h": 8},
] "targets": [
}, {
{ "expr": "sum(rate(http_server_requests_seconds_count{application=\"todo\"}[1m])) by (status)",
"id": 4, "legendFormat": "{{status}}",
"title": "JVM Memory Used", "refId": "A"
"type": "graph", }
"gridPos": {"x": 12, "y": 8, "w": 12, "h": 8}, ],
"targets": [ "fieldConfig": {
{ "defaults": {
"expr": "jvm_memory_used_bytes{application=\"todo\", area=\"heap\"}", "unit": "reqps",
"legendFormat": "Heap" "custom": {}
}, }
{ }
"expr": "jvm_memory_used_bytes{application=\"todo\", area=\"nonheap\"}", },
"legendFormat": "Non-Heap" {
}, "id": 4,
{ "title": "JVM Memory Used",
"expr": "jvm_memory_max_bytes{application=\"todo\", area=\"heap\"}", "type": "timeseries",
"legendFormat": "Heap Max" "gridPos": {"x": 12, "y": 8, "w": 12, "h": 8},
} "targets": [
], {
"yaxes": [ "expr": "jvm_memory_used_bytes{application=\"todo\", area=\"heap\"}",
{"format": "bytes"}, "legendFormat": "Heap",
{"format": "short"} "refId": "A"
] },
}, {
{ "expr": "jvm_memory_used_bytes{application=\"todo\", area=\"nonheap\"}",
"id": 5, "legendFormat": "Non-Heap",
"title": "Database Connection Pool", "refId": "B"
"type": "graph", },
"gridPos": {"x": 0, "y": 16, "w": 12, "h": 8}, {
"targets": [ "expr": "jvm_memory_max_bytes{application=\"todo\", area=\"heap\"}",
{ "legendFormat": "Heap Max",
"expr": "hikaricp_connections_active{application=\"todo\"}", "refId": "C"
"legendFormat": "Active" }
}, ],
{ "fieldConfig": {
"expr": "hikaricp_connections_idle{application=\"todo\"}", "defaults": {
"legendFormat": "Idle" "unit": "bytes",
}, "custom": {}
{ }
"expr": "hikaricp_connections{application=\"todo\"}", }
"legendFormat": "Total" },
}, {
{ "id": 5,
"expr": "hikaricp_connections_max{application=\"todo\"}", "title": "Database Connection Pool",
"legendFormat": "Max" "type": "timeseries",
} "gridPos": {"x": 0, "y": 16, "w": 12, "h": 8},
], "targets": [
"yaxes": [ {
{"format": "short", "label": "Connections"}, "expr": "hikaricp_connections_active{application=\"todo\"}",
{"format": "short"} "legendFormat": "Active",
] "refId": "A"
}, },
{ {
"id": 6, "expr": "hikaricp_connections_idle{application=\"todo\"}",
"title": "Database Connection Acquire Time", "legendFormat": "Idle",
"type": "graph", "refId": "B"
"gridPos": {"x": 12, "y": 16, "w": 12, "h": 8}, },
"targets": [ {
{ "expr": "hikaricp_connections{application=\"todo\"}",
"expr": "rate(hikaricp_connections_acquire_seconds_sum{application=\"todo\"}[1m]) / rate(hikaricp_connections_acquire_seconds_count{application=\"todo\"}[1m])", "legendFormat": "Total",
"legendFormat": "Avg Acquire Time" "refId": "C"
} },
], {
"yaxes": [ "expr": "hikaricp_connections_max{application=\"todo\"}",
{"format": "s"}, "legendFormat": "Max",
{"format": "short"} "refId": "D"
] }
}, ],
{ "fieldConfig": {
"id": 7, "defaults": {
"title": "JVM Threads", "unit": "short",
"type": "graph", "custom": {}
"gridPos": {"x": 0, "y": 24, "w": 8, "h": 8}, }
"targets": [ }
{ },
"expr": "jvm_threads_live_threads{application=\"todo\"}", {
"legendFormat": "Live" "id": 6,
}, "title": "Database Connection Acquire Time",
{ "type": "timeseries",
"expr": "jvm_threads_daemon_threads{application=\"todo\"}", "gridPos": {"x": 12, "y": 16, "w": 12, "h": 8},
"legendFormat": "Daemon" "targets": [
}, {
{ "expr": "rate(hikaricp_connections_acquire_seconds_sum{application=\"todo\"}[1m]) / rate(hikaricp_connections_acquire_seconds_count{application=\"todo\"}[1m])",
"expr": "jvm_threads_peak_threads{application=\"todo\"}", "legendFormat": "Avg Acquire Time",
"legendFormat": "Peak" "refId": "A"
} }
], ],
"yaxes": [ "fieldConfig": {
{"format": "short", "label": "Threads"}, "defaults": {
{"format": "short"} "unit": "s",
] "custom": {}
}, }
{ }
"id": 8, },
"title": "GC Pause Time", {
"type": "graph", "id": 7,
"gridPos": {"x": 8, "y": 24, "w": 8, "h": 8}, "title": "JVM Threads",
"targets": [ "type": "timeseries",
{ "gridPos": {"x": 0, "y": 24, "w": 8, "h": 8},
"expr": "rate(jvm_gc_pause_seconds_sum{application=\"todo\"}[1m])", "targets": [
"legendFormat": "{{action}} - {{cause}}" {
} "expr": "jvm_threads_live_threads{application=\"todo\"}",
], "legendFormat": "Live",
"yaxes": [ "refId": "A"
{"format": "s", "label": "GC Time"}, },
{"format": "short"} {
] "expr": "jvm_threads_daemon_threads{application=\"todo\"}",
}, "legendFormat": "Daemon",
{ "refId": "B"
"id": 9, },
"title": "System CPU Usage", {
"type": "graph", "expr": "jvm_threads_peak_threads{application=\"todo\"}",
"gridPos": {"x": 16, "y": 24, "w": 8, "h": 8}, "legendFormat": "Peak",
"targets": [ "refId": "C"
{ }
"expr": "system_cpu_usage{application=\"todo\"}", ],
"legendFormat": "System" "fieldConfig": {
}, "defaults": {
{ "unit": "short",
"expr": "process_cpu_usage{application=\"todo\"}", "custom": {}
"legendFormat": "Process" }
} }
], },
"yaxes": [ {
{"format": "percentunit", "label": "CPU"}, "id": 8,
{"format": "short"} "title": "GC Pause Time",
] "type": "timeseries",
"gridPos": {"x": 8, "y": 24, "w": 8, "h": 8},
"targets": [
{
"expr": "rate(jvm_gc_pause_seconds_sum{application=\"todo\"}[1m])",
"legendFormat": "{{action}} - {{cause}}",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "s",
"custom": {}
}
}
},
{
"id": 9,
"title": "System CPU Usage",
"type": "timeseries",
"gridPos": {"x": 16, "y": 24, "w": 8, "h": 8},
"targets": [
{
"expr": "system_cpu_usage{application=\"todo\"}",
"legendFormat": "System",
"refId": "A"
},
{
"expr": "process_cpu_usage{application=\"todo\"}",
"legendFormat": "Process",
"refId": "B"
}
],
"fieldConfig": {
"defaults": {
"unit": "percentunit",
"custom": {}
}
} }
],
"refresh": "5s",
"time": {
"from": "now-15m",
"to": "now"
} }
}, ],
"overwrite": true "time": {
"from": "now-15m",
"to": "now"
}
} }
+226 -180
View File
@@ -1,187 +1,233 @@
{ {
"dashboard": { "title": "PostgreSQL & HikariCP Monitoring",
"title": "PostgreSQL & HikariCP Monitoring", "tags": ["database", "postgres", "hikaricp"],
"tags": ["database", "postgres", "hikaricp"], "timezone": "browser",
"timezone": "browser", "schemaVersion": 16,
"panels": [ "version": 0,
{ "refresh": "5s",
"id": 1, "panels": [
"title": "Connection Pool Status", {
"type": "stat", "id": 1,
"gridPos": {"x": 0, "y": 0, "w": 6, "h": 4}, "title": "Connection Pool Status - Active",
"targets": [ "type": "stat",
{ "gridPos": {"x": 0, "y": 0, "w": 6, "h": 4},
"expr": "hikaricp_connections_active{application=\"todo\"}", "targets": [
"legendFormat": "Active" {
} "expr": "hikaricp_connections_active{application=\"todo\"}",
], "legendFormat": "Active",
"options": { "refId": "A"
"colorMode": "value",
"graphMode": "area"
} }
],
"options": {
"colorMode": "value",
"graphMode": "area"
}, },
{ "fieldConfig": {
"id": 2, "defaults": {
"title": "Idle Connections", "unit": "short"
"type": "stat", }
"gridPos": {"x": 6, "y": 0, "w": 6, "h": 4}, }
"targets": [ },
{ {
"expr": "hikaricp_connections_idle{application=\"todo\"}", "id": 2,
"legendFormat": "Idle" "title": "Idle Connections",
} "type": "stat",
], "gridPos": {"x": 6, "y": 0, "w": 6, "h": 4},
"options": { "targets": [
"colorMode": "value", {
"graphMode": "area" "expr": "hikaricp_connections_idle{application=\"todo\"}",
"legendFormat": "Idle",
"refId": "A"
}
],
"options": {
"colorMode": "value",
"graphMode": "area"
},
"fieldConfig": {
"defaults": {
"unit": "short"
}
}
},
{
"id": 3,
"title": "Total Connections",
"type": "stat",
"gridPos": {"x": 12, "y": 0, "w": 6, "h": 4},
"targets": [
{
"expr": "hikaricp_connections{application=\"todo\"}",
"legendFormat": "Total",
"refId": "A"
}
],
"options": {
"colorMode": "value",
"graphMode": "area"
},
"fieldConfig": {
"defaults": {
"unit": "short"
}
}
},
{
"id": 4,
"title": "Pending Threads",
"type": "stat",
"gridPos": {"x": 18, "y": 0, "w": 6, "h": 4},
"targets": [
{
"expr": "hikaricp_connections_pending{application=\"todo\"}",
"legendFormat": "Pending",
"refId": "A"
}
],
"options": {
"colorMode": "value",
"graphMode": "area"
},
"fieldConfig": {
"defaults": {
"unit": "short"
}
}
},
{
"id": 5,
"title": "Connection Pool Utilization (%)",
"type": "timeseries",
"gridPos": {"x": 0, "y": 4, "w": 12, "h": 8},
"targets": [
{
"expr": "(hikaricp_connections_active{application=\"todo\"} / hikaricp_connections_max{application=\"todo\"}) * 100",
"legendFormat": "Active %",
"refId": "A"
},
{
"expr": "(hikaricp_connections{application=\"todo\"} / hikaricp_connections_max{application=\"todo\"}) * 100",
"legendFormat": "Total %",
"refId": "B"
}
],
"fieldConfig": {
"defaults": {
"unit": "percent",
"min": 0,
"max": 100,
"custom": {}
}
}
},
{
"id": 6,
"title": "Connection Acquire Time",
"type": "timeseries",
"gridPos": {"x": 12, "y": 4, "w": 12, "h": 8},
"targets": [
{
"expr": "histogram_quantile(0.5, rate(hikaricp_connections_acquire_seconds_bucket{application=\"todo\"}[1m]))",
"legendFormat": "p50",
"refId": "A"
},
{
"expr": "histogram_quantile(0.95, rate(hikaricp_connections_acquire_seconds_bucket{application=\"todo\"}[1m]))",
"legendFormat": "p95",
"refId": "B"
},
{
"expr": "histogram_quantile(0.99, rate(hikaricp_connections_acquire_seconds_bucket{application=\"todo\"}[1m]))",
"legendFormat": "p99",
"refId": "C"
}
],
"fieldConfig": {
"defaults": {
"unit": "s",
"custom": {}
}
}
},
{
"id": 7,
"title": "Connection Timeout Count",
"type": "timeseries",
"gridPos": {"x": 0, "y": 12, "w": 12, "h": 8},
"targets": [
{
"expr": "rate(hikaricp_connections_timeout_total{application=\"todo\"}[1m])",
"legendFormat": "Timeouts/sec",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "short",
"custom": {}
}
}
},
{
"id": 8,
"title": "Connection Creation Time",
"type": "timeseries",
"gridPos": {"x": 12, "y": 12, "w": 12, "h": 8},
"targets": [
{
"expr": "rate(hikaricp_connections_creation_seconds_sum{application=\"todo\"}[1m]) / rate(hikaricp_connections_creation_seconds_count{application=\"todo\"}[1m])",
"legendFormat": "Avg Creation Time",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "s",
"custom": {}
}
}
},
{
"id": 9,
"title": "Connection Usage Time",
"type": "timeseries",
"gridPos": {"x": 0, "y": 20, "w": 12, "h": 8},
"targets": [
{
"expr": "rate(hikaricp_connections_usage_seconds_sum{application=\"todo\"}[1m]) / rate(hikaricp_connections_usage_seconds_count{application=\"todo\"}[1m])",
"legendFormat": "Avg Usage Time",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "s",
"custom": {}
}
}
},
{
"id": 10,
"title": "Active Connections Timeline",
"type": "timeseries",
"gridPos": {"x": 12, "y": 20, "w": 12, "h": 8},
"targets": [
{
"expr": "hikaricp_connections_active{application=\"todo\"}",
"legendFormat": "Active Connections",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "short",
"custom": {}
} }
},
{
"id": 3,
"title": "Total Connections",
"type": "stat",
"gridPos": {"x": 12, "y": 0, "w": 6, "h": 4},
"targets": [
{
"expr": "hikaricp_connections{application=\"todo\"}",
"legendFormat": "Total"
}
],
"options": {
"colorMode": "value",
"graphMode": "area"
}
},
{
"id": 4,
"title": "Pending Threads",
"type": "stat",
"gridPos": {"x": 18, "y": 0, "w": 6, "h": 4},
"targets": [
{
"expr": "hikaricp_connections_pending{application=\"todo\"}",
"legendFormat": "Pending"
}
],
"options": {
"colorMode": "value",
"graphMode": "area"
}
},
{
"id": 5,
"title": "Connection Pool Utilization (%)",
"type": "graph",
"gridPos": {"x": 0, "y": 4, "w": 12, "h": 8},
"targets": [
{
"expr": "(hikaricp_connections_active{application=\"todo\"} / hikaricp_connections_max{application=\"todo\"}) * 100",
"legendFormat": "Active %"
},
{
"expr": "(hikaricp_connections{application=\"todo\"} / hikaricp_connections_max{application=\"todo\"}) * 100",
"legendFormat": "Total %"
}
],
"yaxes": [
{"format": "percent", "label": "Utilization", "min": 0, "max": 100},
{"format": "short"}
]
},
{
"id": 6,
"title": "Connection Acquire Time",
"type": "graph",
"gridPos": {"x": 12, "y": 4, "w": 12, "h": 8},
"targets": [
{
"expr": "histogram_quantile(0.5, rate(hikaricp_connections_acquire_seconds_bucket{application=\"todo\"}[1m]))",
"legendFormat": "p50"
},
{
"expr": "histogram_quantile(0.95, rate(hikaricp_connections_acquire_seconds_bucket{application=\"todo\"}[1m]))",
"legendFormat": "p95"
},
{
"expr": "histogram_quantile(0.99, rate(hikaricp_connections_acquire_seconds_bucket{application=\"todo\"}[1m]))",
"legendFormat": "p99"
}
],
"yaxes": [
{"format": "s", "label": "Time"},
{"format": "short"}
]
},
{
"id": 7,
"title": "Connection Timeout Count",
"type": "graph",
"gridPos": {"x": 0, "y": 12, "w": 12, "h": 8},
"targets": [
{
"expr": "rate(hikaricp_connections_timeout_total{application=\"todo\"}[1m])",
"legendFormat": "Timeouts/sec"
}
],
"yaxes": [
{"format": "short"},
{"format": "short"}
]
},
{
"id": 8,
"title": "Connection Creation Time",
"type": "graph",
"gridPos": {"x": 12, "y": 12, "w": 12, "h": 8},
"targets": [
{
"expr": "rate(hikaricp_connections_creation_seconds_sum{application=\"todo\"}[1m]) / rate(hikaricp_connections_creation_seconds_count{application=\"todo\"}[1m])",
"legendFormat": "Avg Creation Time"
}
],
"yaxes": [
{"format": "s"},
{"format": "short"}
]
},
{
"id": 9,
"title": "Connection Usage Time",
"type": "graph",
"gridPos": {"x": 0, "y": 20, "w": 12, "h": 8},
"targets": [
{
"expr": "rate(hikaricp_connections_usage_seconds_sum{application=\"todo\"}[1m]) / rate(hikaricp_connections_usage_seconds_count{application=\"todo\"}[1m])",
"legendFormat": "Avg Usage Time"
}
],
"yaxes": [
{"format": "s"},
{"format": "short"}
]
},
{
"id": 10,
"title": "JDBC Queries Rate",
"type": "graph",
"gridPos": {"x": 12, "y": 20, "w": 12, "h": 8},
"targets": [
{
"expr": "rate(jdbc_connections_active{application=\"todo\"}[1m])",
"legendFormat": "Active JDBC Connections"
}
],
"yaxes": [
{"format": "short"},
{"format": "short"}
]
} }
],
"refresh": "5s",
"time": {
"from": "now-15m",
"to": "now"
} }
}, ],
"overwrite": true "time": {
"from": "now-15m",
"to": "now"
}
} }