ARTIFACTORY: How to find the cumulative size and total number of artifacts under a folder in an Artifactory

Ujwal Poovaiah
2023-01-22 11:07

In Artifactory UI, it is possible to get the size & count of artifacts of a folder easily, however, there is no direct REST API to get this information. We can achieve this use case in a couple of ways by combining the REST call file list endpoint as below:

→ Get the total number of artifacts under a folder (Example:hello-world):$ curl -uadmin:password "http://localhost:8081/artifactory/api/storage/docker-local/hello-world?list&deep=1" -s | jq -c '[.files[].uri] | length'
→ Get the cumulative size (in bytes) of artifacts under this path (Example:docker-local/hello-world):  $ curl -uadmin:password "http://localhost:8081/artifactory/api/storage/docker-local/hello-world?list&deep=1" -s | jq -c '[.files[].size] | add' | numfmt --to=iec
→ Also, we can use the below script with AQL queries to print each folder size of a repository and can extend this script according to the use case. 

$ cat

curl -s -k -H 'Content-Type:text/plain' -uadmin:password -XPOST "<JFROG-URL>/artifactory/api/search/aql" -d 'items.find({"type":"folder","repo":"docker-local","depth":1})' | grep "name" | awk '{print $3}' | sed 's/"//g'  | sed 's/,//g' | awk 'length > 1' > folders.txt

for folder in $(cat folders.txt);
echo "Folder size for -->"  $folder

curl -X POST -H "Content-Type:application/json" -uadmin:password "<JFROG-URL>//artifactory/ui/artifactgeneral/artifactsCount?$no_spinner=true" -d '{"name":"'"$folder"'","repositoryPath":"docker-local/'"$folder"'/"}'

printf "\n"