Storage size

Hi i am trying to find Project Storage size in gitlab using rest api can you please give me solution

Hi,

As per the API here: Projects API | GitLab

Look at the results, in particular the statistics part, here is an example from the doc link I provided:

  "statistics": {
    "commit_count": 37,
    "storage_size": 1038090,
    "repository_size": 1038090,
    "wiki_size" : 0,
    "lfs_objects_size": 0,
    "job_artifacts_size": 0,
    "pipeline_artifacts_size": 0,
    "packages_size": 0,
    "snippets_size": 0,
    "uploads_size": 0
  },

on the results returned for a single project you can use something like jq to filter the json results. A working example:

curl -s --header "PRIVATE-TOKEN: my-token-here" https://gitlab.example.com/api/v4/projects/5?statistics=true | jq .statistics
{
  "commit_count": 4730,
  "storage_size": 253667377,
  "repository_size": 172553666,
  "wiki_size": 1405091,
  "lfs_objects_size": 0,
  "job_artifacts_size": 0,
  "pipeline_artifacts_size": 0,
  "packages_size": 0,
  "snippets_size": 157286,
  "uploads_size": 79551334
}
2 Likes

ProjectStat = gl.projects.get(id=project.id,statistics=True) #project statistics
size=project.statistics.storage_size
print(size)

can you please check on thehow to retrive the size

I did in my previous post, you can clearly see storage_size in the results. If you want to filter more than just statistics, you can do that with jq like in my example. You will see I used jq .statistics at the end of the line with a pipe in between the curl and the jq command. To get storage size you just use jq .statistics.storage_size.

If you are doing it in python or something else, then you use the appropriate methods using simplejson or whatever.

1 Like