-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from theletterf/nr-cli-guide
Get started with New Relic CLI
- Loading branch information
Showing
1 changed file
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
--- | ||
path: '/guides/get-started-new-relic-cli' | ||
duration: '20 min' | ||
title: 'Get started with the New Relic CLI' | ||
template: 'GuideTemplate' | ||
description: 'This guide walks you through the essentials of the New Relic CLI, from install and configuration to basic usage.' | ||
--- | ||
|
||
<Intro> | ||
|
||
Access the New Relic platform from the comfort of your terminal: you can use the New Relic CLI to manage entity tags, define workloads, record deployment markers, and much more. Our CLI has been designed for automating common tasks in your DevOps workflow. This guide walks you through the essentials of New Relic CLI, from install and configuration to basic usage. | ||
|
||
<Video id="6uw3tu0d23" type="wistia"/> | ||
</Intro> | ||
|
||
## Before you begin | ||
|
||
For this guide you just need: | ||
|
||
1. Your New Relic [personal API Key](https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys#personal-api-key), which you can create from the **Account settings** of your New Relic account | ||
2. An [instrumented application](/docs/agents/manage-apm-agents/installation/install-agent) in your New Relic account | ||
|
||
<Steps> | ||
<Step> | ||
|
||
## Install the New Relic CLI | ||
|
||
The New Relic CLI can be downloaded via [Homebrew](https://brew.sh/) (macOS), [Scoop](https://scoop.sh/) (Windows), and [Snapcraft](https://snapcraft.io/) (Linux). You can also download [pre-built binaries](https://github.com/newrelic/newrelic-cli/releases) for all platforms, including .deb and .rpm packages, and our Windows x64 .msi installer. | ||
|
||
### Linux | ||
|
||
With [Snapcraft](https://snapcraft.io/) installed, run: | ||
|
||
`sudo snap install newrelic-cli` | ||
|
||
### macOS | ||
|
||
With [Homebrew](https://brew.sh/) installed, run: | ||
|
||
`brew install newrelic-cli` | ||
|
||
### Windows | ||
|
||
With [Scoop](https://scoop.sh/) installed, run: | ||
|
||
`scoop bucket add newrelic-cli https://github.com/newrelic/newrelic-cli.git`<br /> | ||
`scoop install newrelic-cli` | ||
|
||
</Step><Step> | ||
|
||
## Create your New Relic CLI profile | ||
|
||
Now that you've installed the New Relic CLI, it's time to create your first profile. Profiles contain credentials and settings that you can apply to any CLI command, which is useful when switching between accounts. | ||
|
||
To create your first CLI profile, run the [`profiles add`](https://github.com/newrelic/newrelic-cli/blob/master/docs/cli/newrelic_profile_add.md) command. Note that you need to set the [region](https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/get-started/our-eu-us-region-data-centers) of your New Relic account: use `-r` to set either `us` or `eu` (this is required). | ||
|
||
```sh lineNumbers=false | ||
# Create the tutorial account for the US region | ||
newrelic profiles add -n tutorial --apiKey YOUR_NEW_RELIC_API_KEY -r YOUR_REGION | ||
# Set the profile as defaults | ||
newrelic profiles default -n tutorial | ||
``` | ||
|
||
</Step><Step> | ||
|
||
## Get your application details | ||
|
||
In this example, you are going to add tags to the application you've instrumented with New Relic. [Tags](https://docs.newrelic.com/docs/new-relic-one/use-new-relic-one/core-concepts/tagging-use-tags-organize-group-what-you-monitor) are key-value pairs that can help you organize and filter your entities. An [entity](https://docs.newrelic.com/docs/new-relic-one/use-new-relic-one/core-concepts/what-entity-new-relic) (for example, an application) can have a maximum of 100 key-value pairs tied to it. | ||
|
||
Before searching for your application using the New Relic CLI, write down or copy your [Account ID](https://docs.newrelic.com/docs/accounts/install-new-relic/account-setup/account-id) and the [name of your application in New Relic](https://docs.newrelic.com/docs/agents/manage-apm-agents/app-naming/name-your-application) - you need both to find applications in the New Relic platform. | ||
|
||
</Step><Step> | ||
|
||
The New Relic CLI can retrieve your application details as a JSON object. | ||
|
||
To search for your APM application use the [`apm application search`](https://github.com/newrelic/newrelic-cli/blob/master/docs/cli/newrelic_apm_application_search.md) command. If you get an error, check that the account ID and application name you provided are correct. | ||
|
||
```bash lineNumbers=false | ||
newrelic apm application search --accountId YOUR_ACCOUNT_ID --name NAME_OF_YOUR_APP | ||
``` | ||
|
||
</Step><Step> | ||
|
||
If the account ID is valid, and the application name exists in your account, `apm application search` yields data similar to this example. | ||
|
||
When you've successfully searched for your application, look for the `guid` value. It's a unique identifier for your application. You should copy it or write it down. | ||
|
||
```json lineNumbers=false | ||
[ | ||
{ | ||
"accountId": YOUR_ACCOUNT_ID, | ||
"applicationId": YOUR_APP_ID, | ||
"domain": "APM", | ||
"entityType": "APM_APPLICATION_ENTITY", | ||
"guid": "A_LONG_GUID", | ||
"name": "NAME_OF_YOUR_APP", | ||
"permalink": "https://one.newrelic.com/redirect/entity/A_LONG_GUID", | ||
"reporting": true, | ||
"type": "APPLICATION" | ||
} | ||
] | ||
``` | ||
</Step><Step> | ||
|
||
## Add a simple tag to your application | ||
|
||
Now that you have the GUID, you can point the New Relic CLI directly at your application. Adding a tag is the simplest way to try out the CLI capabilities (don't worry, tags can be deleted by using [`entity tags delete`](https://github.com/newrelic/newrelic-cli/blob/master/docs/cli/newrelic_entity_tags_delete.md)). | ||
|
||
Let's suppose that you want to add an environment tag to your application. Go ahead and add the `dev:testing` tag (or any other key-value pair) to your application using the [`entities tags create`](https://github.com/newrelic/newrelic-cli/blob/master/docs/cli/newrelic_entity_tags_create.md) command. | ||
|
||
```sh lineNumbers=false | ||
newrelic entity tags create --guid YOUR_APP_GUID --tag devkit:testing | ||
``` | ||
</Step><Step> | ||
|
||
What if you want to add multiple tags? Tag sets come to the rescue! While tags are key-value pairs separated by colons, tag sets are comma separated lists of tags. For example: | ||
|
||
`tag1:value1,tag2:value2` | ||
|
||
To add multiple tags at once to your application, modify and run the following snippet. | ||
|
||
```sh lineNumbers=false | ||
newrelic entity tags create --guid YOUR_APP_GUID --tag tag1:test,tag2:test | ||
``` | ||
> Adding tags is an asynchronous operation: this means it could take a while for the tags to get created. | ||
</Step><Step> | ||
|
||
You've created and added some tags to your application, but how do you know they're there? You need to retrieve your application's tags. | ||
|
||
To retrieve your application's tags, use the [`entity tags get`](https://github.com/newrelic/newrelic-cli/blob/master/docs/cli/newrelic_entity_tags_get.md) command. | ||
|
||
`newrelic entity tags get --guid YOUR_APP_GUID` | ||
|
||
All tags associated with your application are retrieved as a JSON array. | ||
|
||
```json lineNumbers=false | ||
[ | ||
{ | ||
"Key": "tag1", | ||
"Values": [ | ||
"true" | ||
] | ||
}, | ||
{ | ||
"Key": "tag2", | ||
"Values": [ | ||
"test" | ||
] | ||
}, | ||
{ | ||
"Key": "tag3", | ||
"Values": [ | ||
"testing" | ||
] | ||
} | ||
// ... | ||
] | ||
``` | ||
</Step><Step> | ||
|
||
## Bonus step: Create a deployment marker | ||
|
||
Deployments of applications often go wrong. [Deployment markers](https://docs.newrelic.com/docs/apm/new-relic-apm/maintenance/record-monitor-deployments) are labels that, when attached to your application data, help you track deployments and troubleshoot what happened. | ||
|
||
To create a deployment marker, run the [`apm deployment create`](https://github.com/newrelic/newrelic-cli/blob/master/docs/cli/newrelic_apm_deployment_create.md) command using the same Application ID from your earlier search. | ||
|
||
```bash lineNumbers=false | ||
newrelic apm deployment create --applicationId YOUR_APP_ID --revision $(git describe --tags --always) | ||
``` | ||
|
||
</Step><Step> | ||
|
||
Notice that the JSON response includes the revision and timestamp of the deployment. This workflow could be built into a continuous integration or continuous deployment (CI/CD) system to help indicate changes in your application's behavior after deployments. | ||
|
||
Here is an example. | ||
|
||
```json lineNumbers=false | ||
{ | ||
"id": 37075986, | ||
"links": { | ||
"application": 204261368 | ||
}, | ||
"revision": "v1.2.4", | ||
"timestamp": "2020-03-04T15:11:44-08:00", | ||
"user": "Developer Toolkit Test Account" | ||
} | ||
``` | ||
</Step></Steps> | ||
|
||
## Next steps | ||
|
||
Have a look at [all the available commands](https://github.com/newrelic/newrelic-cli/blob/master/docs/cli/newrelic.md). For example, you could create a [New Relic workflow](https://docs.newrelic.com/docs/new-relic-one/use-new-relic-one/core-concepts/new-relic-one-workloads-isolate-resolve-incidents-faster) using [`workload create`](https://github.com/newrelic/newrelic-cli/blob/master/docs/cli/newrelic_workload_create.md) | ||
|
||
If you'd like to engage with other community members, visit our [New Relic Explorers Hub](https://discuss.newrelic.com/c/build-on-new-relic/developer-toolkit) page. We welcome feature requests or bug reports on [GitHub](https://github.com/newrelic/newrelic-cli). | ||
|
||
## Related info | ||
|
||
- [New Relic CLI commands reference](https://github.com/newrelic/newrelic-cli/blob/master/docs/cli/newrelic.md) | ||
- [New Relic CLI repository on GitHub](https://github.com/newrelic/newrelic-cli) | ||
- [New Relic documentation](https://docs.newrelic.com) |