Skip to main content

New Relic query interface

Project description

Code style: black pre-commit pre-commit.ci status

Python package codecov

Query interface for the telemetry from New Relic SaaS platform.

Requirements

Description

This module, designed to be used ether from Jypyter or from application providing you a query access to your data stored in New Relic platform, so you can perform custom analysis.

Installation

You can download this module from GitHub repository. Then run

make init dependencies

This will install all dependencies. Then running the pip install as

pip install .

from the module directory source and nrquery module will be installed

How to query New Relic platform ?

nrquery module uses New Relic advanced GraphQL capabilities, but currently only supports NRQL queries. GraphQL queries will be implemented at some point in the future. Module consists of two classes:

Query class

nrquery.Query class provides an interface for sending NRQL queries to New Relic GraphQL API endpoint. Constructor of that class takes two values:

New Relic account (or None) New Relic API User key (or None)

if you pass None to any of the parameters, nrquery module will try to take account information from NRACCOUNT environment variable and API key from NRAPIKEY environment variable.

If nether is specified, exception will be raised.

nrquery.Query.Run method takes NRQL query as parameter and returns nrquery.Result object.

import nrquery

res = nrquery.Query().Run("SELECT COUNT(*) FROM TransactionError")

How to send a multiple queries

You can prepare your nrquery.Query instance to send a multiple queries, then combine result in single DataFrame

import nrquery

q = nrquery.Query()
q += "SELECT * FROM TransactionError LIMIT 1"
q += "SELECT * FROM TransactionError LIMIT 1"
res = q.Run()
df = res.Dataframe()

How to detect a nodes that stop sending data (NODATA() nodes).

There is a special method for nrquery.Query.Deadnodes. This method takes a date query as a partameter. Date query could be in a form of "May 9, 2022" or "1 day ago" or "05-09-2022" and that dat is cut-off date for detection of dead nodes.

import nrquery

q = nrquery.Query()
res = q.Deadnodes("1 hour ago")

This request will return result with list of the nodes stop sending data 1 hour ago.

Get the list of alertable nodes.

nrquery.Query.Alertable() is a special method that will return the list of the nodes that is in Alertable state

import nrquery

q = nrquery.Query()
res = q.Alertable()

Result class

You shall not directly create instances of the nrquery.Result class. Method Run of the class nrquery.Query will return an instance of the Result class. There are few class variables that can pose some interest:

  • nrquery.Result.IsSuccess - True or False insicating success or failure of the query associated with result.
  • nrquery.Result.Elapsed - time tat takes New Relic platform to run that query
  • nrquery.Result.Query - query associated with that result

Following methods can be used to extract the value of the query. You must undestand the expected query outcome and use appropriate conversion methods:

  • nrquery.Result.Json - will convert result into a plain JSON
  • nrquery.Result.Series - will convert result into a single Pandas series object
  • nrquery.Result.Dataframe - will convert result into a Pandas Dataframe object
  • nrquery.Result.CSV - will convert result into a CSV string.
  • nrqauery.Result.Numpy - will convert result into a dictionary of numpy arrays
import nrquery

res = nrquery.Query().Run("SELECT * FROM TransactionError")
df = res.Dataframe()

nrquery.Result.Deadnodes

This merhod returns the list of nodes that been prepared by nrquery.Query.Deadnodes

nrquery.Result.Alertable

This method will return the list of the nodes prepared by nrquery.Query.Alertable

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nrquery-1.6.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

nrquery-1.6-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file nrquery-1.6.tar.gz.

File metadata

  • Download URL: nrquery-1.6.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for nrquery-1.6.tar.gz
Algorithm Hash digest
SHA256 fbf3e05ec80a3a9962a624472a15c9f0983e5a6352a2bf4c9a3076914c8a11c4
MD5 e89c3f1eafbc124fc0a34ecdd7c3d798
BLAKE2b-256 6237afcf006f542a9e40434a685906355899d875d2cad94f8f9598d65af74d98

See more details on using hashes here.

File details

Details for the file nrquery-1.6-py3-none-any.whl.

File metadata

  • Download URL: nrquery-1.6-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for nrquery-1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 eff2f0083cd6e533501b94e5d07334c440241c5fbd1bc84cc29b01cb1ee0b52c
MD5 27042659fe3a261ef20d90025c7347b6
BLAKE2b-256 135a79381fcda3ab1e2bbe3b4b1b56b21c501e22cb90f7a5eae00b0dc0b7f0a6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page