Automating NewRelic Dashboards

Jan 2, 2019 • Mark Eschbach

Tags:

As apart of making services easier to monitor and maintain I would like to create a tool to create the New Relic Insight
dashboards for us. I have already authored a program to deal with the updating SLI alarm thresholds. This program will
use the configurations from there to build the dashboard.

How to get Dashboards

I feel like the documentation on Dashboards
is a bit vague. Their blog post at least provides an
example. Since us humans use names and not ids (well, with the exception of bookmarks) to find Dashboards the first
step will be to check if the dashboard exists. This means paging through the list resource.

asyncfunctionlistDashboards(logger,apiKey){lethasMore,page=1;//Page must start at 1do{consttarget="/dashboard";constqs={page,per_page:100//Maxmimum};constresponse=awaitrp({uri:"https://api.newrelic.com/v2"+target,qs:qs,headers:{"X-Api-Key":apiKey,"Accept":"application/json"},json:true,method:"GET"});hasMore=response.dashboards.length!=0;page++;logger.info("Dashboards",response.dashboards.map((d)=>{return{id:d.id,title:d.title};}));}while(hasMore);}

Cool! Now we have the specific ID for the dashboard. There is also a URL embedded into the response entity for the
list operation, which might be useful in higher throughput scenarios.

Next up is trying to grab the actual dashboard. With the ID this just gets tacked onto the URL. So the following
should successfully pull the full entity. From here I can copy the JSON entity instead of guessing what it would look
like from the documentation.

This gives us an entity like the following. This structure is a bit unwieldy but I think I can build what I need with
it. Layouts are not simple, neither are charts. So I guess the union between the two shouldn’t be simple either.