Code Monkey home page Code Monkey logo

nexus3-component-counter's Introduction

Nexus Repository Component Counter

Objective

This script asynchronously fetches component counts from Nexus Repository Manager and outputs the data to a JSON file. It is designed to handle multiple repositories concurrently, adjusting to network conditions and server response times. This utility is especially useful for administrators and teams who manage large Nexus repository instances and require regular reports on repository contents.

Usage

Requirements

  • Python 3.7+
  • aiohttp asyncio argparse libraries
  • Nexus Repository Manager with REST API access
  • NEXUS_USERNAME and NEXUS_PASSWORD environment variables for authentication

Installation

Install the required Python library using pip:

pip install aiohttp asyncio argparse

Command-Line Arguments

The script supports several command-line arguments to customize its operation:

--url (required): The base URL for the Nexus API.

--type (optional): Filters repositories by type (e.g., hosted, proxy).

--format (optional): Filters repositories by format (e.g., maven, npm).

--concurrency (optional): Specifies the maximum number of concurrent requests (default is 10).

--output-dir (optional): Specifies the directory to store the output JSON files (default is the current directory).

ALL flags can be used together.

Important note

The speed of this script depends on the performance of your Nexus instance and its total component count. During testing it processed roughly 60.0000 components within 8~10 minutes against a Nexus instance with MINIMUM load.

Examples

Basic Usage:

Run the script with the minimum required parameters:

export NEXUS_USERNAME=<yourUserName> && export NEXUS_PASSWORD='<yourPassword>'
python nexus_component_counter.py --url http://localhost:8081/service/rest/v1

Filtered Usage:

Run the script for only maven format repositories of ALL types:

python nexus_component_counter.py --url http://localhost:8081/service/rest/v1 --format maven

Run the script for only maven format repositories with type 'hosted':

python nexus_component_counter.py --url http://localhost:8081/service/rest/v1 --format maven --type hosted

Concurrent Usage:

Run the script with a higher level of concurrency to handle more repositories simultaneously:

python nexus_component_counter.py --url http://localhost:8081/service/rest/v1 --concurrency 20

Specified Output Directory:

Run the script and specify an output directory for the results:

python nexus_component_counter.py --url http://localhost:8081/service/rest/v1 --output-dir /path/to/output

Output / Result

The script generates a JSON file named based on the type and format parameters provided. If no type or format is specified, it defaults to “all”. For example: hosted_maven_components.json for hosted Maven repositories. all_all_components.json if no type or format is specified.

The JSON file will contain a dictionary -sorted by count number- where each key is a repository name and the value specifying the type, format, and count of components within that repository:

{
 "repo1": {
   "type": "hosted",
   "format": "maven",
   "count": 1200
 },
 "repo2": {
   "type": "proxy",
   "format": "npm",
   "count": 3000
 }
}

During execution it will report back to the console after each API call:

Total repositories fetched: 16
Starting processing repository: repo1-helm-charts
Found 1 components so far in repo1-helm-charts  (Completed repos: 0/16)
Completed 1/16: repo1-helm-charts
Found 7 components so far in repo2-helm-charts  (Completed repos: 1/16)
Completed 2/16: repo2-helm-charts
Found 7 components so far in repo3-helm-charts  (Completed repos: 2/16)
Completed 3/16: repo3-helm-charts
Found 20 components so far in repo4-helm-charts  (Completed repos: 3/16)
Found 30 components so far in repo4-helm-charts  (Completed repos: 3/16)
(...)
Completed 16/16: repo16-helm-charts

This file provides a clear and organized view of component counts across your Nexus repositories, useful for auditing, monitoring, and reporting purposes.

nexus3-component-counter's People

Contributors

brianveltman avatar

Stargazers

 avatar

Watchers

 avatar

nexus3-component-counter's Issues

Ability to continue where it left off

Since we're writing the processed repositories to file after its completion, we might be able to load that information to decide if and from which point we can continue generating the report.

Report which repositories are bigger than <given> amount of components

Currently the script will iterate over all repositories and count the number of components.
This can be a lengthy process on big instances. At some point it doesn't really matter anymore if there are 5.000 components or 10.000, or even 100.000.

I think it will greatly improve the process if you can give a limit to the script and it will stop executing the count for repositories that exceeds the given limit. Meaning these repositories have more than the given amount of components. It can be a different run mode, count vs identify kind of thing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.