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