Authored by htoooth

parse useragent

... ... @@ -2,6 +2,7 @@ const msg2row = require('./msg2row');
const Sender = require('influx-batch-sender');
const MysqlSender = require('../lib/mysql-sender');
const ipService = require('./ip-service');
const useragent = require('useragent');
const _ = require('lodash');
... ... @@ -110,6 +111,8 @@ function handleClientFirst(scope, item) {
}
async function handleClientTiming(scope, item) {
const agent = useragent.lookup(scope.useragent);
const data = {
app: scope.app,
reqid: item.rid,
... ... @@ -129,9 +132,13 @@ async function handleClientTiming(scope, item) {
pageLoadTime: _.parseInt(item.rrt),
screenWidth: _.parseInt(item.sw),
screenHeight: _.parseInt(item.sh),
os: item.pf,
useragent: scope.useragent,
os: item.pf,
ip: scope.ip,
browserName: agent.family,
browserVersion: agent.toVersion(),
osName: agent.family,
osVersion: agent.toVersion()
};
const ipInfo = await ipService.getIsp(scope.ip).catch(() => {});
... ...
... ... @@ -26,6 +26,7 @@
"request-promise": "^4.2.1",
"source-map": "^0.5.7",
"url": "^0.11.0",
"useragent": "^2.3.0",
"yoho-node-lib": "^0.5.24"
},
"devDependencies": {
... ...
const useragnet = require('useragent');
const us = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36';
const result = useragnet.lookup(us);
console.log(result.family, result.toVersion());
console.log(result.os.family, result.os.toVersion());
... ...