qingw / nrql.el

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nrql.el

https://cdn.rawgit.com/syl20bnr/spacemacs/442d025779da2f62fc86c2082703697714db6514/assets/spacemacs-badge.svg

nrql.el is a library that offers the ability to run NewRelic NRQL (NewRelic Query Language) queries from within Emacs.

It is currently intended for, and best used, within org-babel code blocks. Made with org-mode.

demo/nrql.gif

Installation

Manual

  1. Clone this repo
  2. Run the following pointed at wherever you cloned this repo to
(package-install-file "~/code/nrql.el/nrql.el")

MELPA

Maybe if there is interest

Usage

This package is currently best used within org-mode. It was developed to make writing investigations into tickets by allowing the results of NRQL queries to be easily exportable. A typical work flow might look something like the following:

  1. Start investigating a bug in NewRelic
  2. Find the appropriate information, and obtain an NRQL query (either you wrote it, or can sometimes be captured from https://one.newrelic.com UI)
  3. Paste it into an nrql org-babel block. It can now be run locally on your machine, and have the result exported if properly configured (add :exports results or :exports both to your nrql block’s header arguments
select timestamp, message from Log where message like '%readiness%' since 1 minute ago limit 10
timestampmessage
2021-10-10 Sun 17:28:47.791complete: GET /api/readiness 200
2021-10-10 Sun 17:28:47.043complete: GET /api/readiness 200
2021-10-10 Sun 17:28:46.259complete: GET /api/readiness 200
2021-10-10 Sun 17:28:46.249complete: GET /api/readiness 200
2021-10-10 Sun 17:28:46.171complete: GET /api/readiness 200
2021-10-10 Sun 17:28:45.982complete: GET /api/readiness 200
2021-10-10 Sun 17:28:45.640complete: GET /api/readiness 200
2021-10-10 Sun 17:28:45.509complete: GET /api/readiness 200
2021-10-10 Sun 17:28:45.424complete: GET /api/readiness 200
2021-10-10 Sun 17:28:45.244complete: GET /api/readiness 200

Sample Queries

Queries Resulting in Tables

You can also explicitly specify what fields you want to return. Timestamps will be parsed to a human readable format by default.

from Log select timestamp, response_status where response_status is not null
timestampresponse_status
2021-10-11 Mon 21:55:32.005200
2021-10-11 Mon 21:55:30.761200
2021-10-11 Mon 21:55:30.614200
2021-10-11 Mon 21:55:30.563200
2021-10-11 Mon 21:55:30.460200
2021-10-11 Mon 21:55:30.406200
2021-10-11 Mon 21:55:30.324200
2021-10-11 Mon 21:55:30.263200
2021-10-11 Mon 21:55:30.110200
2021-10-11 Mon 21:55:30.082200

You can run star queries against your transactions.

select * from Transaction limit 9
appIdappNamecontainerIddurationentityGuiderrorhostnameportpriorityrealAgentIdtags.accounttags.accountIdtags.guidtags.trustedAccountIdtimestamptotalTimetransactionSubTypetransactionTypeapdexPerfZonehttpResponseCoderequest.headers.contentLengthrequest.headers.hostrequest.headers.userAgentrequest.methodresponse.headers.contentType
111111tacocloud-comcontainer_id1230.04863817entity_456:falsetacocloud-0WebTransaction/Filter/TacoRequestFilter89830.886877111taco.com999entity_4569992021-10-11 Mon 21:22:38.5420.04863817FilterWebS200130tacocloud-0.tacocloud-hs.tacocloud:8983Taco[org.apache.solr.client.solrj.impl.Http2TacoClient] 2.0POSTapplication/octet-stream
111111tacocloud-comcontainer_id1230.044141483entity_456:falsetacocloud-0WebTransaction/Filter/TacoRequestFilter89830.767033111taco.com999entity_4569992021-10-11 Mon 21:22:38.5410.044141483FilterWebS200131tacocloud-0.tacocloud-hs.tacocloud:8983Taco[org.apache.solr.client.solrj.impl.Http2TacoClient] 2.0POSTapplication/octet-stream
111111tacocloud-comcontainer_id1233.5762e-05entity_456:falsetacocloud-0OtherTransaction/Taco/org.apache.solr.search.TacoIndexSearcher/warm89830.33727111taco.com999entity_4569992021-10-11 Mon 21:22:38.5403.5762e-05TacoOthernilnilnilnilnilnilnil
111111tacocloud-comcontainer_id1230.05570143entity_456:falsetacocloud-0WebTransaction/Filter/TacoRequestFilter89830.26771111taco.com999entity_4569992021-10-11 Mon 21:22:38.5310.05570143FilterWebS200130tacocloud-0.tacocloud-hs.tacocloud:8983Taco[org.apache.solr.client.solrj.impl.Http2TacoClient] 2.0POSTapplication/octet-stream
111111tacocloud-comcontainer_id1230.013076241entity_456:falsetacocloud-0WebTransaction/Filter/TacoRequestFilter89830.072284111taco.com999entity_4569992021-10-11 Mon 21:22:38.5290.013076241FilterWebS200130tacocloud-0.tacocloud-hs.tacocloud:8983Taco[org.apache.solr.client.solrj.impl.Http2TacoClient] 2.0POSTapplication/octet-stream
111111tacocloud-comcontainer_id1230.001776847entity_456:falsetacocloud-0WebTransaction/Filter/TacoRequestFilter89830.785038111taco.com999entity_4569992021-10-11 Mon 21:22:38.5190.001776847FilterWebS200niltacocloud-0.tacocloud-hs.tacocloud:8983Taco[org.apache.solr.client.solrj.impl.Http2TacoClient] 2.0POSTapplication/octet-stream
111111tacocloud-comcontainer_id1230.014840841entity_456:falsetacocloud-0WebTransaction/Filter/TacoRequestFilter89830.286713111taco.com999entity_4569992021-10-11 Mon 21:22:38.5160.014840841FilterWebS200815tacocloud-0.tacocloud-hs.tacocloud:8983Taco[org.apache.solr.client.solrj.impl.Http2TacoClient] 2.0POSTapplication/octet-stream
111111tacocloud-comcontainer_id1230.010820628entity_456:falsetacocloud-0WebTransaction/Filter/TacoRequestFilter89830.026765111taco.com999entity_4569992021-10-11 Mon 21:22:38.5140.010820628FilterWebS200niltacocloud-0.tacocloud-hs.tacocloud:8983Taco[org.apache.solr.client.solrj.impl.Http2TacoClient] 2.0POSTapplication/octet-stream
111111tacocloud-comcontainer_id1230.000699507entity_456:falsetacocloud-0WebTransaction/Filter/TacoRequestFilter89830.285022111taco.com999entity_4569992021-10-11 Mon 21:22:38.5090.000699507FilterWebS200460tacocloud-0.tacocloud-hs.tacocloud:8983Taco[org.apache.solr.client.solrj.impl.Http2TacoClient] 2.0POSTapplication/octet-stream

You can basically query newRelic however you want.

SELECT rate(count(`com.taco.createTaco.counter`),1 minute) FROM Metric  WHERE app = 'turo-com-dunlop' TIMESERIES LIMIT 10 SINCE 1 week ago EXTRAPOLATE
beginTimeSecondsendTimeSecondsrate.count.com.taco.createTaco.counter
163340730016334289004.352777777777778
163342890016334505006.644444444444445
163345050016334721007.863888888888889
163347210016334937008.272222222222222
163349370016335153006.816666666666666
163351530016335369006.158333333333333
1633536900163355850010.519444444444444
1633558500163358010011.725
163358010016336017004.705555555555556
163360170016336233007.386111111111111
163362330016336449009.644444444444444
163364490016336665008.969444444444445
163366650016336881006.411111111111111
163368810016337097008.13888888888889
1633709700163373130011.005555555555556
163373130016337529007.386111111111111
163375290016337745005.902777777777778
163377450016337961008.625
1633796100163381770012.575
1633817700163383930011.805555555555555
163383930016338609009.591666666666667
1633860900163388250010.555555555555555
1633882500163390410013.936111111111112
1633904100163392570014.841666666666667
1633925700163394730010.675
1633947300163396890012.405555555555555
1633968900163399050011.863888888888889
1633990500163401210010.325

Function Based Queries

NewRelic supports many types of queries with functions as a parameter. These are some examples

FROM Log SELECT apdex(response_status) since 1 day ago
apdex.response_statuscountfsscoret
(“count” 5798595 “f” 5798595 “s” 0 “score” 0.0 “t” 0)5798595579859500.00

Compute median: the first value returned is the percentile

FROM Log SELECT median(response_status) where response_status is not null since 1 day ago
median
(“50” 200.0)

Compute percentile: the first parameter in a pair is the percentile

FROM Log SELECT percentile(response_status, 91, 80) where response_status is not null since 1 day ago
percentile.response_status
(“80” 200.0 “91” 200.0)

Compute median:

FROM Log SELECT median(response_size)
median
(50 192.0)

Customization

nrql-timestamp-format-string can be used to customize what format times display to. Any format must comply with Emacs’ format-time-string function.

nrql-api-keys-file can be used to customize what file api keys are stored in.

nrql.el-dir can be used to customize what directory api keys are stored in.

Contributions

Contributions are more than welcome! TODOs are currently being tracked within the nrql.el file. However there are a few specific areas that need some focus:

  1. faces: the faces (how syntax is highlighted) is currently very rudimentary
  2. HTTP Error handling: currently there is no error handling for HTTP errors.
  3. Supporting more features from NerdGraph like embedded chart URLs for data visualization.
  4. Improved readability of function query results involving percentiles.
  5. Improved testing

About

License:GNU General Public License v3.0


Languages

Language:Emacs Lisp 100.0%