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