mirror of
https://github.com/DullJZ/s3-balance.git
synced 2026-09-05 07:46:42 +08:00
metrics
This commit is contained in:
@@ -43,6 +43,18 @@ func (h *S3Handler) handleBucketOperations(w http.ResponseWriter, r *http.Reques
|
||||
vars := mux.Vars(r)
|
||||
bucketName := vars["bucket"]
|
||||
|
||||
// 记录操作指标
|
||||
start := time.Now()
|
||||
method := r.Method
|
||||
var status = "success"
|
||||
defer func() {
|
||||
if h.metrics != nil {
|
||||
duration := time.Since(start).Seconds()
|
||||
h.metrics.RecordS3Operation(method, bucketName, status)
|
||||
h.metrics.RecordS3OperationDuration(method, bucketName, duration)
|
||||
}
|
||||
}()
|
||||
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
h.handleListObjects(w, r, bucketName)
|
||||
|
||||
@@ -18,6 +18,18 @@ func (h *S3Handler) handleObjectOperations(w http.ResponseWriter, r *http.Reques
|
||||
bucketName := vars["bucket"]
|
||||
key := vars["key"]
|
||||
|
||||
// 记录操作指标
|
||||
start := time.Now()
|
||||
method := r.Method
|
||||
var status = "success"
|
||||
defer func() {
|
||||
if h.metrics != nil {
|
||||
duration := time.Since(start).Seconds()
|
||||
h.metrics.RecordS3Operation(method, bucketName, status)
|
||||
h.metrics.RecordS3OperationDuration(method, bucketName, duration)
|
||||
}
|
||||
}()
|
||||
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
h.handleGetObject(w, r, bucketName, key)
|
||||
|
||||
@@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"github.com/DullJZ/s3-balance/internal/balancer"
|
||||
"github.com/DullJZ/s3-balance/internal/bucket"
|
||||
"github.com/DullJZ/s3-balance/internal/metrics"
|
||||
"github.com/DullJZ/s3-balance/internal/storage"
|
||||
"github.com/DullJZ/s3-balance/pkg/presigner"
|
||||
"github.com/gorilla/mux"
|
||||
@@ -16,6 +17,7 @@ type S3Handler struct {
|
||||
storage *storage.Service
|
||||
accessKey string
|
||||
secretKey string
|
||||
metrics *metrics.Metrics
|
||||
}
|
||||
|
||||
// NewS3Handler 创建新的S3兼容API处理器
|
||||
@@ -26,6 +28,7 @@ func NewS3Handler(
|
||||
storage *storage.Service,
|
||||
accessKey string,
|
||||
secretKey string,
|
||||
metrics *metrics.Metrics,
|
||||
) *S3Handler {
|
||||
return &S3Handler{
|
||||
bucketManager: bucketManager,
|
||||
@@ -34,6 +37,7 @@ func NewS3Handler(
|
||||
storage: storage,
|
||||
accessKey: accessKey,
|
||||
secretKey: secretKey,
|
||||
metrics: metrics,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user