How to retrieve repository size through REST API

Hi Team

I am trying to retrieve individual disk size occupied by gitlab repository in order to create a grafana dashboard which highlights top 10-20(customisable) repositories which are occupying more space.

Hi @SunnyAgrawal,

You can use the Projects API with ?statistics=true variable set at the end of your statement.

If using curl for API requests, it would look like:

all projects:

curl --header "Private-Token: <your_token>" "https://<your_instance>/api/v4/projects?statistics=true

single project:

curl --header "Private-Token: <your_token>" "https://<your_instance>/api/v4/projects/<project_id>?statistics=true

The relevant output will be in the following format:

    "statistics": {
      "commit_count": 5914,
      "storage_size": 1727206,
      "repository_size": 0,
      "wiki_size": 52428,
      "lfs_objects_size": 0,
      "job_artifacts_size": 1674778
    },

Thanks for the quick reply. but the size is in KB or Bytes, how should i convert it to MB ?

The size is listed in Bytes.
To convert to KB, divide by 1,000.
To convert to MB, divide by 1,000,000.

For example, for a storage storage_size of 1234567 bytes:
1234567 / 1000 = 1234.567 Kb
1234567 / 1000000 = 1.234567 Mb

i can use this api get repository_size but when i push file to the repository then i request this api again, i also get old repository_size,the size unchange , so how can I get the real-time statistical results,thanks

need help using api

@Namskar don’t double-post, since you already asked this question I posted the answer: Storage size

Also, gitlab-greg posted the API command needed, which I also used in my example. Had you attempted that, you would already have the answer to your question.

@Namskar stop double-posting. I am going to flag your post for moderation now.