Last active
December 25, 2015 22:49
-
-
Save neumino/7053150 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.db('etdemo').table('et_metrics').groupedMapReduce( | |
// group -- we return the value that we are going to use to group | |
function(doc) { | |
// We group by logTime rouned to 5*60 (5 min) | |
return doc("logTime").sub( doc("logTime").mod(5*60) ) | |
}, | |
// map -- we return the value we are interested in | |
// count is to keep track of how many group we are | |
function(doc) { | |
return { | |
iowait: doc("cpu")("times")("iowait"), | |
system: doc("cpu")("times")("system"), | |
count: 1 | |
} | |
}, | |
// reduce -- here we just do the sum of iowait, system and count -- the left/right objects are the one mapped before so something like { iowait:..., system: ..., count:...} | |
function(left, right) { | |
return { | |
iowait: left("iowait").add( right("iowait")), | |
system: left("system").add( right("system")), | |
count: left("count").add( right("count")) | |
} | |
} | |
).map( function(reducedObject) { | |
// here reducedObject("count") is the number of doc we have in each group (we mapped each do to 1, then did the sum) | |
return { | |
group: reducedObject("group"), | |
iowait: reducedObject("reduction")("iowait").div( reducedObject("reduction")("count") ), | |
system: reducedObject("reduction")("system").div( reducedObject("reduction")("count") ) | |
} | |
}) |
wojons
commented
Oct 20, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment