如何使用石墨作为数据源获取脚本化仪表板?

时间:2017-01-18 15:15:24

标签: data-visualization graphite grafana

如何从石墨数据源获取指标? 我已经有了这个脚本,但是它会从假数据源生成随机指标。

图片:

enter image description here

我可以在此脚本中设置石墨数据源

'use strict';
var window, document, ARGS, $, jQuery, moment, kbn;
var dashboard;
var ARGS;
dashboard = {
  rows : [],
  schemaVersion: 13,
};
dashboard.title = 'Scripted and templated dash';
dashboard.time = {
  from: "now-6h",
  to: "now"
};
var rows = 1;
var seriesName = 'argName';
if(!_.isUndefined(ARGS.name)) {
  seriesName = ARGS.name;
}
  dashboard.rows.push({
    title: 'Chart',
    height: '300px',
    panels: [
      {
        title: 'Events',
        type: 'graphite',
        span: 12,
        fill: 1,
        linewidth: 2,
        targets: [
          {
            'target': 'stats.gauges.WidgetOccurrences.places.300'
          }
        ],
      }
    ]
  });
return dashboard;

1 个答案:

答案 0 :(得分:0)

尝试使用数据源值。

   // Intialize a skeleton with nothing but a rows array and service object
   dashboard = {
       __inputs: [{
           'name': "DS",
           'label': "datasource_label",
           'description': "",
           'type': "datasource",
           'pluginId': "datasource_plugin_id",
           'pluginName': "datasource_plugin_name"
       }],
       __requires: [{
               'type': 'panel',
               'id': 'graph',
               'name': 'Graph',
               'version': ''
           },
           {
               'type': 'datasource',
               'id': 'datasource_plugin_id',
               'name': 'datasource_plugin_name',
               'version': '1.0.0'
           }
       ],
       editable: true,
       rows: [],
   };

   dashboard.title = 'Scripted';
   dashboard.time = {
       from: 'now-36h',
       to: 'now'
   };

   dashboard.rows.push({
       title: 'Chart',
       height: '300px',
       panels: [{
           title: 'Variable Importance',
           type: 'graph',
           span: 12,
           fill: 1,
           linewidth: 2,
           datasource: 'datasource_label',
           targets: [{
               "target": "target"
           }],
           seriesOverrides: [],
           tooltip: {
               shared: true,
               sort: 0,
               value_type: 'individual'
           },
           xaxis: {
               "buckets": null,
               "mode": "time",
               "name": null,
               "show": true,
               "values": []
           },
           yaxes: [{
                   "format": "short",
                   "label": null,
                   "logBase": 1,
                   "max": null,
                   "min": null,
                   "show": true
               },
               {
                   "format": "short",
                   "label": null,
                   "logBase": 1,
                   "max": null,
                   "min": null,
                   "show": true
               }
           ]
       }]
   });
   return dashboard;