The New Relic CLI is a powerful tool for developers and administrators. It allows you to interact with your New Relic account from the command line.
To get started with the New Relic CLI, you'll need to install it on your system. You can do this by running the command `brew install newrelic-cli` on a Mac or `sudo apt-get install newrelic-cli` on a Linux system.
The New Relic CLI uses a simple and intuitive syntax, making it easy to use even for those new to the tool. You can view the available commands by running `newrelic help`.
New Relic CLI commands can be used to manage your account, applications, and data. You can use them to create and manage alerts, monitor application performance, and more.
Installation and Setup
You can install the New Relic CLI on various platforms, including macOS, Windows, and Linux.
To update to the latest version, you can use specific commands, which are available for older versions of the CLI.
You can download pre-built binaries for all platforms, including .deb and .rpm packages, and our Windows x64 .msi installer.
The New Relic CLI can be installed on MacOS via homebrew, which is a package manager for macOS.
To install the New Relic CLI on MacOS via homebrew, you'll need to run a specific command, which is:
Profile and Configuration
To create a New Relic CLI profile, you need to run the profiles add command. This command is used to add a new profile to your CLI.
A profile in New Relic CLI contains credentials and settings that you can apply to any CLI command, which is useful when switching between accounts. This makes it easier to work with multiple accounts without having to constantly re-enter your credentials.
After running the profiles add command, you'll be prompted to enter the required information, including the account ID and API key. This information will be used to authenticate your CLI commands and ensure you have access to the right data.
Working with Applications
To get started with working with applications in New Relic CLI, you'll need to have your application details handy. Write down or copy your Account ID and the name of your application in New Relic.
You can then use the apm application search command to find your APM application. This command will help you locate your application in the New Relic platform.
Before you can retrieve your application's tags, you'll need to have created and added some tags to your application. You can do this by using the entity tags get command, which will retrieve all tags associated with your application as a JSON array.
Using the CLI
To use the New Relic CLI, you'll first need to install it on your operating system, which can be downloaded from the New Relic website. You can also download pre-built binaries for all platforms.
The New Relic CLI uses exit codes to help with scripting and confirming that a command has run successfully. For example, after you run a nr CLI command, you can retrieve its return code by running `echo $?` (on Windows, `echo %ERRORLEVEL%`). If the return code is 0, the command was successful.
You can configure the output format of the CLI to display results in either JSON or YAML format using the `-o json` or `-o YAML` argument. Additionally, you can configure a proxy if the target machine cannot directly connect to newrelic.com by setting the `NEW_RELIC_PROXY` environment variable.
To restore monitors, you can use the `nr restore` command with the `-d` argument to specify the folder containing the monitor files, and the `-f` argument to specify the file containing the monitor names. You can also use the `-F` argument to specify a file containing names of monitors to retry.
To Start Using
To start using the New Relic CLI, you'll need to define your New Relic admin API key in your environment. This can be done on Linux OS using the export command: `export NEW_RELIC_APIKEY=xxxx-xxxxxxx-xxxxx-xxxxxx`.
To specify the output format, you can use the `-o` argument, either with `json` or `YAML`. For example, `nr CLI` commands can be configured to output in JSON format using `-o json`.
If you're behind a proxy, you can configure the New Relic CLI to connect through it by setting the `NEW_RELIC_PROXY` environment variable. This is useful if your target machine can't directly connect to newrelic.com.
To configure retries for calling New Relic REST API while dealing with network issues, you can set the `RETRIES` environment variable. The default value is 3, but you can adjust it to suit your needs.
The New Relic CLI uses exit codes to help with scripting and confirming that a command has run successfully. You can retrieve the return code by running `echo $?` on Linux or `echo %ERRORLEVEL%` on Windows.
Build Project
To build your project using the CLI, you'll want to start by cloning the newrelic-cli repository.
First, run the command `git clone newrelic-cli` to download the repository to your local machine.
Next, navigate to the project root folder by running `cd newrelic-cli`.
Now, run the command `make deps` to install the dependencies required for the project.
After that, run `make build` to compile the project.
That's it! Your project is now built.
Core Recipe Library
The core recipe library is a treasure trove of installation recipes that come bundled with the CLI.
A core library of installation recipes is included with the CLI for use within the install command. This library is syndicated from open-install-library and embedded in the CLI binary at release time.
To fetch the latest recipe library while developing, you can use the recipes-fetch make target. This will update the recipe files in internal/install/recipes/files.
If you need a specific version of the recipe library, you can pass the archive download URL to the recipes-fetch make target via the RECIPES_ARCHIVE_URL option.
Cleaning up recipe files is a breeze, just use the recipes-clean make target.
Keyboard Shortcuts
Keyboard shortcuts can be a game-changer for navigating the UI efficiently. You can open the keyboard shortcut list by pressing ?.
If you're using a Mac, you can open the global search by pressing ⌘ + K, while Windows users can use Ctrl + K. The NRQL console can be opened with Ctrl + Shift + O.
You can also focus the filter input by pressing F, and copy a permalink by pressing ⌘ + . on a Mac or Ctrl + . on a Windows machine.
Here's a quick rundown of some common keyboard shortcuts:
You can quickly navigate to different areas of the UI using keyboard shortcuts. For example, you can go to Integrations & Agents by pressing G then I, or go to all entities by pressing G then E.
Frequently Asked Questions
What is a New Relic agent?
A New Relic agent is a software that collects performance data from your application or server by instrumenting your code at the source level. This agent is installed within your application or host server to gather essential performance metrics.
What is the New Relic query language like?
The New Relic query language, also known as NRQL, is similar to ANSI SQL, allowing you to retrieve detailed data insights into your applications and business activity. It's a powerful tool for gaining a deeper understanding of your systems and performance.
Sources
Featured Images: pexels.com