mirror of
https://github.com/DullJZ/s3-balance.git
synced 2026-09-07 08:56:38 +08:00
feat: Add object count tracking and display for S3 buckets.
This commit is contained in:
@@ -44,6 +44,7 @@ type BucketResponse struct {
|
|||||||
UsedSize int64 `json:"used_size"`
|
UsedSize int64 `json:"used_size"`
|
||||||
AvailableSize int64 `json:"available_size"`
|
AvailableSize int64 `json:"available_size"`
|
||||||
UsagePercent float64 `json:"usage_percent"`
|
UsagePercent float64 `json:"usage_percent"`
|
||||||
|
ObjectCount int64 `json:"object_count"`
|
||||||
Weight int `json:"weight"`
|
Weight int `json:"weight"`
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
Available bool `json:"available"`
|
Available bool `json:"available"`
|
||||||
@@ -59,18 +60,18 @@ type BucketResponse struct {
|
|||||||
|
|
||||||
// BucketsListResponse 存储桶列表响应结构
|
// BucketsListResponse 存储桶列表响应结构
|
||||||
type BucketsListResponse struct {
|
type BucketsListResponse struct {
|
||||||
Total int `json:"total"`
|
Total int `json:"total"`
|
||||||
Buckets []BucketResponse `json:"buckets"`
|
Buckets []BucketResponse `json:"buckets"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// HealthResponse 健康状态响应结构
|
// HealthResponse 健康状态响应结构
|
||||||
type HealthResponse struct {
|
type HealthResponse struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Timestamp time.Time `json:"timestamp"`
|
Timestamp time.Time `json:"timestamp"`
|
||||||
LoadBalancer string `json:"load_balancer_strategy"`
|
LoadBalancer string `json:"load_balancer_strategy"`
|
||||||
TotalBuckets int `json:"total_buckets"`
|
TotalBuckets int `json:"total_buckets"`
|
||||||
AvailableBuckets int `json:"available_buckets"`
|
AvailableBuckets int `json:"available_buckets"`
|
||||||
Database string `json:"database_type"`
|
Database string `json:"database_type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterRoutes 注册管理API路由
|
// RegisterRoutes 注册管理API路由
|
||||||
@@ -205,6 +206,7 @@ func (h *AdminHandler) convertBucketInfo(b *bucket.BucketInfo) BucketResponse {
|
|||||||
MaxSize: b.Config.MaxSize,
|
MaxSize: b.Config.MaxSize,
|
||||||
MaxSizeBytes: b.Config.MaxSizeBytes,
|
MaxSizeBytes: b.Config.MaxSizeBytes,
|
||||||
UsedSize: b.UsedSize,
|
UsedSize: b.UsedSize,
|
||||||
|
ObjectCount: b.GetObjectCount(),
|
||||||
Weight: b.Config.Weight,
|
Weight: b.Config.Weight,
|
||||||
Enabled: b.Config.Enabled,
|
Enabled: b.Config.Enabled,
|
||||||
Available: b.Available,
|
Available: b.Available,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ type BucketInfo struct {
|
|||||||
Config config.BucketConfig
|
Config config.BucketConfig
|
||||||
Client *s3.Client
|
Client *s3.Client
|
||||||
UsedSize int64 // 已使用容量(字节)
|
UsedSize int64 // 已使用容量(字节)
|
||||||
|
ObjectCount int64 // 对象数量
|
||||||
Available bool // 是否可用(由health监控更新)
|
Available bool // 是否可用(由health监控更新)
|
||||||
LastChecked time.Time // 最后检查时间(由health监控更新)
|
LastChecked time.Time // 最后检查时间(由health监控更新)
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
@@ -320,6 +321,13 @@ func (b *BucketInfo) GetUsedSize() int64 {
|
|||||||
return b.UsedSize
|
return b.UsedSize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetObjectCount 获取对象数量
|
||||||
|
func (b *BucketInfo) GetObjectCount() int64 {
|
||||||
|
b.mu.RLock()
|
||||||
|
defer b.mu.RUnlock()
|
||||||
|
return b.ObjectCount
|
||||||
|
}
|
||||||
|
|
||||||
// UpdateUsedSize 更新已使用容量
|
// UpdateUsedSize 更新已使用容量
|
||||||
func (b *BucketInfo) UpdateUsedSize(delta int64) {
|
func (b *BucketInfo) UpdateUsedSize(delta int64) {
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ func (r *MetricsReporter) ReportStats(stats *health.Stats) {
|
|||||||
if exists {
|
if exists {
|
||||||
bucket.mu.Lock()
|
bucket.mu.Lock()
|
||||||
bucket.UsedSize = stats.UsedSize
|
bucket.UsedSize = stats.UsedSize
|
||||||
|
bucket.ObjectCount = stats.ObjectCount
|
||||||
bucket.mu.Unlock()
|
bucket.mu.Unlock()
|
||||||
|
|
||||||
// 更新 Prometheus 指标
|
// 更新 Prometheus 指标
|
||||||
|
|||||||
Reference in New Issue
Block a user