working on system management
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -44,7 +45,8 @@ type ZFSPool struct {
|
||||
AutoExpand bool `json:"auto_expand"`
|
||||
ScrubInterval int `json:"scrub_interval"` // days
|
||||
IsActive bool `json:"is_active"`
|
||||
HealthStatus string `json:"health_status"` // online, degraded, faulted, offline
|
||||
HealthStatus string `json:"health_status"` // online, degraded, faulted, offline
|
||||
CompressRatio float64 `json:"compress_ratio"` // compression ratio (e.g., 1.45x)
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
CreatedBy string `json:"created_by"`
|
||||
@@ -359,6 +361,26 @@ func (s *ZFSService) getSpareDisks(ctx context.Context, poolName string) ([]stri
|
||||
return spareDisks, nil
|
||||
}
|
||||
|
||||
// getCompressRatio gets the compression ratio from ZFS
|
||||
func (s *ZFSService) getCompressRatio(ctx context.Context, poolName string) (float64, error) {
|
||||
cmd := exec.CommandContext(ctx, "zfs", "get", "-H", "-o", "value", "compressratio", poolName)
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return 1.0, err
|
||||
}
|
||||
|
||||
ratioStr := strings.TrimSpace(string(output))
|
||||
// Remove 'x' suffix if present (e.g., "1.45x" -> "1.45")
|
||||
ratioStr = strings.TrimSuffix(ratioStr, "x")
|
||||
|
||||
ratio, err := strconv.ParseFloat(ratioStr, 64)
|
||||
if err != nil {
|
||||
return 1.0, err
|
||||
}
|
||||
|
||||
return ratio, nil
|
||||
}
|
||||
|
||||
// ListPools lists all ZFS pools
|
||||
func (s *ZFSService) ListPools(ctx context.Context) ([]*ZFSPool, error) {
|
||||
query := `
|
||||
@@ -407,8 +429,17 @@ func (s *ZFSService) ListPools(ctx context.Context) ([]*ZFSPool, error) {
|
||||
pool.SpareDisks = spareDisks
|
||||
}
|
||||
|
||||
// Get compressratio from ZFS system
|
||||
compressRatio, err := s.getCompressRatio(ctx, pool.Name)
|
||||
if err != nil {
|
||||
s.logger.Warn("Failed to get compressratio", "pool", pool.Name, "error", err)
|
||||
pool.CompressRatio = 1.0 // Default to 1.0 if can't get ratio
|
||||
} else {
|
||||
pool.CompressRatio = compressRatio
|
||||
}
|
||||
|
||||
pools = append(pools, &pool)
|
||||
s.logger.Debug("Added pool to list", "pool_id", pool.ID, "name", pool.Name)
|
||||
s.logger.Debug("Added pool to list", "pool_id", pool.ID, "name", pool.Name, "compressratio", pool.CompressRatio)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user