Load the cubeInspect.js in mongo shell, e.g. by copy/pasting, in the same database as cube (by default, cube_development
)
In mongo shell, in the same database as cube, you can now write queries like this :
> use cube_development;
> cubeInspect('cube_request').distinct('_id')
[cubeInspect] start date for incremental map/reduce: Thu Jan 01 1970 01:00:00 GMT+0100 (CET)
[ "ip", "method", "path" ]
Here 'ip', 'method' and 'path' are what you can use in a query for 'cube_request' type
At next call, it will be way quicker to compute those fields :
> cubeInspect('cube_request').distinct('_id')
[cubeInspect] start date for incremental map/reduce: Fri Jun 01 2012 17:35:05 GMT+0200 (CEST)
[ "ip", "method", "path" ]
As you can see, the start date is not the same for the map reduce as it's an incremental map/reduce. It's using the latest known event from the previous map/reduce as a start, so you can miss some fields, but in general it should be a pretty good approximation (if you wanted it to be perfect, you probably couldn't do it in incremental)
Due to how it works (based on incremental map/reduce), the first call of cubeInspect for a type is pretty slow. Next call for the same type should be quick if you call it often, so it won't have to parse a lot of new events to check nothing has changed.
In order to store the result for it to be incremental, the convention is to use the type suffixed by "_keys", in the same way you should already have type+"_events" and type+"_metrics", e.g. :
- We want to know what are the usable keys of
cube_compute
- Cube will have already created the collections
cube_compute_events
andcube_compute_metrics
- calling the
cubeInspect
function will create a newcube_compute_keys
collection to store the map/reduce results.
There is as much result stored in the _keys collection as there is different kind of key in documents and subdocuments of each ".d" of the _event
collection
CubeInspect uses an incremental map/reduce that you should launch as much as possible if you want the result to be quick at each call.
The map/reduce checks all the different keys and subkeys available in each document of the _events
collection of a type
This script has been made as a specific for cube, and is heavily inspired by more generic case detailed in those pages :