Files
elasticsearch-js/scripts/generate/logs/samples/index.js
2014-05-13 09:43:02 -07:00

99 lines
2.3 KiB
JavaScript

var _ = require('../../../../src/lib/utils');
var WeightedList = require('./weighted_list');
var RandomList = require('./random_list');
var IpGenerator = require('./ip_generator');
var Stochator = require('./stochator');
var dayMs = 86400000;
exports.make = function (startingMoment, endingMoment) {
var sets = {};
var startms = startingMoment.toDate().getTime();
var endms = endingMoment.toDate().getTime();
sets.randomMsInDayRange = function () {
return _.random(startms, endms);
};
sets.lessRandomRespSize = new Stochator({
mean: 4500,
stddev: 4500 * 0.56,
min: 1500,
max: 10000
}, 'get');
sets.lessRandomMsInDay = new Stochator({
min: 0,
max: dayMs,
mean: dayMs / 2,
stdev: dayMs * 0.15,
}, 'get');
sets.randomRam = new RandomList(require('./ram'));
sets.randomOs = new RandomList(require('./os'));
sets.astronauts = new RandomList(require('./astronauts').map(function (name) {
return name.replace(/\W+/g, '-').toLowerCase();
}));
sets.airports = new RandomList(require('./airports'));
sets.ips = new IpGenerator(100, 1000);
sets.countries = new WeightedList(require('./countries'));
sets.extensions = new WeightedList({
'html': 40,
'php': 30,
'png': 15,
'gif': 5,
'css': 10
});
sets.responseCodes = new WeightedList({
200: 92,
404: 5,
503: 3
});
sets.tags = new WeightedList({
'error': 6,
'warning': 10,
'success': 84
});
sets.tags2 = new WeightedList({
'security': 20,
'info': 75,
'login': 5
});
sets.timezones = new WeightedList({
'-07:00': 1
});
sets.referrers = new WeightedList({
'www.slate.com': 50,
'twitter.com': 35,
'facebook.com': 20,
'nytimes.com': 10
});
sets.userAgents = new WeightedList({
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)': 30,
'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.50 Safari/534.24': 35,
'Mozilla/5.0 (X11; Linux x86_64; rv:6.0a1) Gecko/20110421 Firefox/6.0a1': 40
});
sets.types = new WeightedList({
'nginx': 1,
'apache': 4
});
return _.mapValues(sets, function (set) {
return (typeof set === 'function') ? set : function () {
return set.get();
};
});
};