submitting queries not through the dashboard

61 views
Skip to first unread message

Bryan

unread,
Jan 3, 2012, 8:09:14 PM1/3/12
to cube-user
Hey... started with Cube today, digging it so far. I like the
dashboard and visualizations, but I also have a need to be able to run
the same kind of queries the dashboard does to fill the graphs, but
manually so I just get the data back. I am seeing Web Socket requests
requests going by in the Chrome dev tool to the 'ws://localhost:
1081/1.0/metric/get' url, but I don't see any payload.

I read the 'Query Evaluation' section of your documentation here
http://square.github.com/cube/ and saw that it provides the example
json of:

{
"expression": "sum(request)",
"start": "2011-09-10T12:37:12Z",
"stop": "2011-09-13T04:00:02Z",
"step": 300000
}

It would be super handy if that /1.0/metric/get endpoint would also
work with a regular HTTP get so I can write some quick and dirty
scripts that use curl. Is there a version of this endpoint that
support URL parameters?

TIA... Bryan

Mike Bostock

unread,
Jan 3, 2012, 8:15:33 PM1/3/12
to cube...@googlegroups.com
We've been working on that over here:

https://github.com/square/cube/issues/24

It looks almost ready to bundle up into a pull request to get merged
to master. Feel free to lend a hand if you want it faster!

Mike

Bryan

unread,
Jan 3, 2012, 8:17:10 PM1/3/12
to cube-user
Hey Mike... really appreciate the quick response. I'll check it out.

Bryan

unread,
Jan 3, 2012, 8:21:41 PM1/3/12
to cube-user
Just had another thought. I think it would be acceptable to write a
little tool that uses a Web Socket client to make the calls, then run
my tool with a script (passing it whatever query I wanted to) instead
of running curl with a script. If I went that route, is it safe to
assume that I just send a json-formatted String like the example shows
to the ws://...1.0/metric/get endpoint. If that's all the browser is
doing, I can whip something up that does that too and forego having to
rely on a GET with curl.

On Jan 3, 7:15 pm, Mike Bostock <mbost...@cs.stanford.edu> wrote:

Mike Bostock

unread,
Jan 3, 2012, 8:41:26 PM1/3/12
to cube...@googlegroups.com
Sure, but your tool would need to speak WebSockets. It's pretty easy
to write a Node.js script that speaks WebSockets and makes a request.
For example:

https://gist.github.com/1557990

The one annoying thing is that you'll need to compute the number of
responses you expect to know when the request is fulfilled. This isn't
too hard to compute (subtract the two times, divide by the step, then
floor).

Mike

Bryan

unread,
Jan 3, 2012, 8:45:21 PM1/3/12
to cube-user
Yeep. That makes sense. Thanks.

Bryan

unread,
Jan 18, 2012, 5:41:20 PM1/18/12
to cube-user
So I noticed that you committed the code that supports HTTP GETability
and I decided to try to install Node from source locally to play with
that feature. I'm a total Node newb, so I suspect it's some general
Node thing I'm not doing right rather than something wrong with Cube.
I do an 'npm install' from the cloned dir locally and get the output
below. I assume that mean that v2.7.2 of d3 is not published to
registry.npmjs.org. What's the right thing to do next? Ask for it to
be published or try to build that version of that dependency from
source too?




