Using Other Data Sources for cubism.js

心已入冬 提交于 2019-11-26 19:52:54

问题


I like the user experience of cubism, and would like to use this on top of a backend we have.

I've read the API doc's and some of the code, most of this seems to be extracted away. How could I begin to use other data sources exactly?

I have a data store of about 6k individual machines with 5 minute precision on around 100 or so stats.

I would like to query some web app with a specific identifier for that machine and then render a dashboard similar to cubism via querying a specific mongo data store.

Writing the webapp or the querying to mongo isn't the issue.

The issue is more in line with the fact that cubism seems to require querying whatever data store you use for each individual data point (say you have 100 stats across a window of a week...expensive).

Is there another way I could leverage this tool to look at data that gets loaded using something similar to the code below?

var data = [];
d3.json("/initial", function(json) { data.concat(json); });
d3.json("/update", function(json) { data.push(json); });

回答1:


Cubism takes care of initialization and update for you: the initial request is the full visible window (start to stop, typically 1,440 data points), while subsequent requests are only for a few most recent metrics (7 data points).

Take a look at context.metric for how to implement a new data source. The simplest possible implementation is like this:

var foo = context.metric(function(start, stop, step, callback) {
  d3.json("/data", function(data) {
    if (!data) return callback(new Error("unable to load data"));
    callback(null, data);
  });
});

You would extend this to change the "/data" URL as appropriate, passing in the start, stop and step times, and whatever else you want to use to identify a metric. For example, both Cube and Graphite use a metric expression as an additional query parameter.



来源:https://stackoverflow.com/questions/10526058/using-other-data-sources-for-cubism-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!