UNPKG

3.88 kBJavaScriptView Raw
1/**
2 * Created by bala on 10/7/15.
3 */
4var njstrace = require('./lib/njstrace/njsTrace');
5var agentSetting = require("./lib/agent-setting");
6var path = require('path');
7var logStream = 'OUTPUT_STREAM'
8var util = require('./lib/util');
9var cluster = require('cluster'),
10 instrumentationFile,customInstrumenattionProfile;
11var NDControlConnectionManager = require('./lib/NDConnectionManager')
12NJSInstrument.prototype.instrument = function instrument(args)
13{
14 try
15 {
16 var temp = process.env.CAV_LOGS ? process.env.CAV_LOGS : logStream;
17 if(temp == 'BOTH' || temp == 'FILE' )
18 logStream = temp;
19
20 if(args){
21 if(!args.logLevel)
22 args.logLevel = 'info'
23 if(!args.BCILoggingMode)
24 args.BCILoggingMode = logStream
25 if(args.BCILoggingMode !== logStream && args.BCILoggingMode !== 'BOTH' && args.BCILoggingMode !== 'FILE')
26 args.BCILoggingMode = logStream
27 }
28 else{
29 args = {logLevel : 'info' , BCILoggingMode : logStream}
30 }
31
32 if(cluster.isMaster) {
33 util.initializeLogger(args.logLevel, args.BCILoggingMode)
34 }
35 else {
36 agentSetting.clusterMode =true;
37 agentSetting.settingFileMode = 'SHARED' //Changing file mode to shared, so need to write Tier Server Instance name send by ndc in ndsettings.conf file.
38 util.initializeLogger(args.logLevel, args.BCILoggingMode);
39 }
40 agentSetting.initAllMap(args);
41 agentSetting.readSettingFile(); //reading ndsetting file to connect with NS
42
43 /*
44 In cluster mode, Instance filed will be generated by agent only in EXCLUSIVE mode in Shared mode, auto scale feature will be
45 used to generate instance by NDC
46 This check will work only in those case, if auto scaling is not working in instance is sunning in cluster
47 mode, then we will provide "EXCLUSIVE" mode in ndsetting.conf .
48 */
49 if(agentSetting.enableMultiInstMode) //This code is commenting because now we have autoscaling feature .
50 agentSetting.isCluster();
51
52 //njstrace.inject(null,instrumentationFile);
53 //njstrace.inject(null,agentSetting.instrumentationMap);
54 //agentSetting.parseInstrProfile(data)
55 try {
56 instrumentationFile = require('./../../nodeInstr.json'); //Getting Instrumentation profile from server side
57 }catch(err){util.logger.warn("No instrumentation profile present ")}
58
59 var instPrfParseobj = require('./lib/njstrace/instrumentationProfleParser');
60 if(instrumentationFile)
61 instPrfParseobj.parseInstrFile(instrumentationFile) //parsing Instrumentation profile
62 else{
63 try {
64 customInstrumenattionProfile = require('./lib/utils/customNodeInstr.json'); //Getting Instrumentation profile from server side
65 }catch(err){util.logger.warn("No instrumentation profile present ")}
66 instPrfParseobj.parseInstrFile(customInstrumenattionProfile)
67 }
68 if(agentSetting.agentMode >= 3) {
69 njstrace.inject(null,instPrfParseobj.getInstrMap(),agentSetting.enableWraping); //injecting our code into applications code
70 }
71 if(agentSetting.agentMode >= 2){
72 require('./lib/nodetime/index').profile();
73 }
74
75 agentSetting.generateFPMask();
76 process.nextTick(function(){
77 try {
78 if(agentSetting.agentMode > 0)
79 NDControlConnectionManager.checkProtocolAndMakeConnection()
80 }
81 catch(e){
82 util.logger.warn(e);
83 }
84 },1000);
85
86 }
87 catch(err){
88 console.log(err);
89 }
90};
91
92function NJSInstrument()
93{
94
95}
96
97module.exports = new NJSInstrument();