NRQL2Nerd
A lightweight Ruby gem for executing NRQL queries against New Relic's NerdGraph API.
Skip the boilerplate and get straight to your data.
Features
- Simple, intuitive API for NRQL queries
- Works as a library or command-line tool
- Environment variable or explicit credential configuration
- Returns parsed JSON results ready for use
Installation
Add to your Gemfile:
gem "nrql2nerd"Or install directly:
gem install nrql2nerdConfiguration
Set your New Relic credentials via environment variables:
export NEW_RELIC_API_KEY="your-api-key"
export NEW_RELIC_ACCOUNT_ID="your-account-id"Or pass them explicitly when creating a client.
Usage
As a Library
require "nrql2nerd"
client = NRQL2Nerd::Client.new
results = client.run_query("SELECT count(*) FROM Transaction SINCE 1 hour ago")
# => [{"count" => 42}]With explicit credentials:
client = NRQL2Nerd::Client.new(
api_key: "your-api-key",
account_id: "12345"
)Command Line
# Using environment variables
nrql2nerd -q "SELECT count(*) FROM Transaction SINCE 1 hour ago"
# With explicit credentials
nrql2nerd -q "SELECT * FROM Transaction LIMIT 10" \
--api-key your-api-key \
--account-id 12345A shorter alias n2n is also available:
n2n -q "SELECT count(*) FROM PageView SINCE 1 day ago"Development
bin/setup # Install dependencies
bundle exec rake # Run tests and linting
bin/console # Interactive promptContributing
Bug reports and pull requests are welcome on GitHub. Please follow the code of conduct.
License
Available as open source under the MIT License.
