apminsight
Version:
monitor nodejs applications
405 lines (384 loc) • 15.7 kB
JavaScript
var process = require("process");
const licenseKey = "license.key",
appNameKey = "application.name",
appPortKey = "application.port",
defaultAppName = "My Node Application",
usCollectorHostName = "plusinsight.site24x7.com",
euCollectorHostName = "plusinsight.site24x7.eu",
cnCollectorHostName = "plusinsight.site24x7.cn",
indCollectorHostName = "plusinsight.site24x7.in",
indHdfcCollectorHostName = "hdplusinsight.site24x7.in",
jpCollectorHostName = "plusinsight.site24x7.jp",
ausCollectorHostName = "plusinsight.site24x7.net.au",
caCollectorHostName = "plusinsight.site24x7.ca",
ukCollectorHostName = "plusinsight.site24x7.uk",
saCollectorHostName = "plusinsight.site24x7.sa",
aeCollectorHostName = "plusinsight.site24x7.ae",
usRumStaticBeaconHostName =
"//static.site24x7rum.com/beacon/site24x7rum-min.js?appKey=", //No I18N
inRumStaticBeaconHostName =
"//static.site24x7rum.in/beacon/site24x7rum-min.js?appKey=", //No I18N
euRumStaticBeaconHostName =
"//static.site24x7rum.eu/beacon/site24x7rum-min.js?appKey=", //No I18N
ausRumStaticBeaconHostName =
"//static.site24x7rum.com.au/beacon/site24x7rum-min.js?appKey=", //No I18N
cnRumStaticBeaconHostName =
"//static.site24x7rum.cn/rum/resources/beacon/site24x7rum-min.js?appKey=", //No I18N
rumBeacon =
'<script type="text/javascript">(function(w,d,s,r,k,h,m){if(w.performance && w.performance.timing && w.performance.navigation) {w[r] = w[r] || function(){(w[r].q = w[r].q || []).push(arguments)};h=d.createElement("script");h.async=true;h.setAttribute("src",s+k);d.getElementsByTagName("head")[0].appendChild(h);(m = window.onerror),(window.onerror = function (b, c, d, f, g) {m && m(b, c, d, f, g),g || (g = new Error(b)),(w[r].q = w[r].q || []).push(["captureException",g]);})}})(window,document,"{static_beacon}","s247r","{rum_key}");</script>', //No I18N
sslPort = "443",
httpPort = "80",
requestMethod = "POST",
connectUrl = "/arh/connect",
dataUrl = "/arh/data",
traceUrl = "/arh/trace",
nodeVmUrl = "/arh/nvm",
configUpdateUrl = "/arh/agent_config_update",
// configuration related keys
apdexTh = "apdex.threshold",
sqlCapture = "sql.capture.enabled",
sqlParametrize = "transaction.trace.sql.parametrize",
lastModifiedTime = "last.modified.time",
traceThreshold = "transaction.trace.threshold",
traceEnabled = "transaction.trace.enabled",
sqlStracktrace = "transaction.trace.sql.stacktrace.threshold",
webTxnSamplingFactor = "transaction.tracking.request.interval",
autoUpgrade = "autoupgrade.enabled",
txnSkipListeningKey = "transaction.skip.listening",
txnSkip = "transaction.skip.patterns",
txnGrouping = "transaction.grouping",
txnTrackerDropThKey = "webtransaction.tracker.drop.threshold",
txnTraceExtCountThKey =
"webtransaction.trace.external.components.count.threshold",
captureHttpParams = "webtransaction.trace.input.params.record",
captureHttpHeaders = "webtransaction.trace.request.headers.record",
requestHeadersIgnore = "webtransaction.trace.request.headers.ignore",
httpErrorCodesIgnore = "http.errors.ignore",
httpErrorCodesTrack = "http.errors.track",
txnNormalizationRegex = /\/\d+(?=\/)/g,
bgTxnTrackingEnabled = "bgtransaction.tracking.enabled",
bgTxnTraceEnabled = "bgtransaction.trace.enabled",
bgTxnTraceTh = "bgtransaction.trace.threshold",
bgTxnSamplingFactor = "bgtransaction.tracking.request.interval",
keyTxnList = "transaction.key.transactions",
distributedTracingKey = "distributed.tracing.enabled",
crossAppReqHeader = "X-Site24x7-Id",
crossAppReqHeaderLower = crossAppReqHeader.toLowerCase(),
crossAppResHeader = "X-Site24x7-Dt-Data",
crossAppResHeaderLower = crossAppResHeader.toLowerCase(),
rumIntegrationAppKey = "X-SITE24X7-RUM-APPKEY",
rumIntegrationAppKeyLower = rumIntegrationAppKey.toLowerCase(),
rumIntegrationTraceId = "X-SITE24X7-RUM-TRACEID",
rumIntegrationTraceIdLower = rumIntegrationTraceId.toLowerCase(),
syntheticMonitoringKey = "Site24x7SyntheticKey",
syntheticMonitoringKeyLower = syntheticMonitoringKey.toLowerCase(),
contentLengthHeaderKey = "content-length",
// Add delay constants for request scheduling
nodeVmDelay = 3000,
traceDataDelay = 6000,
configUpdateDelay = 9000,
// agent specific configurations
logLevel = "apminsight.log.level",
appGroupName = "application.group.name",
tags = "tags",
// metrics store keys
apdexMetric = "metricstore.metric.bucket.size",
dbMetric = "metricstore.dbmetric.bucket",
bgMetric = "metricstore.bgmetric.bucket.size",
traceSize = "transaction.tracestore.size",
// log levels
info = "INFO",
warning = "WARNING",
debug = "DEBUG",
critical = "CRITICAL",
error = "ERROR",
// metric keys
agentInfo = "agent_info",
applicationType = "NODEJS",
agentInstallPath = "AgentInstallPath",
instanceInfo = "instance-info",
instanceId = "instanceid",
instance_Id = "instance_id",
instanceDotId = "instance.id",
responseCode = "response-code",
host = "host",
port = "port",
customConfigInfo = "custom_config_info",
agentSpecifInfo = "agent_specific_info",
txnSpecificInfo = "transaction_specific_config",
//connect payload keys
isAutoScaleEnabled = "is.autoscale.environment",
agentVersion = "agent.version",
agentVersionInfo = "agent.version.info",
applicationTypeKey = "application.type",
hostType = "host.type",
hostLicenseApply = "hostlicense.apply",
cloudInstanceId = "cloud.instance.id",
fqdn = "fqdn",
serverMonitorKey = "server.monitor.key",
// Environment section keys
userName = "UserName",
osVersion = "OSVersion",
machineName = "MachineName",
nodejsVersion = "NODEJS version",
osArch = "OSArch",
os = "OS",
ipAddress = "IP",
portNumber = "port",
hostname = "hostname",
// response codes
licenseExpired = 701,
licenseInstanceExceeded = 702,
instanceAddFailed = 703,
deleteAgent = 900,
invalidAgent = 901,
unmanageAgent = 910,
manageAgent = 911,
agentLicenseUpdated = 915,
agentConfigUpdated = 920,
shutdown = 0,
// namespace
oneAgentSectionInfo = "apminsight_auto_profiler",
oneAgentLicenseKey = "APMINSIGHT_LICENSEKEY",
oneAgentIV = "APMINSIGHT_AGENT_ID",
oneAgentSaltKey = "APMINSIGHT_AGENT_START_TIME",
oneAgentNodeSpecificDir = "NODE",
oneAgentServerMonitorKey = "SERVER_MONITOR_KEY",
webTxnPrefix = "transaction/http/",
bgTxnPrefix = "transaction/bckgrnd/",
apdex = "apdex",
bckgrnd = "bckgrnd",
appParam = "appparam",
sumStr = "sum",
avgStr = "average",
emptyString = "",
homeDir = process.env.HOME || process.env.USERPROFILE,
externalComponents = [
"MYSQL",
"PGSQL",
"MEMCACHED",
"MONGODB",
"REDIS",
"CASSANDRA",
"HTTP",
"MSSQL",
"ORACLEDB",
"ELASTICSEARCH"
],
dbOpnOverAll = "db/all/all/dummy-db",
maxTrackers = 1000,
maxExcPerTrace = 20,
dbTracker = 1,
esTracker = "esTracker",
selectQueryMatcher = /\s*(select)\s+.*from\s+(\S+)?.*/i,
insertQueryMatcher = /\s*(insert)\s+into\s+(\S+)?[(]?.*/i,
updateQueryMatcher = /\s*(update)\s+(\S+)?.*/i,
deleteQueryMatcher = /\s*(delete)\s+.*from\s+(\S+)?.*/i,
createQueryMatcher =
/\s*(create)\s+(?:table|procedure|database|index)\s+(\S+)?[(]?.*/i,
dropQueryMatcher = /\s*(drop)\s+(?:table|procedure|database|index)\s+(\S+)?.*/i,
alterQueryMatcher = /\s*(alter)\s+(?:table|procedure|database|index)\s+(\S+)?.*/i,
callSPMatcher = /\s*(call)\s+([`\w]+)[\s()]*.*/i,
execSPMatcher = /\s*(exec)\s+([`\w]+)[\s()]*.*/i,
showQueryMatcher = /\s*(show)\s+(\w+)(\s+)?.*/i,
firstSyllable = /\s*(\w+)\s+.*/i,
stackTraceRegex = /^\s*at .*(\S+:\d+)/m,
dbOpnRegex = {
select: selectQueryMatcher,
insert: insertQueryMatcher,
update: updateQueryMatcher,
delete: deleteQueryMatcher,
create: createQueryMatcher,
drop: dropQueryMatcher,
alter: alterQueryMatcher,
show: showQueryMatcher,
call: callSPMatcher,
exec: execSPMatcher
},
site24x7LicenseRegex =
/^((us|eu|cn|in|in_hd|au|aa|ab|gd|jp|ca|uk|sa|ae)_)?[a-f0-9\s]{0,100}$/,
appManagerLicenseRegex = /^APMI_[A-Fa-f0-9]{64}$/,
oracleSimpleConnectStringRegex = /^([^:/]+)(?::(\d+))?\//,
oracleDescriptionConnectStringRegex = /HOST=([^)]*)\).*?PORT=(\d+)/,
applicationGroupRegex = /^[\p{L}\p{N}.\-\\_\s:;=&+!@#$%^*()\[\]{}'",/?~`|]{0,1024}$/u,
oneAgentProxyUrlRegex = /^(?:(.*?):(.*?)@)?([^:]+):(\d+)$/,
initVector = "745731af4484f323",
securitykey = "4cac4540992d51feeaefe4668bbfed72",
// Exporter related keys
s247DataExporterHost = "localhost",
s247DataExporterStatusPort = 20021,
s247DataExporterDataPort = 20022,
isDataExporterEnabled = false,
s247DataExporterTxnName = "txn.name",
traceIdBytes = 16, //16*2 bytes length will be generated
spanIdBytes = 8, //8*2 bytes length will be generated
// Connection error codes that warrant reconnection
connectionErrors = [
'EPIPE', 'ECONNRESET', 'ENOTCONN', 'ECONNABORTED',
'ECONNREFUSED', 'ETIMEDOUT', 'EHOSTUNREACH', 'ENETUNREACH'
];
module.exports = {
licenseKey: licenseKey,
appNameKey: appNameKey,
appPortKey: appPortKey,
defaultAppName : defaultAppName,
connectUrl: connectUrl,
dataUrl: dataUrl,
traceUrl: traceUrl,
nodeVmUrl: nodeVmUrl,
configUpdateUrl: configUpdateUrl,
usCollectorHostName: usCollectorHostName,
euCollectorHostName: euCollectorHostName,
cnCollectorHostName: cnCollectorHostName,
indCollectorHostName: indCollectorHostName,
indHdfcCollectorHostName: indHdfcCollectorHostName,
jpCollectorHostName: jpCollectorHostName,
ausCollectorHostName: ausCollectorHostName,
caCollectorHostName: caCollectorHostName,
ukCollectorHostName: ukCollectorHostName,
saCollectorHostName: saCollectorHostName,
aeCollectorHostName: aeCollectorHostName,
collectorPort: sslPort,
httpPort: httpPort,
requestMethod: requestMethod,
apdexThKey: apdexTh,
sqlCaptureKey: sqlCapture,
sqlParametrizeKey: sqlParametrize,
lastModifiedTimeKey: lastModifiedTime,
traceThresholdKey: traceThreshold,
traceEnabledKey: traceEnabled,
sqlStracktraceKey: sqlStracktrace,
webTxnsamplingFactorKey: webTxnSamplingFactor,
autoUpgradeKey: autoUpgrade,
txnSkipListeningKey: txnSkipListeningKey,
txnSkip: txnSkip,
txnGrouping: txnGrouping,
txnTrackerDropThKey: txnTrackerDropThKey,
txnTraceExtCountThKey: txnTraceExtCountThKey,
captureHttpParams: captureHttpParams,
captureHttpHeaders: captureHttpHeaders,
requestHeadersIgnore: requestHeadersIgnore,
txnNormalizationRegex: txnNormalizationRegex,
httpErrorCodesIgnore: httpErrorCodesIgnore,
httpErrorCodesTrack: httpErrorCodesTrack,
bgTxnTrackingEnabledKey: bgTxnTrackingEnabled,
bgTxnSamplingFactorKey: bgTxnSamplingFactor,
bgTxnTraceEnabledKey: bgTxnTraceEnabled,
bgTxnTraceThKey: bgTxnTraceTh,
keyTxnList: keyTxnList,
distributedTracingKey: distributedTracingKey,
crossAppReqHeader: crossAppReqHeader,
crossAppReqHeaderLower: crossAppReqHeaderLower,
crossAppResHeader: crossAppResHeader,
crossAppResHeaderLower: crossAppResHeaderLower,
rumIntegrationAppKey: rumIntegrationAppKey,
rumIntegrationAppKeyLower: rumIntegrationAppKeyLower,
rumIntegrationTraceId: rumIntegrationTraceId,
rumIntegrationTraceIdLower: rumIntegrationTraceIdLower,
syntheticMonitoringKey: syntheticMonitoringKey,
syntheticMonitoringKeyLower: syntheticMonitoringKeyLower,
contentLengthHeader: contentLengthHeaderKey,
// Add the exported delay constants
nodeVmDelay: nodeVmDelay,
traceDataDelay: traceDataDelay,
configUpdateDelay: configUpdateDelay,
apdexMetricKey: apdexMetric,
dbMetricKey: dbMetric,
bgMetricKey: bgMetric,
traceMetricKey: traceSize,
info: info,
warning: warning,
critical: critical,
error: error,
debug: debug,
agentInfo: agentInfo,
applicationType: applicationType,
agentInstallPath: agentInstallPath,
host: host,
port: port,
instanceInfo: instanceInfo,
instanceid: instanceId,
instance_Id: instance_Id,
instanceDotId: instanceDotId,
responseCode: responseCode,
customConfigInfo: customConfigInfo,
agentSpecifInfo: agentSpecifInfo,
txnSpecificInfo: txnSpecificInfo,
isAutoScaleEnabled: isAutoScaleEnabled,
agentVersion: agentVersion,
agentVersionInfo: agentVersionInfo,
applicationTypeKey: applicationTypeKey,
hostType: hostType,
hostLicenseApply: hostLicenseApply,
cloudInstanceId: cloudInstanceId,
fqdn: fqdn,
serverMonitorKey: serverMonitorKey,
userName: userName,
osVersion: osVersion,
machineName: machineName,
nodejsVersion: nodejsVersion,
osArch: osArch,
os: os,
ipAddress: ipAddress,
portNumber: portNumber,
hostname: hostname,
logLevel: logLevel,
appGroupName: appGroupName,
tags: tags,
licenseExpired: licenseExpired,
instanceAddFailed: instanceAddFailed,
licenseInstanceExceeded: licenseInstanceExceeded,
deleteAgent: deleteAgent,
invalidAgent: invalidAgent,
unmanageAgent: unmanageAgent,
manageAgent: manageAgent,
agentConfigUpdated: agentConfigUpdated,
agentLicenseUpdated: agentLicenseUpdated,
shutdown: shutdown,
oneAgentSectionInfo: oneAgentSectionInfo,
oneAgentLicenseKey: oneAgentLicenseKey,
oneAgentIV: oneAgentIV,
oneAgentSaltKey: oneAgentSaltKey,
oneAgentNodeSpecificDir: oneAgentNodeSpecificDir,
oneAgentServerMonitorKey: oneAgentServerMonitorKey,
webTxnPrefix: webTxnPrefix,
bgTxnPrefix: bgTxnPrefix,
apdex: apdex,
bckgrnd: bckgrnd,
appParam: appParam,
sumStr: sumStr,
avgStr: avgStr,
emptyString: emptyString,
homeDir: homeDir,
maxTrackers: maxTrackers,
maxExcPerTrace: maxExcPerTrace,
dbTracker: dbTracker,
esTracker: esTracker,
externalComponents: externalComponents,
dbOpnOverAll: dbOpnOverAll,
dbOpnRegex: dbOpnRegex,
firstSyllable: firstSyllable,
stackTraceRegex: stackTraceRegex,
site24x7LicenseRegex: site24x7LicenseRegex,
appManagerLicenseRegex: appManagerLicenseRegex,
oracleSimpleConnectStringRegex: oracleSimpleConnectStringRegex,
oracleDescriptionConnectStringRegex: oracleDescriptionConnectStringRegex,
oneAgentProxyUrlRegex: oneAgentProxyUrlRegex,
applicationGroupRegex: applicationGroupRegex,
initVector: initVector,
securitykey: securitykey,
usRumStaticBeaconHostName: usRumStaticBeaconHostName,
euRumStaticBeaconHostName: euRumStaticBeaconHostName,
cnRumStaticBeaconHostName: cnRumStaticBeaconHostName,
ausRumStaticBeaconHostName: ausRumStaticBeaconHostName,
inRumStaticBeaconHostName: inRumStaticBeaconHostName,
rumBeacon: rumBeacon,
s247DataExporterStatusPort: s247DataExporterStatusPort,
s247DataExporterDataPort: s247DataExporterDataPort,
isDataExporterEnabled: isDataExporterEnabled,
s247DataExporterHost: s247DataExporterHost,
s247DataExporterTxnName: s247DataExporterTxnName,
traceIdBytes: traceIdBytes,
spanIdBytes: spanIdBytes,
connectionErrors: connectionErrors
};