Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
676 views
in Technique[技术] by (71.8m points)

json - Using Other Data Sources for cubism.js

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); });
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...