|
|
const lineparse = require('../lib/line-parse');
|
|
|
|
|
|
const Sender = require('influx-batch-sender');
|
|
|
const MysqlSender = require('../lib/mysql-sender');
|
|
|
const config = require('../common/config');
|
|
|
const msg2row = require('./msg2row');
|
|
|
const lineparse = require('../lib/line-parse');
|
|
|
|
|
|
const errorSender = new MysqlSender(config.table.error);
|
|
|
const slowRouterSender = new MysqlSender(config.table.slow);
|
|
|
|
|
|
const influxSender = new Sender(config.reportRoute);
|
|
|
const routeSender = new Sender(config.reportRoute);
|
|
|
const apiSender = new Sender(config.reportApi);
|
|
|
|
|
|
const server = {
|
|
|
async handle(data) {
|
...
|
...
|
@@ -18,43 +18,40 @@ const server = { |
|
|
if (m.measurement === 'web-server-duration') {
|
|
|
let duration = parseInt(m.fields.duration);
|
|
|
|
|
|
if (duration > config.slowRoute.min || duration < config.slowRoute.max) {
|
|
|
if (duration > config.slowRoute.min && duration < config.slowRoute.max) {
|
|
|
slowRouterSender.addMessage(msg2row.slowRouter(m));
|
|
|
}
|
|
|
|
|
|
if (m.tags.type.toLowerCase() === 'api') {
|
|
|
influxSender.addMessage({
|
|
|
measurement: 'api-info',
|
|
|
apiSender.addMessage({
|
|
|
tags: {
|
|
|
app: m.tags.app,
|
|
|
hostname: m.tags.hostname,
|
|
|
host: m.tags.hostname,
|
|
|
api: m.tags.api
|
|
|
},
|
|
|
fields: {
|
|
|
duration: m.duration,
|
|
|
duration: duration,
|
|
|
times: 1
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (m.tags.type.toLowerCase() === 'route') {
|
|
|
influxSender.addMessage({
|
|
|
measurement: 'route-info',
|
|
|
routeSender.addMessage({
|
|
|
tags: {
|
|
|
app: m.tags.app,
|
|
|
hostname: m.tags.hostname,
|
|
|
host: m.tags.hostname,
|
|
|
route: m.tags.route
|
|
|
|
|
|
},
|
|
|
fields: {
|
|
|
duration: m.duration
|
|
|
duration: duration
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
} else if (m.measurement === 'error-report') {
|
|
|
errorSender.addMessage(msg2row.errorRouter(m));
|
|
|
} else if (m.measurement === 'process-info') {
|
|
|
influxSender.addMessage(m);
|
|
|
routeSender.addMessage(m);
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
|