New Relic CLI

repository·main·Indexed 41 days ago

https://github.com/newrelic/newrelic-cli

A command-line tool for consolidating resource management tasks, including entity searching, tagging, and deployment marking. It features a Fleet Control CLI for managing New Relic agents across infrastructure, allowing users to group entities into fleets, create and version agent configurations, manage ring-based deployments, and query managed or unassigned entities.

Tokens
63.6K
Snippets
280
Records
351
Agent score
99%

What's inside New Relic CLI

  1. Overview of Fleet Control CLI

    main

    The Fleet Control CLI is a command-line interface designed for managing New Relic Fleet Control entities. It allows for centralized management of New Relic agents across infrastructure by providing capabilities to:

    • Group entities into fleets for organized management.
    • Create and version agent configurations.
    • Deploy configurations to fleet members.
    • Manage fleet membership using ring-based deployments.
    • Query both managed and unassigned entities.
  2. Overview of New Relic CLI

    main

    The New Relic CLI is an officially supported command line interface for managing New Relic resources. It is part of the New Relic Developer Toolkit.

    Core capabilities include:

    • Entity Search: Search for entities across all New Relic accounts.
    • Entity Tagging: Manage tags across all entities.
    • Deployment Markers: Record APM Application deployments within New Relic.
  3. Manage New Relic One workloads with the workload command

    main

    The newrelic workload command serves as the entry point for interacting with New Relic One workloads. It provides access to subcommands for creating, deleting, duplicating, retrieving, listing, and updating workloads.

    To use these commands, you must provide authentication and account context, typically via the --profile and --accountId flags, or through environment variables.

  4. Related New Relic CLI tools

    main

    While newrelic-cli is a powerful tool for fleet control, there are other specialized New Relic command-line utilities for specific workflows:

    • NR1 CLI: Used for managing development workflows for custom Nerdpacks on New Relic One.
    • New Relic Lambda CLI: Used to install the New Relic AWS Lambda integration and layers.
    • New Relic Diagnostics: A utility for automatically detecting common problems with New Relic agents.
  5. Manage NerdStorage documents and collections

    main

    The newrelic nerdstorage command provides the interface to read, write, and delete NerdStorage documents and collections. This command acts as a parent to more specific subcommands for managing individual collections or specific documents.

    To use NerdStorage commands, you can specify an account ID using the --accountId flag or the NEW_RELIC_ACCOUNT_ID environment variable, and control the output format using --format (supporting JSON, Text, or YAML).

  6. Manage entity tags via the CLI

    main

    The newrelic entity tags command group is used to manage metadata tags on New Relic entities. This includes retrieving, creating, deleting, and replacing tag:value pairs.

    Available subcommands include:

    • get: Retrieve tags for an entity.
    • create: Add new tag:value pairs.
    • delete: Remove specific tag:value pairs.
    • delete-values: Remove all values associated with a specific tag.
    • replace: Replace existing tag:value pairs.
  7. Manage New Relic Entity deployments

    main

    The newrelic entity deployment command allows you to manage deployment markers for New Relic entities. A deployment marker is an event that indicates a deployment occurred, paired with metadata (such as user, revision, or change-log) from your SCM system. New Relic visualizes these as vertical lines on charts and graphs at the specific timestamp of the event.

    Note: This feature is in Limited Preview and may not be available to all customers.

  8. Use the `--agent` flag for complex deployments

    main

    The --agent flag allows you to define a deployment using a specific string format. This is the preferred method for deploying multiple agent types in a single command, which is not possible with the legacy flag syntax.

    Format: "AgentType:Version:ConfigVersionID1,ConfigVersionID2,..."

    Rules:

    • No spaces: Do not include spaces within the string.
    • Version Wildcards: The * wildcard is only supported for KUBERNETESCLUSTER managed entity types. For HOST fleets, you must specify an explicit version (e.g., 1.70.0).
    • Mutual Exclusivity: The --agent flag cannot be mixed with legacy flags (--agent-type, --agent-version, --configuration-version-ids).

    Examples:

    • Single agent: --agent "NRInfra:1.70.0:version-1"
    • Multiple agents: --agent "NRInfra:1.70.0:v1" --agent "NRDOT:2.0.0:v2"
    • Kubernetes wildcard: --agent "NRInfra:*:v1" (Valid only for K8s clusters)
    # Single agent with one configuration version
    --agent "NRInfra:1.70.0:version-abc-123"
    
    # Single agent with multiple configuration versions
    --agent "NRInfra:1.70.0:version-1,version-2,version-3"
    
    # Multiple agents (Infrastructure and .NET)
    --agent "NRInfra:1.70.0:version-1,version-2" \
    --agent "NRDOT:2.0.0:version-3"
    
    # Wildcard version for Kubernetes fleet (only valid for KUBERNETESCLUSTER type)
    --agent "NRInfra:*:config-k8s-v1"
  9. Understand the Fleet Control CLI directory structure

    main

    The Fleet Control CLI is organized into a command hierarchy managed by command.go. Configuration for specific operations is stored in YAML files within the configs/ directory. Each command has a corresponding handler implementation file.

    Key components include:

    • configs/: Contains YAML templates for various operations like fleet_management_create.yaml, fleet_deployment_deploy.yaml, and fleet_members_add.yaml.
    • command.go: The main entry point defining the command hierarchy.
    • command_framework.go: The core framework driving the CLI logic.