Skip to content

Instantly share code, notes, and snippets.

@mikekunze
Created September 12, 2011 21:44
Show Gist options
  • Save mikekunze/1212551 to your computer and use it in GitHub Desktop.
Save mikekunze/1212551 to your computer and use it in GitHub Desktop.
Using Async to parse many metrics log files
var populateMetrics = function() {
metricsFiles = [];
var addMetric = function(file, callback) {
fs.stat(path + '/' + file, function(err, stats) {
if(stats.isDirectory()) {
fs.stat(path + '/' + file + '/Metrics.txt', function(err, stats) {
if(err) {
callback();
} else {
metricsFiles.push(path + '/' + file + '/Metrics.txt');
callback();
}
})
} else callback();
});
};
fs.readdir(path, function(err, files) {
if(err) console.log(err);
async.forEach(files, addMetric, function(err) {
if(err) console.log(err);
console.log('************************\n' + metricsFiles.length + ' metric files found');
scanMetrics();
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment