Skip to main content

Usage Metrics for Nexus Repository Manager 2 (NXRM2)

Use the following procedures and scripts to collect usage metrics from Nexus Repository Manager 2 (NXRM2).

Count components (NXRM2)

To estimate the number of unique components stored in NXRM2, query the storage directory on the server.

  1. Go to the storage directory on the NXRM2 server:

    cd [nexus2-folder]/sonatype-work/nexus/storage
  2. Generate a list of all stored files, excluding meta directories and hidden files:

    find . -type f ! -path "*/.meta/*" ! -path "*/.nexus/*" ! -name ".*" > components.txt
  3. Share the components.txt file with your Sonatype contact for analysis.

Sonatype uses a script for Maven repositories that

  • Excludes metadata and checksum files.

  • Groups files by group, artifact, and version (GAV).

  • Counts unique components instead of individual files.

This aligns with the standard Maven definition of a component and provides a unique component count, not just a file count.

Example:

#!/bin/bash
# List unique Maven components from file list
# Excludes .meta and .nexus directories
# Excludes metadata and hash files per Maven component definition
# Groups files by GAV (Group/Artifact/Version) to count as single component
grep -v "\.meta/" "$1" | \
grep -v "\.nexus/" | \
grep -v "maven-metadata\.xml" | \
grep -v "\.sha1$" | \
grep -v "\.sha256$" | \
grep -v "\.sha-256$" | \
grep -v "\.sha512$" | \
grep -v "\.sha-512$" | \
grep -v "\.md5$" | \
grep -v "\.asc$" | \
sed 's|/[^/]*\.[^./]*$||' | \
sort -u

Customer Action

  • Run the find command to create components.txt.

  • Run the aggregation script with components.txt as input.

  • Provide the resulting unique component count.

Counting HTTP Requests (NXRM2)

You can analyze HTTP requests for NXRM2 by using the request.log files.

This script:

  • Finds all request.log files in a directory tree.

  • Extracts basic HTTP request information.

  • Shows a small sample of requests.

  • Prints the total number of requests per log file.

#!/bin/bash
# Analyze HTTP requests from all request.log files in subdirectories
# Extracts: IP, Method, URL, Status Code

echo "Analyzing HTTP requests from all request.log files..."
echo ""

# Find all request.log files
find . -name "request.log" -type f | while read -r logfile; do
  dirname=$(dirname "$logfile" | sed 's|^\./||' | sed 's|/work/logs||')
  echo "=== $dirname ==="

  # Extract request details (Method, URL, Status Code)
  # Format: IP - - [Date] "METHOD URL HTTP/VERSION" STATUS SIZE TIME
  awk '{
    # Extract method and URL from the quoted request string
    match($0, /"([A-Z]+) ([^ ]+) HTTP/, arr)
    method = arr[1]
    url = arr[2]

    # Extract status code (after the quoted string)
    match($0, /" ([0-9]+)/, status_arr)
    status = status_arr[1]

    # Extract IP address (first field)
    ip = $1

    if (method != "" && url != "" && status != "") {
      print ip, method, url, status
    }
  }' "$logfile" | head -10

  echo ""
  echo "Total requests: $(wc -l < "$logfile" | tr -d ' ')"
  echo ""
done

To calculate requests per month:

  1. Review the date range covered by each request.log file.

  2. Sum the total number of requests for that period.

  3. Normalize the result to a per-month value based on the actual time span represented in the logs.

Customer Action

  • Access the request.log files.

  • Use the script to calculate approximate monthly request volumes for a time span of at least one month.

  • Report the monthly number of requests based on your historical consumption.