Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- count = 10000
- size = 100 // megabytes
- hosts = ['host1', 'host2', 'host3', 'host4', 'host5']
- facilities = ['Server', 'Client', 'Proxy']
- chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz '.split('');
- speed = 1500.0; // messages per second
- start = new Date().getTime() - 24*60*60*1000;
- function random(elements) {
- return elements[Math.floor(Math.random() * elements.length)];
- }
- function message() {
- var str = '';
- for (var i=0; i < 100; i++) {
- str += random(chars);
- };
- return str;
- }
- db.messages.drop()
- db.createCollection('messages', {capped: true, size: size * 1024 * 1024})
- for (var i = 0; i < count; i++) {
- hash = {};
- hash.created_at = (start + i / speed * 1000.0) / 1000.0;
- hash.host = random(hosts);
- hash.facility = random(facilities);
- hash.level = random([1,2,3,4,5,6]);
- hash.message = message();
- db.messages.save(hash);
- }
- db.messages.find().sort({$natural: 1}).limit(1).forEach(function(x) { printjson(x); })
- db.messages.find().sort({$natural: -1}).limit(1).forEach(function(x) { printjson(x); })
Add Comment
Please, Sign In to add comment