feat: show disk usage of mover source with configurable warning threshold
GET /api/storage/disk-usage returns source path stats (total/used/free bytes, %).
Polls every 30s while Storage page is open.
Backend:
- migration 0009: adds mover_warning_threshold (1-99, default 80) to storage_config
- StatPath moved to internal/storage package for testability
- handleStorageDiskUsage returns {source: PathStat}
Frontend:
- DiskUsageBar component in Mergerfs Mover card: usage bar with color
green < threshold, amber >= threshold, red >= 95%
- Warning message when threshold reached or exceeded
- New input in config form: Umbral de aviso (%)
- storageDiskUsage() API method
Tests: StatPath unit tests (empty/nonexistent/valid paths)
Version: 0.7.3
This commit is contained in:
@@ -45,6 +45,10 @@ func (s *Server) handleStorageUpdateConfig(w http.ResponseWriter, r *http.Reques
|
||||
writeError(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if cfg.MoverWarningThreshold < 1 || cfg.MoverWarningThreshold > 99 {
|
||||
writeError(w, http.StatusBadRequest, "mover_warning_threshold must be between 1 and 99")
|
||||
return
|
||||
}
|
||||
flags, err := storage.ParseExtraRsyncFlags(cfg.MoverRsyncOptions)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadRequest, err.Error())
|
||||
@@ -214,6 +218,15 @@ func setSSEHeaders(w http.ResponseWriter) {
|
||||
w.Header().Set("X-Accel-Buffering", "no")
|
||||
}
|
||||
|
||||
func (s *Server) handleStorageDiskUsage(w http.ResponseWriter, r *http.Request) {
|
||||
cfg, err := s.DB.GetStorageConfig()
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"source": storage.StatPath(cfg.MoverSource)})
|
||||
}
|
||||
|
||||
func sseEmit(w io.Writer, event string, data any) {
|
||||
body, _ := json.Marshal(data)
|
||||
fmt.Fprintf(w, "event: %s\ndata: %s\n\n", event, string(body))
|
||||
|
||||
@@ -88,8 +88,9 @@ func NewRouter(s *Server) chi.Router {
|
||||
})
|
||||
|
||||
protected.Route("/storage", func(storageRouter chi.Router) {
|
||||
storageRouter.Get("/capabilities", s.handleStorageCapabilities)
|
||||
storageRouter.Get("/config", s.handleStorageGetConfig)
|
||||
storageRouter.Get("/capabilities", s.handleStorageCapabilities)
|
||||
storageRouter.Get("/disk-usage", s.handleStorageDiskUsage)
|
||||
storageRouter.Get("/config", s.handleStorageGetConfig)
|
||||
storageRouter.Put("/config", s.handleStorageUpdateConfig)
|
||||
storageRouter.Route("/jobs", func(j chi.Router) {
|
||||
j.Get("/", s.handleStorageListJobs)
|
||||
|
||||
Reference in New Issue
Block a user