nrql-simple is a small Python library that provides a convenient way to interact with the New Relic Insights query API. You can interact with this library programmatically or via the Command Line.
Project description
nrql-simple is a small Python library that provides a convenient way to interact with the New Relic Insights query API. You can interact with this library programmatically or via the Command Line.
Installation
nrql-simple is available on the Python Package Index (PyPI). You can install nrql-simple using pip.
virtualenv env source env/bin/activate pip install nrql-simple
To install the development version, run:
pip install https://github.com/AnthonyBloomer/nrql-simple/archive/master.zip
About
The New Relic Insights query API is a REST API for querying Insights event data. After you supply a standard NRQL query via HTTPS request, the query API returns a JSON response for parsing.
To use the API, you need a query key. You can have multiple query keys, and any query key can be used to initiate any Insights API query. If you have multiple systems querying Insights or different data destinations, New Relic recommends you use multiple query keys to enhance data security.
To create a new query key:
Go to insights.newrelic.com > Manage data > API keys.
Select the plus icon next to the Query keys heading.
Enter a short description of the key.
Select Save your notes.
You will also need make note of your New Relic Account ID. To find the account ID for your New Relic account:
Sign in to rpm.newrelic.com.
In the URL bar, copy the number after the /accounts/ portion of the URL: https://rpm.newrelic.com/accounts/ACCOUNT_ID/
Usage
The first step is to initialize a NRQL object and set your API Key and Account ID.
from nrql.api import NRQL
nrql = NRQL()
nrql.api_key = 'YOUR_API_KEY'
nrql.account_id = 'YOUR_ACCOUNT_ID'
Alternatively, you can export your API key and Account ID as environment variables.
$ export NR_API_KEY='YOUR_API_KEY' $ export NR_ACCOUNT_ID='YOUR_ACCOUNT_ID'
Then simply pass your NRQL statement into the query function. NRQL is a query language similar to SQL that you use to make calls against the New Relic Insights Events database. Refer to the NRQL documentation for examples and usage information.
Consider the following example that gets the unique number of container IDs for each application since this quarter.
req = nrql.query("select uniqueCount(containerId) from NrDailyUsage facet apmAppName since this quarter")
for k in req['facets']:
print("%s : %s" % (k['name'], k['results'][0]['uniqueCount']))
To use the CLI, you must first export your API key and Account ID as environment variables. Then, simply call the nrql command with your NRQL statement as an argument.
nrql "select uniqueCount(containerId) from nrdailyusage where apmAppName = 'SinatraApp' since this quarter"
The above command will output JSON formatted like this:
{
"results": [
{
"uniqueCount": 175
}
]
}
By default the program will just output the results array. To output the entire response, pass the --verbose flag.
nrql "select uniqueCount(containerId) from NrDailyUsage facet apmAppName since this quarter" --verbose
Contributing
Fork the project and clone locally.
Create a new branch for what you’re going to work on.
Push to your origin repository.
Create a new pull request in GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for nrql_simple-1.0.8-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f482434ff24684c86a9d69c6e514527413abcb14d526117d2235362e9f2b410f |
|
MD5 | d08609a282f41fb7e2b9ce27da4782a1 |
|
BLAKE2b-256 | 0539068fbb0375434fe56d0a9755ba1523135c63827f50713c61b2e8491bd3d6 |