Programatically generating Grafana dashboard files with node.js
Grafana-dashboard-generator.js is an example of how to use node.js to automate Grafana JSON dashboard generation. To get going with it, take the file, save it into a directory of its own, and execute these npm install commands to meet the module dependencies…
npm install extend
npm install sync-request
(Those modules will default install into a node_modules directory)
Then execute the script like this…
wumpus:~/bin$ node grafana-dashboard-generator.js
calling get_all_servers()
in get_all_servers()
executing request GET for url = http://graphite:8080/metrics/expand/?query=telegraf.*
status code response from get was 200
calling JSON.parse(res)obj.hasOwnProperty(results) is true
returning obj.results
loaded serverlist with 1 keys
generating dashboard for wumpus
in function(main) with args = /usr/bin/nodejs,/home/mrtg/bin/grafana-dashboard-generator.js
server = wumpus
dashboard.title = wumpus
dashboard.editable = true
dashboard.pulldowns = [object Object],[object Object]
returning panels = [object Object],[object Object],[object Object],[object Object]
returning panels = [object Object],[object Object]
returning panels = [object Object],[object Object],[object Object],[object Object]
returning panels = [object Object],[object Object]
returning panels = [object Object],[object Object]
dashboard is composed, length = 17041 bytes, returning to caller
writing dashboard for wumpus to /opt/grafana/dashboard-json/wumpus.json
done with /opt/grafana/dashboard-json/wumpus.jsonwumpus:~/bin$
This particular dashboard generator script expects to find a list of servers in the telegraf.* Graphite name space. If you don’t store your telegraf data in telegraf.* modify the HTTP call around line 56 to fit your namespace.