30

How can I get a size of specific repository in Nexus 3?

For example, Artifactory shows the repository "size on disk" via UI.

Does Nexus have something similar? If not - how can I get this information by script?

Ivan
  • 3,084
  • 4
  • 21
  • 22

3 Answers3

37

You can use admin task with groovy script nx-blob-repo-space-report.groovy from https://issues.sonatype.org/browse/NEXUS-14837 - for me turned out too slow

Or you can get it from database:

  1. login with user-owner nexus installation on nexus server (e.g. nexus)

  2. go to application directory (e.g. /opt/nexus):

    $ cd /opt/nexus

  3. run java orient console:

    $ java -jar ./lib/support/nexus-orient-console.jar

  4. connect to local database (e.g. /opt/sonatype-work/nexus3/db/component):

    > CONNECT PLOCAL:/opt/sonatype-work/nexus3/db/component admin admin

  5. find out repository row id in @RID column by repository_name value:

    > select * from bucket limit 50;

  6. get sum for all assets with repo row id found in the previous step:

    > select sum(size) from asset where bucket = #15:9;

result should be like (apparently in bytes):
+----+------------+ |# |sum | +----+------------+ |0 |224981921470| +----+------------+

nexus database connection steps took from https://support.sonatype.com/hc/en-us/articles/115002930827-Accessing-the-OrientDB-Console

another useful queries

summary size by repository name (instead 5 and 6 steps):

> select sum(size) from asset where bucket.repository_name = 'releases';

top 10 repositories by size:

> select bucket.repository_name as repository,sum(size) as bytes from asset group by bucket.repository_name order by bytes desc limit 10;
tigl
  • 556
  • 5
  • 5
  • 5
    If you are using the Docker image (sonatype/nexus3), after you connect to the running Docker container (`sudo docker exec -it /bin/sh`) then the jar executable is: `java -jar /opt/sonatype/nexus/lib/support/nexus-orient-console.jar` and then the connection command after this connects is `> CONNECT PLOCAL:/nexus-data/db/component admin admin` – phillipuniverse Jan 31 '19 at 21:15
  • I don't have the nexus-orient-console.jar on my server, I'm using version OSS 3.15.2-01, is that a feature for the Enterprise version? – 0xAA55 Mar 29 '19 at 18:51
  • it should be there even on OSS version (I got 3.15.1 and also had it on previous versions too). – Markus May 03 '19 at 10:10
  • How can we check further sizes under releases repository? i mean size of each release? – ImranRazaKhan Dec 15 '21 at 07:01
  • Don't skip point 1 - it renders nexus unable to access the database! To correct this mishap run (assuming nexus as your service user) `chown -R nexus:nexus /opt/sonatype-work/nexus3/db` – itshorty Jan 20 '22 at 16:35
9

Assign each repository to its own Blob Store.

enter image description here

Thiago Figueiro
  • 410
  • 5
  • 15
  • 5
    This is a very good tip for new repositories (and I upvote it), but it doesn't help with existing repos. – Ivan Jun 25 '18 at 13:37
0

You can refer below GitHub project. The script can be help to clear storage space on Nexus repository by analyzing the stats generated by the script. The script feature prompt-based user input, Search/Filter the results, Generates CSV output file and Print the output on console in a tabular format.

Nexus Space Utilization - GitHub


You may also refer below post on the same.

Nexus Space Utilization - Post