From 0630cb09c7ab50aaf8e164e319be92b5048df7a0 Mon Sep 17 00:00:00 2001 From: DullJZ <79080562+DullJZ@users.noreply.github.com> Date: Tue, 21 Oct 2025 19:59:28 +0800 Subject: [PATCH] grafana display --- .../dashboards/s3-balance-dashboard.json | 63 ++++++++++++++++++- internal/api/operation_tracker.go | 4 ++ internal/metrics/service.go | 11 +++- 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/deploy/monitoring/grafana/dashboards/s3-balance-dashboard.json b/deploy/monitoring/grafana/dashboards/s3-balance-dashboard.json index c23c237..c8a1ec4 100644 --- a/deploy/monitoring/grafana/dashboards/s3-balance-dashboard.json +++ b/deploy/monitoring/grafana/dashboards/s3-balance-dashboard.json @@ -99,6 +99,67 @@ "title": "QPS (操作/秒)", "type": "timeseries" }, + { + "datasource": "Prometheus", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "custom": { + "align": "auto", + "displayMode": "auto" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 0 + }, + "id": 12, + "options": { + "footer": { + "fields": "", + "reducer": [ + "sum" + ], + "show": false + }, + "showHeader": true + }, + "targets": [ + { + "expr": "sum by (bucket, category)(increase(s3_balance_backend_operations_total[$__range]))", + "instant": true, + "legendFormat": "", + "refId": "A" + } + ], + "timeFrom": "now/M", + "title": "后端操作次数 (本自然月)", + "transformations": [ + { + "id": "labelsToFields", + "options": { + "valueLabel": "操作次数" + } + } + ], + "type": "table" + }, { "datasource": "Prometheus", "fieldConfig": { @@ -334,5 +395,5 @@ "timezone": "", "title": "S3 Balance 监控面板", "uid": "s3-balance-monitoring", - "version": 1 + "version": 2 } diff --git a/internal/api/operation_tracker.go b/internal/api/operation_tracker.go index d4b17c1..e894469 100644 --- a/internal/api/operation_tracker.go +++ b/internal/api/operation_tracker.go @@ -11,6 +11,10 @@ func (h *S3Handler) recordBackendOperation(b *bucket.BucketInfo, category bucket if b == nil { return } + + if h.metrics != nil { + h.metrics.RecordBackendOperation(b.Config.Name, string(category)) + } if disabled := b.RecordOperation(category); disabled { log.Printf("Bucket %s disabled after exceeding %s-type operation limit", b.Config.Name, category) } diff --git a/internal/metrics/service.go b/internal/metrics/service.go index e799b44..e7febb0 100644 --- a/internal/metrics/service.go +++ b/internal/metrics/service.go @@ -36,6 +36,11 @@ var ( Name: "s3_balance_balancer_decisions_total", Help: "Total number of load balancing decisions", }, []string{"strategy", "bucket"}) + + backendOperationsTotal = promauto.NewCounterVec(prometheus.CounterOpts{ + Name: "s3_balance_backend_operations_total", + Help: "Total number of backend bucket operations by category", + }, []string{"bucket", "category"}) ) type Metrics struct{} @@ -67,4 +72,8 @@ func (m *Metrics) RecordS3OperationDuration(operation, bucket string, duration f func (m *Metrics) RecordBalancerDecision(strategy, bucket string) { balancerDecisions.WithLabelValues(strategy, bucket).Inc() -} \ No newline at end of file +} + +func (m *Metrics) RecordBackendOperation(bucket, category string) { + backendOperationsTotal.WithLabelValues(bucket, category).Inc() +}