Investigating Blobstore Space Usage

When multiple repositories are configured to use the same blobstore, you may want to have some insight into how the space is being used.  

This article provides you with a couple of different ways find out where blobstore space is being consumed.

1. Using a groovy script from the command line.

The groovy script below will find the largest blobs inside a blobstore directory. Execute the script from the command line making sure dir_name points to the correct path for your sonatype-work directory. The output contains a list of blobs larger than 100M sorted by size. 

long min_size = 100000000
String dir_name = '/opt/Nexus/sonatype-work/nexus3'

def ant = new AntBuilder()
def scanner = ant.fileScanner {
  fileset(dir: dir_name) {
    include(name: '**/blobs/**/*.properties')
    exclude(name: '**/metadata.properties')
    exclude(name: '**/*metrics.properties')
    exclude(name: '**/tmp')
  }
}
def results = [:].withDefault { 0 }
scanner.each { File file ->
  def properties = new Properties()
  file.withInputStream { is ->
    properties.load(is)
  }
  long prop_size = properties.size as long;
  if (prop_size > min_size) {
    results.put(properties['@BlobStore.blob-name'], prop_size)
  }
}
def sorted = results.sort { a, b -> b.value <=> a.value }

sorted.each{ k, v -> println "${k}:${v}" }

2. Running a repository manager task.

The groovy script below can be executed as a task in Nexus repository manager. In the Administration pane select System > Tasks. Create a new Execute Script task. Set the Language to groovy and task frequency to Manual, using the Source below. When you execute the task the output logged to the nexus.log will list assets larger than min_size in descending size order for each repository.

import org.sonatype.nexus.repository.storage.StorageFacet
import org.sonatype.nexus.repository.Repository
import org.sonatype.nexus.repository.storage.Asset
import groovy.json.JsonOutput

long min_size = 100000000

repository.repositoryManager.browse().each { Repository repo ->
    StorageFacet storageFacet = repo.facet(StorageFacet)
    def tx = storageFacet.txSupplier().get()

    tx.begin()
    
    def results = [:].withDefault { 0 }
    
    tx.browseAssets(tx.findBucket(repo)).each { Asset asset ->
      if (asset.size() > min_size) {
        results.put(asset.name(),asset.size())
      }
    }
    
    tx.close()
    def sorted = results.sort { a, b -> b.value <=> a.value }
    log.info(JsonOutput.prettyPrint(JsonOutput.toJson(sorted)))
}

Have more questions? Submit a request

0 Comments

Article is closed for comments.
Powered by Zendesk