npm http GET https://registry.npmjs.org/mongodb/0.9.7-1.3
npm http GET https://registry.npmjs.org/pegjs/0.6.2
npm http GET https://registry.npmjs.org/vows/0.5.11
npm http GET https://registry.npmjs.org/websocket/1.0.2
npm http GET https://registry.npmjs.org/websocket-server/1.4.04
npm http GET https://registry.npmjs.org/d3/2.7.2
npm http 304 https://registry.npmjs.org/mongodb/0.9.7-1.3
npm http 304 https://registry.npmjs.org/websocket/1.0.2
npm http 304 https://registry.npmjs.org/websocket-server/1.4.04
npm WARN websocke...@1.4.04 package.json: bugs['web'] should
probably be bugs['url']
npm http 304 https://registry.npmjs.org/vows/0.5.11
npm http 304 https://registry.npmjs.org/d3/2.7.2
npm ERR! Error: No dist in undefined package
npm ERR!     at next (/usr/local/lib/node_modules/npm/lib/cache.js:
515:26)
npm ERR!     at /usr/local/lib/node_modules/npm/lib/cache.js:508:5
npm ERR!     at Object.saved [as oncomplete] (/usr/local/lib/
node_modules/npm/lib/utils/npm-registry-client/get.js:147:7)
npm ERR! Report this *entire* log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <np...@googlegroups.com>
npm ERR!
npm ERR! System Darwin 10.8.0
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /path/to/cube
npm ERR! node -v v0.6.6
npm ERR! npm -v 1.1.0-beta-4
npm ERR! message No dist in undefined package
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /path/to/cube/npm-debug.log
npm not ok

Mike Bostock

unread,
Jan 18, 2012, 5:45:48 PM1/18/12
to cube...@googlegroups.com
Ah, my bad. I forgot to publish D3 2.7.2 to NPM. Doing that now.

Mike

Bryan

unread,
Jan 18, 2012, 6:19:19 PM1/18/12
to cube-user
Thanks again for the quick response. All is well now. Much
appreciated.

Bryan

unread,
Jan 19, 2012, 11:34:27 AM1/19/12
to cube-user
I've been playing around with this yesterday since I got the GET
working and noticed that the minimum step value supported is 300000 (5
minutes).

I assume that means that you're doing some math in the evaluator
client to support the 'every 20 seconds' graphing?

Mike Bostock

unread,
Jan 19, 2012, 12:26:16 PM1/19/12
to cube...@googlegroups.com
> the minimum step value supported is 300000 (5 minutes).

The minimum step value is 20 seconds:

https://github.com/square/cube/blob/master/lib/cube/server/tiers.js#L13-18

Mike

Bryan

unread,
Jan 19, 2012, 2:42:05 PM1/19/12
to cube-user
Bah. My bad. I think I was being obtuse and tried to pass it '20'
instead of '20000'.

On Jan 19, 11:26 am, Mike Bostock <mbost...@cs.stanford.edu> wrote:
> > the minimum step value supported is 300000 (5 minutes).
>
> The minimum step value is 20 seconds:
>
> https://github.com/square/cube/blob/master/lib/cube/server/tiers.js#L...
>
> Mike

Michael C

unread,
Apr 3, 2012, 10:11:09 AM4/3/12
to cube...@googlegroups.com
Just getting started with Cube over the past couple of days.  I have it running and am able to use its visual editor to create reports based upon data sent to the mongoDB via a modified emitter.

I now want to be able to query the data independently so that I can create my own graphs using D3.

I've read this thread and the linked article: https://github.com/square/cube/issues/24 , but I'm not sure how to formulate a query.

It seems like I should be able to query from a browser using http://localhost:1081/<uniqueID>/?expression=sum(request)&start=2011-09-10T12:37:12Z&stop=2011-09-13T04:00:02Z&step=300000 

But the above does not work (404 not found).

Could someone please provide an example of the way I can formulate the query to retrieve the data directly from a GET?

Mike

Mike Bostock

unread,
Apr 3, 2012, 11:46:19 AM4/3/12
to cube...@googlegroups.com
> http://localhost:1081/<uniqueID>/?expression=sum(request)&start=2011-09-10T12:37:12Z&stop=2011-09-13T04:00:02Z&step=300000

Replace "<uniqueID>/" with "1.0/metric", so:

http://localhost:1081/1.0/metric?expression=sum(request)&start=2011-09-10T12:37:12Z&stop=2011-09-13T04:00:02Z&step=300000

Mike

Michael Cook

unread,
Apr 3, 2012, 12:15:10 PM4/3/12
to cube...@googlegroups.com
Ok.  got it.  Works great.

Mike
Reply all
Reply to author
Forward
0 new messages