aboutsummaryrefslogtreecommitdiff
path: root/weed/server/master_server_handlers_admin.go
diff options
context:
space:
mode:
authorRiccardo Bertossa <33728857+rikigigi@users.noreply.github.com>2024-08-19 16:44:45 +0200
committerGitHub <noreply@github.com>2024-08-19 07:44:45 -0700
commit6fe86395046cbf48690380746c057f56555b5df8 (patch)
tree0fc9172ea8ec9ec9f54def69a9b7ec9a38c86ac1 /weed/server/master_server_handlers_admin.go
parente50d85c0f3697caf0ff9aca6662d59b4327a8424 (diff)
downloadseaweedfs-6fe86395046cbf48690380746c057f56555b5df8.tar.xz
seaweedfs-6fe86395046cbf48690380746c057f56555b5df8.zip
add http endpoint to get the size of a collection (#5910)
Diffstat (limited to 'weed/server/master_server_handlers_admin.go')
-rw-r--r--weed/server/master_server_handlers_admin.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/weed/server/master_server_handlers_admin.go b/weed/server/master_server_handlers_admin.go
index 7479b5535..e003d7d9f 100644
--- a/weed/server/master_server_handlers_admin.go
+++ b/weed/server/master_server_handlers_admin.go
@@ -178,3 +178,58 @@ func (ms *MasterServer) getVolumeGrowOption(r *http.Request) (*topology.VolumeGr
}
return volumeGrowOption, nil
}
+
+func (ms *MasterServer) collectionInfoHandler(w http.ResponseWriter, r *http.Request) {
+ //get collection from request
+ collectionName := r.FormValue("collection")
+ if collectionName == "" {
+ writeJsonError(w, r, http.StatusBadRequest, fmt.Errorf("collection is required"))
+ return
+ }
+ //output details of the volumes?
+ detail := r.FormValue("detail") == "true"
+ //collect collection info
+ collection, ok := ms.Topo.FindCollection(collectionName)
+ if !ok {
+ writeJsonError(w, r, http.StatusBadRequest, fmt.Errorf("collection %s does not exist", collectionName))
+ return
+ }
+
+ volumeLayouts := collection.GetAllVolumeLayouts()
+
+ if detail {
+ //prepare the json response
+ all_stats := make([]map[string]interface{}, len(volumeLayouts))
+ for i, volumeLayout := range volumeLayouts {
+ volumeLayoutStats := volumeLayout.Stats()
+ m := make(map[string]interface{})
+ m["Version"] = util.Version()
+ m["Collection"] = collectionName
+ m["TotalSize"] = volumeLayoutStats.TotalSize
+ m["FileCount"] = volumeLayoutStats.FileCount
+ m["UsedSize"] = volumeLayoutStats.UsedSize
+ all_stats[i] = m
+ }
+ //write it
+ writeJsonQuiet(w, r, http.StatusOK, all_stats)
+ } else {
+ //prepare the json response
+ collectionStats := map[string]interface{}{
+ "Version": util.Version(),
+ "Collection": collectionName,
+ "TotalSize": uint64(0),
+ "FileCount": uint64(0),
+ "UsedSize": uint64(0),
+ "VolumeCount": uint64(0),
+ }
+ for _, volumeLayout := range volumeLayouts {
+ volumeLayoutStats := volumeLayout.Stats()
+ collectionStats["TotalSize"] = collectionStats["TotalSize"].(uint64) + volumeLayoutStats.TotalSize
+ collectionStats["FileCount"] = collectionStats["FileCount"].(uint64) + volumeLayoutStats.FileCount
+ collectionStats["UsedSize"] = collectionStats["UsedSize"].(uint64) + volumeLayoutStats.UsedSize
+ collectionStats["VolumeCount"] = collectionStats["VolumeCount"].(uint64) + 1
+ }
+ //write it
+ writeJsonQuiet(w, r, http.StatusOK, collectionStats)
+ }
+}