Authored by 周奇琪

加oneapm的监控

@@ -5,6 +5,13 @@ @@ -5,6 +5,13 @@
5 */ 5 */
6 'use strict'; 6 'use strict';
7 7
  8 +const config = require('./config/common');
  9 +
  10 +// use one apm
  11 +if (config.useOneapm) {
  12 + require('oneapm');
  13 +}
  14 +
8 let express = require('express'), 15 let express = require('express'),
9 path = require('path'), 16 path = require('path'),
10 bodyParser = require('body-parser'), 17 bodyParser = require('body-parser'),
@@ -5,6 +5,10 @@ @@ -5,6 +5,10 @@
5 * @date 2016/05/06 5 * @date 2016/05/06
6 */ 6 */
7 7
  8 +
  9 +const isProduction = process.env.NODE_ENV === 'production';
  10 +const isTest = process.env.NODE_ENV === 'test';
  11 +
8 module.exports = { 12 module.exports = {
9 siteUrl: 'http://m.yohobuy.com', 13 siteUrl: 'http://m.yohobuy.com',
10 domains: { 14 domains: {
@@ -12,14 +16,17 @@ module.exports = { @@ -12,14 +16,17 @@ module.exports = {
12 service: 'http://testservice.yoho.cn:28077/' 16 service: 'http://testservice.yoho.cn:28077/'
13 }, 17 },
14 loggers: { 18 loggers: {
15 - file: { 19 + infoFile: {
  20 + name: 'info',
16 level: 'info', 21 level: 'info',
17 - maxsize: 100 * 1024 * 1024,  
18 - handleExceptions: true,  
19 - zippedArchive: true,  
20 - timestamp: true,  
21 filename: 'info.log' 22 filename: 'info.log'
22 }, 23 },
  24 + errorFile: {
  25 + name: 'error',
  26 + level: 'error',
  27 + filename: 'error.log',
  28 + handleExceptions: true
  29 + },
23 udp: { // send by udp 30 udp: { // send by udp
24 level: 'debug', // logger level 31 level: 'debug', // logger level
25 host: '192.168.102.162', // influxdb host 32 host: '192.168.102.162', // influxdb host
@@ -32,3 +39,15 @@ module.exports = { @@ -32,3 +39,15 @@ module.exports = {
32 } 39 }
33 } 40 }
34 }; 41 };
  42 +
  43 +if (isProduction) {
  44 + Object.assign(module.exports, {
  45 + appName: 'm.yohobuy.com',
  46 + useOneapm: true
  47 + });
  48 +} else if (isTest) {
  49 + Object.assign(module.exports, {
  50 + appName: 'm.yohobuy.com for test',
  51 + useOneapm: true
  52 + });
  53 +}
@@ -14,8 +14,8 @@ @@ -14,8 +14,8 @@
14 14
15 let logger = new (winston.Logger)({ 15 let logger = new (winston.Logger)({
16 transports: [ 16 transports: [
17 - // new (FileTransport)(config.loggers.infoFile),  
18 - // new (FileTransport)(config.loggers.errorFile), 17 + new (FileTransport)(config.loggers.infoFile),
  18 + new (FileTransport)(config.loggers.errorFile),
19 new (winston.transports.UdpTransport)(config.loggers.udp), 19 new (winston.transports.UdpTransport)(config.loggers.udp),
20 new (winston.transports.Console)(config.loggers.console) 20 new (winston.transports.Console)(config.loggers.console)
21 ] 21 ]
  1 +// use for app name
  2 +const commonConfig = require('./config/common');
  3 +
  4 +/**
  5 + * OneAPM agent configuration.
  6 + *
  7 + * See lib/config.defaults.js in the agent distribution for a more complete
  8 + * description of configuration variables and their potential values.
  9 + */
  10 +exports.config = {
  11 + /**
  12 + * Array of application names.
  13 + */
  14 + app_name : [commonConfig.appName], // eslint-disable-line
  15 + /**
  16 + * Your OneAPM license key.
  17 + */
  18 + license_key : 'BwEGA1dRDlQ6357HHQ1AD1xJVkbc9fNfWRtQUwhQG41c5QFWGFIDSQoHc0e8AgMaUlcUVw0=',// eslint-disable-line
  19 + logging : { // eslint-disable-line
  20 + /**
  21 + * Level at which to log. 'trace' is most useful to OneAPM when diagnosing
  22 + * issues with the agent, 'info' and higher will impose the least overhead on
  23 + * production applications.
  24 + */
  25 + level : 'info'// eslint-disable-line
  26 + },
  27 + transaction_events: {// eslint-disable-line
  28 + enabled: true// eslint-disable-line
  29 + }
  30 +};
@@ -38,6 +38,7 @@ @@ -38,6 +38,7 @@
38 "lodash": "^4.12.0", 38 "lodash": "^4.12.0",
39 "md5": "^2.1.0", 39 "md5": "^2.1.0",
40 "morgan": "^1.7.0", 40 "morgan": "^1.7.0",
  41 + "oneapm": "^1.2.20",
41 "request-promise": "^3.0.0", 42 "request-promise": "^3.0.0",
42 "serve-favicon": "^2.3.0", 43 "serve-favicon": "^2.3.0",
43 "winston": "^2.2.0", 44 "winston": "^2.2.0",