I am currently using a scripted dashboard to query my influxdb for bandwidth graph data, the dashboard below works fine but the data shown is in kbits instead of kbytes. If i manuall add the match(*8) to my query the graph looks correct, but I cant get it to work in my dashboard JS. Below is what I am currently using.
/* global _ */
/*
- Complex scripted dashboard
- This script generates a dashboard object that Grafana can load. It also takes a number of user
- supplied URL parameters (in the ARGS variable)
- Return a dashboard object, or a function
- For async scripts, return a function, this function must take a single callback function as argument,
- call this callback function with the dashboard object (look at scripted_async.js for an example)
*/
‘use strict’;
// accessible variables in this scope
var window, document, ARGS, $, jQuery, moment, kbn;
// Setup some variables
var dashboard;
// All url parameters are available via the ARGS object
var ARGS;
// Intialize a skeleton with nothing but a rows array and service object
dashboard = {
rows : ,
};
// Set a title
dashboard.title = ‘Bandwidth’;
// Set default time
// time can be overriden in the url using from/to parameters, but this is
// handled automatically in grafana core during dashboard initialization
dashboard.time = {
from: “now-6h”,
to: “now”
};
var rows = 1;
var seriesName = ‘argName’;
var hostName = ‘argHost’
var int = ‘argInterface’
var interFace = ‘interface’
if(!_.isUndefined(ARGS.rows)) {
rows = parseInt(ARGS.rows, 10);
}
if(!_.isUndefined(ARGS.name)) {
seriesName = ARGS.name;
hostName = ARGS.host;
int = ARGS.interface;
}
//var interFace = int.replace(/q\s+/g, “:”);
var interFace = int.replace(/q/g, “:”);
//var interFace = int.replace(“/!/g”, “:”);
var query = function(interFace,hostName) {
return [
‘SELECT percentile(“value”, 95)’,
‘FROM "’ + interFace + ‘"’,
‘WHERE “host” = ’ + "’" + hostName + “'”,
‘AND “check” = ’ + "’" + “out” + “'”,
‘AND $timeFilter’,
].join(’ ');
};
for (var i = 0; i < rows; i++) {
dashboard.rows.push({
title: ‘Chart’,
height: ‘300px’,
panels: [
{
‘title’: seriesName,
‘type’: ‘graph’,
“y_formats”: [
“bps”,
“short”
],
‘datasource’: null,
“aliasColors”: {
“95th”: “#BF1B00”
},
‘span’: 12,
“nullPointMode”: “connected”,
‘fill’: 0,
‘linewidth’: 2,
‘function’: ‘mean’,
‘column’: ‘value’,
“seriesOverrides”: [
{
“alias”: “95th”,
“bars”: true,
“lines”: true,
“linewidth”: 1,
“yaxis”: 1
}
],
"targets": [
{
"fields": [
{
"func": "max",
"name": "value"
}
],
"groupBy": [
{
"interval": "auto",
"type": "time"
}
],
"measurement": interFace,
"alias": "Out",
"refId": "A",
"tags": [
{
"key": "host",
"operator": "=",
"value": hostName
},
{
"condition": "AND",
"key": "check",
"operator": "=",
"value": "out"
}
]
},
{
"fields": [
{
"func": "max",
"name": "value"
}
],
"groupBy": [
{
"interval": "auto",
"type": "time"
}
],
"measurement": interFace,
"alias": "In",
"refId": "A",
"tags": [
{
"key": "host",
"operator": "=",
"value": hostName
},
{
"condition": "AND",
"key": "check",
"operator": "=",
"value": "in"
}
]
},
],
tooltip: {
shared: true
},
"yaxes": [
{
"label": null,
"show": true,
"logBase": 1,
"min": null,
"max": null,
"format": "bits"
},
{
"label": null,
"show": true,
"logBase": 1,
"min": null,
"max": null,
"format": "short"
}
],
"xaxis": {
"show": true
},
"legend": {
"show": true,
"values": true,
"min": false,
"max": true,
"current": false,
"total": false,
"avg": false
},
}
]
});
}
return dashboard;