Guest User

Untitled

a guest
Jan 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. count = 10000
  2. size = 100 // megabytes
  3.  
  4. hosts = ['host1', 'host2', 'host3', 'host4', 'host5']
  5. facilities = ['Server', 'Client', 'Proxy']
  6. chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz '.split('');
  7.  
  8. speed = 1500.0; // messages per second
  9. start = new Date().getTime() - 24*60*60*1000;
  10.  
  11. function random(elements) {
  12. return elements[Math.floor(Math.random() * elements.length)];
  13. }
  14.  
  15. function message() {
  16. var str = '';
  17. for (var i=0; i < 100; i++) {
  18. str += random(chars);
  19. };
  20. return str;
  21. }
  22.  
  23.  
  24. db.messages.drop()
  25. db.createCollection('messages', {capped: true, size: size * 1024 * 1024})
  26.  
  27.  
  28. for (var i = 0; i < count; i++) {
  29. hash = {};
  30. hash.created_at = (start + i / speed * 1000.0) / 1000.0;
  31. hash.host = random(hosts);
  32. hash.facility = random(facilities);
  33. hash.level = random([1,2,3,4,5,6]);
  34. hash.message = message();
  35.  
  36. db.messages.save(hash);
  37. }
  38.  
  39. db.messages.find().sort({$natural: 1}).limit(1).forEach(function(x) { printjson(x); })
  40. db.messages.find().sort({$natural: -1}).limit(1).forEach(function(x) { printjson(x); })
Add Comment
Please, Sign In to add comment