this._questionCallback = null;
this.setPrompt(this._oldPrompt);
cb(line);
} else {
this.emit('line', line);
}
};
保存的数据需要进行分析比如哪个IP访问最多哪条错误最多可以用聚合来进行分析贴出示例分析某个IP在某一天访问出错最多的原因
db.logs.aggregate(
// Pipeline
[
// Stage 1
{
$group: {
'_id': { 'client': '114.112.163.28', 'server': '$server', 'error': '$error', 'url': '$url', 'upstream': '$upstream','date':'$date' ,'msg':'$msg' } , 'date':{'$addToSet':'$date'},
count: { '$sum': 1 }
}
},
// Stage 2
{
$match: {
count: { $gte: 1 },
date: ['2019-05-10']
}
},
{
$sort: {
count: -1
}
},
],
// Options
{
cursor: {
batchSize: 50
},
allowDiskUse: true
}
);
总结
以上所述是小编给大家介绍的NodeJS读取分析Nginx错误日志的方法,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!









