newrelic 8.3.0 → 8.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/NEWS.md +34 -0
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/api.js +74 -68
  4. package/bin/test-naming-rules.js +22 -22
  5. package/lib/agent.js +4 -4
  6. package/lib/attributes.js +2 -2
  7. package/lib/collector/api.js +12 -12
  8. package/lib/collector/facts.js +1 -1
  9. package/lib/collector/http-agents.js +12 -11
  10. package/lib/collector/key-parser.js +1 -1
  11. package/lib/collector/remote-method.js +27 -26
  12. package/lib/config/attribute-filter.js +23 -23
  13. package/lib/config/default.js +12 -10
  14. package/lib/config/hsm.js +1 -1
  15. package/lib/config/index.js +82 -66
  16. package/lib/config/lasp.js +3 -3
  17. package/lib/config/merge-server-config.js +1 -1
  18. package/lib/db/parse-sql.js +8 -8
  19. package/lib/db/parsed-statement.js +9 -8
  20. package/lib/db/query-parsers/sql.js +7 -7
  21. package/lib/db/query-sample.js +9 -9
  22. package/lib/db/query-trace-aggregator.js +4 -4
  23. package/lib/db/statement-matcher.js +5 -5
  24. package/lib/db/utils.js +1 -1
  25. package/lib/environment.js +43 -43
  26. package/lib/errors/error-collector.js +2 -2
  27. package/lib/errors/error-trace-aggregator.js +1 -1
  28. package/lib/errors/helper.js +3 -3
  29. package/lib/errors/index.js +17 -17
  30. package/lib/header-attributes.js +6 -6
  31. package/lib/header-processing.js +1 -1
  32. package/lib/instrumentation/amqplib.js +26 -26
  33. package/lib/instrumentation/bluebird.js +3 -3
  34. package/lib/instrumentation/cassandra-driver.js +7 -3
  35. package/lib/instrumentation/connect.js +4 -4
  36. package/lib/instrumentation/core/async_hooks.js +6 -6
  37. package/lib/instrumentation/core/domain.js +2 -2
  38. package/lib/instrumentation/core/globals.js +1 -1
  39. package/lib/instrumentation/core/http-outbound.js +14 -83
  40. package/lib/instrumentation/core/http.js +34 -67
  41. package/lib/instrumentation/core/inspector.js +2 -2
  42. package/lib/instrumentation/core/timers.js +7 -7
  43. package/lib/instrumentation/core/zlib.js +2 -2
  44. package/lib/instrumentation/director.js +4 -4
  45. package/lib/instrumentation/express.js +8 -8
  46. package/lib/instrumentation/generic-pool.js +1 -1
  47. package/lib/instrumentation/hapi/hapi-17.js +11 -11
  48. package/lib/instrumentation/hapi/shared.js +1 -1
  49. package/lib/instrumentation/hapi.js +22 -22
  50. package/lib/instrumentation/ioredis.js +7 -7
  51. package/lib/instrumentation/memcached.js +7 -7
  52. package/lib/instrumentation/mongodb/common.js +4 -1
  53. package/lib/instrumentation/mysql.js +19 -19
  54. package/lib/instrumentation/oracle.js +15 -15
  55. package/lib/instrumentation/pg.js +4 -4
  56. package/lib/instrumentation/promise.js +46 -46
  57. package/lib/instrumentation/q.js +2 -2
  58. package/lib/instrumentation/redis.js +11 -11
  59. package/lib/instrumentation/restify.js +1 -1
  60. package/lib/instrumentation/vision.js +4 -4
  61. package/lib/instrumentation/when.js +3 -3
  62. package/lib/instrumentations.js +1 -1
  63. package/lib/logger.js +5 -5
  64. package/lib/metrics/index.js +15 -15
  65. package/lib/metrics/mapper.js +7 -7
  66. package/lib/metrics/normalizer/rule.js +9 -9
  67. package/lib/metrics/normalizer/tx_segment.js +17 -17
  68. package/lib/metrics/normalizer.js +22 -22
  69. package/lib/metrics/recorders/custom.js +5 -5
  70. package/lib/metrics/recorders/generic.js +3 -3
  71. package/lib/metrics/recorders/http.js +7 -7
  72. package/lib/metrics/recorders/http_external.js +7 -7
  73. package/lib/metrics/recorders/message-transaction.js +5 -6
  74. package/lib/metrics/recorders/other.js +5 -5
  75. package/lib/parse-proc-cpuinfo.js +18 -18
  76. package/lib/parse-proc-meminfo.js +2 -2
  77. package/lib/prioritized-attributes.js +2 -2
  78. package/lib/priority-queue.js +10 -10
  79. package/lib/reservoir.js +3 -3
  80. package/lib/sampler.js +26 -26
  81. package/lib/shim/datastore-shim.js +35 -32
  82. package/lib/shim/index.js +2 -2
  83. package/lib/shim/message-shim.js +47 -47
  84. package/lib/shim/promise-shim.js +1 -1
  85. package/lib/shim/shim.js +61 -61
  86. package/lib/shim/specs/index.js +3 -3
  87. package/lib/shim/transaction-shim.js +44 -192
  88. package/lib/shim/webframework-shim.js +52 -52
  89. package/lib/spans/span-event.js +1 -1
  90. package/lib/spans/streaming-span-attributes.js +1 -1
  91. package/lib/stats/apdex.js +2 -2
  92. package/lib/stats/index.js +2 -2
  93. package/lib/system-info.js +23 -23
  94. package/lib/timer.js +5 -5
  95. package/lib/transaction/dt-payload.js +1 -1
  96. package/lib/transaction/index.js +40 -40
  97. package/lib/transaction/name-state.js +14 -14
  98. package/lib/transaction/trace/exclusive-time-calculator.js +6 -6
  99. package/lib/transaction/trace/index.js +14 -14
  100. package/lib/transaction/trace/segment.js +18 -18
  101. package/lib/transaction/tracecontext.js +1 -1
  102. package/lib/transaction/tracer/index.js +53 -49
  103. package/lib/uninstrumented.js +7 -7
  104. package/lib/util/arity.js +2 -2
  105. package/lib/util/byte-limit.js +4 -4
  106. package/lib/util/cat.js +269 -24
  107. package/lib/util/codec.js +2 -2
  108. package/lib/util/copy.js +2 -2
  109. package/lib/util/deep-equal.js +10 -10
  110. package/lib/util/flatten.js +4 -4
  111. package/lib/util/hashes.js +14 -14
  112. package/lib/util/label-parser.js +17 -17
  113. package/lib/util/logger.js +24 -24
  114. package/lib/util/process-version.js +2 -2
  115. package/lib/util/properties.js +4 -4
  116. package/lib/util/sql/obfuscate.js +15 -15
  117. package/lib/util/stream-sink.js +3 -3
  118. package/lib/util/unwrapped-core.js +2 -2
  119. package/lib/util/urltils.js +16 -16
  120. package/lib/utilization/aws-info.js +7 -7
  121. package/lib/utilization/azure-info.js +6 -6
  122. package/lib/utilization/common.js +13 -13
  123. package/lib/utilization/docker-info.js +11 -11
  124. package/lib/utilization/gcp-info.js +4 -4
  125. package/lib/utilization/index.js +5 -5
  126. package/lib/utilization/pcf-info.js +9 -9
  127. package/package.json +7 -2
  128. package/stub_api.js +8 -8
@@ -5,7 +5,7 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- var logger = require('../../logger').child({ component: 'tx_segment_normalizer' })
8
+ const logger = require('../../logger').child({ component: 'tx_segment_normalizer' })
9
9
 
10
10
  module.exports = TxSegmentNormalizer
11
11
 
@@ -33,21 +33,21 @@ function TxSegmentNormalizer() {
33
33
  * @return {NormalizationResults} - The results of normalizing the given path.
34
34
  */
35
35
  TxSegmentNormalizer.prototype.normalize = function normalize(path) {
36
- var currentTerm
37
- var prefix
38
- for (var i = 0; i < this.terms.length; i++) {
36
+ let currentTerm
37
+ let prefix
38
+ for (let i = 0; i < this.terms.length; i++) {
39
39
  currentTerm = this.terms[i]
40
40
  prefix = currentTerm.prefix
41
41
  if (path.lastIndexOf(prefix, 0) === -1) {
42
42
  continue
43
43
  }
44
- var fragment = path.slice(prefix.length)
45
- var parts = fragment.split('/')
46
- var result = []
47
- var prev
44
+ const fragment = path.slice(prefix.length)
45
+ const parts = fragment.split('/')
46
+ const result = []
47
+ let prev
48
+ let segment
48
49
 
49
- var segment
50
- for (var j = 0; j < parts.length; j++) {
50
+ for (let j = 0; j < parts.length; j++) {
51
51
  segment = parts[j]
52
52
 
53
53
  if (segment === '' && j + 1 === parts.length) {
@@ -87,10 +87,10 @@ TxSegmentNormalizer.prototype.load = function load(json) {
87
87
  }
88
88
 
89
89
  function filterRules(rules) {
90
- var map = Object.create(null)
90
+ const map = Object.create(null)
91
91
 
92
- for (var i = 0, l = rules.length; i < l; ++i) {
93
- var prefix = rules[i].prefix
92
+ for (let i = 0, l = rules.length; i < l; ++i) {
93
+ let prefix = rules[i].prefix
94
94
 
95
95
  if (!prefix || typeof prefix !== 'string') {
96
96
  continue
@@ -101,7 +101,7 @@ function filterRules(rules) {
101
101
  rules[i].prefix = prefix
102
102
  }
103
103
 
104
- var segments = prefix.split('/')
104
+ const segments = prefix.split('/')
105
105
  if (segments.length !== 3 || !segments[0] || !segments[1] || segments[3]) {
106
106
  continue
107
107
  }
@@ -111,10 +111,10 @@ function filterRules(rules) {
111
111
  }
112
112
  }
113
113
 
114
- var keys = Object.keys(map)
115
- var filtered = new Array(keys.length)
114
+ const keys = Object.keys(map)
115
+ const filtered = new Array(keys.length)
116
116
 
117
- for (i = 0, l = keys.length; i < l; ++i) {
117
+ for (let i = 0, l = keys.length; i < l; ++i) {
118
118
  filtered[i] = map[keys[i]]
119
119
  }
120
120
 
@@ -5,12 +5,12 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- var EventEmitter = require('events').EventEmitter
9
- var util = require('util')
10
- var logger = require('../logger').child({ component: 'metric_normalizer' })
11
- var deepEqual = require('../util/deep-equal')
12
- var NormalizerRule = require('./normalizer/rule')
13
- var NAMES = require('../metrics/names.js')
8
+ const EventEmitter = require('events').EventEmitter
9
+ const util = require('util')
10
+ const logger = require('../logger').child({ component: 'metric_normalizer' })
11
+ const deepEqual = require('../util/deep-equal')
12
+ const NormalizerRule = require('./normalizer/rule')
13
+ const NAMES = require('../metrics/names.js')
14
14
 
15
15
  function url(normalized, path, config) {
16
16
  if (normalized) {
@@ -91,7 +91,7 @@ MetricNormalizer.prototype.load = function load(json) {
91
91
 
92
92
  json.forEach((ruleJSON) => {
93
93
  // no need to add the same rule twice
94
- var rule = new NormalizerRule(ruleJSON)
94
+ const rule = new NormalizerRule(ruleJSON)
95
95
  if (!this.rules.find(deepEqual.bind(null, rule))) {
96
96
  this.rules.push(rule)
97
97
  logger.trace('Loaded %s normalization rule: %s', this.type, rule)
@@ -115,7 +115,7 @@ MetricNormalizer.prototype.load = function load(json) {
115
115
  * Operates via side effects.
116
116
  */
117
117
  MetricNormalizer.prototype.loadFromConfig = function loadFromConfig() {
118
- var rules = this.config.rules
118
+ const rules = this.config.rules
119
119
 
120
120
  if (rules && rules.name && rules.name.length > 0) {
121
121
  rules.name.forEach((rule) => {
@@ -126,9 +126,9 @@ MetricNormalizer.prototype.loadFromConfig = function loadFromConfig() {
126
126
  return logger.error({ rule: rule }, 'Simple naming rules require a replacement name.')
127
127
  }
128
128
 
129
- var precedence = rule.precedence
130
- var terminal = rule.terminate_chain
131
- var json = {
129
+ const precedence = rule.precedence
130
+ const terminal = rule.terminate_chain
131
+ const json = {
132
132
  match_expression: rule.pattern,
133
133
  eval_order: typeof precedence === 'number' ? precedence : 500,
134
134
  terminate_chain: typeof terminal === 'boolean' ? terminal : true,
@@ -138,8 +138,8 @@ MetricNormalizer.prototype.loadFromConfig = function loadFromConfig() {
138
138
  }
139
139
 
140
140
  // Find where the rule should be inserted and do so.
141
- var reverse = this.config.feature_flag.reverse_naming_rules
142
- var insert = this.rules.findIndex(function findRule(r) {
141
+ const reverse = this.config.feature_flag.reverse_naming_rules
142
+ const insert = this.rules.findIndex(function findRule(r) {
143
143
  return reverse ? r.precedence >= json.eval_order : r.precedence > json.eval_order
144
144
  })
145
145
  if (insert === -1) {
@@ -174,7 +174,7 @@ MetricNormalizer.prototype.addSimple = function addSimple(pattern, name) {
174
174
  return logger.error('Simple naming rules require a pattern.')
175
175
  }
176
176
 
177
- var json = {
177
+ const json = {
178
178
  match_expression: pattern,
179
179
  eval_order: 0,
180
180
  terminate_chain: true,
@@ -200,16 +200,16 @@ MetricNormalizer.prototype.addSimple = function addSimple(pattern, name) {
200
200
  * @returns {NormalizationResults} - The results of normalization.
201
201
  */
202
202
  MetricNormalizer.prototype.normalize = function normalize(path) {
203
- var last = path
204
- var length = this.rules.length
205
- var normalized
206
- var matched = false
207
- var ignored = false
203
+ let last = path
204
+ const length = this.rules.length
205
+ let normalized
206
+ let matched = false
207
+ let ignored = false
208
208
 
209
209
  // Apply each of our rules in turn.
210
- for (var i = 0; i < length; i++) {
211
- var rule = this.rules[i]
212
- var applied = rule.apply(last)
210
+ for (let i = 0; i < length; i++) {
211
+ const rule = this.rules[i]
212
+ const applied = rule.apply(last)
213
213
  if (!rule.matched) {
214
214
  continue
215
215
  }
@@ -5,13 +5,13 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- var NAMES = require('../names')
8
+ const NAMES = require('../names')
9
9
 
10
10
  function record(segment, scope) {
11
- var duration = segment.getDurationInMillis()
12
- var exclusive = segment.getExclusiveDurationInMillis()
13
- var transaction = segment.transaction
14
- var name = NAMES.CUSTOM + NAMES.ACTION_DELIMITER + segment.name
11
+ const duration = segment.getDurationInMillis()
12
+ const exclusive = segment.getExclusiveDurationInMillis()
13
+ const transaction = segment.transaction
14
+ const name = NAMES.CUSTOM + NAMES.ACTION_DELIMITER + segment.name
15
15
 
16
16
  if (scope) {
17
17
  transaction.measure(name, scope, duration, exclusive)
@@ -6,9 +6,9 @@
6
6
  'use strict'
7
7
 
8
8
  function record(segment, scope) {
9
- var duration = segment.getDurationInMillis()
10
- var exclusive = segment.getExclusiveDurationInMillis()
11
- var transaction = segment.transaction
9
+ const duration = segment.getDurationInMillis()
10
+ const exclusive = segment.getExclusiveDurationInMillis()
11
+ const transaction = segment.transaction
12
12
 
13
13
  if (scope) {
14
14
  transaction.measure(segment.name, scope, duration, exclusive)
@@ -16,19 +16,19 @@ function recordWeb(segment, scope) {
16
16
  return
17
17
  }
18
18
 
19
- var tx = segment.transaction
19
+ const tx = segment.transaction
20
20
  // if there was a nested webTransaction use its recorder instead
21
21
  if (tx.type === 'web' && tx.baseSegment && segment !== tx.baseSegment) {
22
22
  return
23
23
  }
24
24
 
25
- var duration = segment.getDurationInMillis()
26
- var totalTime = tx.trace.getTotalTimeDurationInMillis()
27
- var exclusive = segment.getExclusiveDurationInMillis()
28
- var partial = segment.partialName
29
- var config = segment.transaction.agent.config
25
+ const duration = segment.getDurationInMillis()
26
+ const totalTime = tx.trace.getTotalTimeDurationInMillis()
27
+ const exclusive = segment.getExclusiveDurationInMillis()
28
+ const partial = segment.partialName
29
+ const config = segment.transaction.agent.config
30
30
  // named / key transaction support requires per-name apdexT
31
- var keyApdexInMillis = config.web_transactions_apdex[scope] * TO_MILLIS || 0
31
+ const keyApdexInMillis = config.web_transactions_apdex[scope] * TO_MILLIS || 0
32
32
 
33
33
  tx.measure(NAMES.WEB.RESPONSE_TIME, null, duration, exclusive)
34
34
  tx.measure(NAMES.WEB.TOTAL_TIME, null, totalTime, exclusive)
@@ -5,16 +5,16 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- var EXTERNAL = require('../../metrics/names').EXTERNAL
8
+ const EXTERNAL = require('../../metrics/names').EXTERNAL
9
9
 
10
10
  function recordExternal(host, library) {
11
11
  return function externalRecorder(segment, scope) {
12
- var duration = segment.getDurationInMillis()
13
- var exclusive = segment.getExclusiveDurationInMillis()
14
- var transaction = segment.transaction
15
- var metricName = EXTERNAL.PREFIX + host + '/' + library
16
- var rollupType = transaction.isWeb() ? EXTERNAL.WEB : EXTERNAL.OTHER
17
- var rollupHost = EXTERNAL.PREFIX + host + '/all'
12
+ const duration = segment.getDurationInMillis()
13
+ const exclusive = segment.getExclusiveDurationInMillis()
14
+ const transaction = segment.transaction
15
+ const metricName = EXTERNAL.PREFIX + host + '/' + library
16
+ const rollupType = transaction.isWeb() ? EXTERNAL.WEB : EXTERNAL.OTHER
17
+ const rollupHost = EXTERNAL.PREFIX + host + '/all'
18
18
 
19
19
  if (segment.catId && segment.catTransaction) {
20
20
  transaction.measure(
@@ -5,19 +5,18 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- var NAMES = require('../../metrics/names.js')
8
+ const NAMES = require('../../metrics/names.js')
9
9
 
10
10
  function recordMessageTransaction(segment, scope) {
11
- var tx = segment.transaction
11
+ const tx = segment.transaction
12
12
  if (tx.type !== 'message' || tx.baseSegment !== segment) {
13
13
  return
14
14
  }
15
15
 
16
- var duration = segment.getDurationInMillis()
17
- var exclusive = segment.getExclusiveDurationInMillis()
18
- var totalTime = segment.transaction.trace.getTotalTimeDurationInMillis()
16
+ const duration = segment.getDurationInMillis()
17
+ const exclusive = segment.getExclusiveDurationInMillis()
18
+ const totalTime = segment.transaction.trace.getTotalTimeDurationInMillis()
19
19
 
20
- var tx = segment.transaction
21
20
  if (scope) {
22
21
  tx.measure(scope, null, duration, exclusive)
23
22
  tx.measure(
@@ -10,15 +10,15 @@ const recordDistributedTrace = require('./distributed-trace')
10
10
 
11
11
  function recordBackground(segment, scope) {
12
12
  // if there was a nested otherTransaction use its recorder instead
13
- var tx = segment.transaction
13
+ const tx = segment.transaction
14
14
  if (tx.type === 'bg' && tx.baseSegment && segment !== tx.baseSegment) {
15
15
  return
16
16
  }
17
17
 
18
- var duration = segment.getDurationInMillis()
19
- var exclusive = segment.getExclusiveDurationInMillis()
20
- var totalTime = segment.transaction.trace.getTotalTimeDurationInMillis()
21
- var name = segment.partialName
18
+ const duration = segment.getDurationInMillis()
19
+ const exclusive = segment.getExclusiveDurationInMillis()
20
+ const totalTime = segment.transaction.trace.getTotalTimeDurationInMillis()
21
+ const name = segment.partialName
22
22
 
23
23
  if (scope) {
24
24
  tx.measure(scope, null, duration, exclusive)
@@ -5,26 +5,26 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- var logger = require('./logger.js').child({ component: 'proc-cpuinfo' })
8
+ const logger = require('./logger.js').child({ component: 'proc-cpuinfo' })
9
9
  module.exports = parseProcCPUInfo
10
10
 
11
11
  function parseProcCPUInfo(data) {
12
- var relevantAttributes = ['processor', 'physical id', 'cpu cores', 'core id']
12
+ const relevantAttributes = ['processor', 'physical id', 'cpu cores', 'core id']
13
13
 
14
- var processorStats = {
14
+ let processorStats = {
15
15
  logical: null,
16
16
  cores: null,
17
17
  packages: null
18
18
  }
19
19
 
20
20
  // separate the processors
21
- var splitData = data.split('\n').map(function formatAttribute(attr) {
21
+ let splitData = data.split('\n').map(function formatAttribute(attr) {
22
22
  return attr.split(':').map(function eliminateExtraWhitespace(s) {
23
23
  return s.replace(/\\r|\\t| {2,}/g, '').trim()
24
24
  })
25
25
  })
26
26
 
27
- var validData = splitData.filter(function checkForValidAttrs(a) {
27
+ const validData = splitData.filter(function checkForValidAttrs(a) {
28
28
  return a.length === 2 && relevantAttributes.indexOf(a[0]) !== -1
29
29
  })
30
30
  if (validData.length === 0) {
@@ -34,7 +34,7 @@ function parseProcCPUInfo(data) {
34
34
 
35
35
  splitData = collapseMultilineValues(splitData)
36
36
 
37
- var processors = seperateProcessors(splitData)
37
+ const processors = seperateProcessors(splitData)
38
38
 
39
39
  processorStats = countProcessorStats(processors)
40
40
  if (!processorStats.cores) {
@@ -56,9 +56,9 @@ function parseProcCPUInfo(data) {
56
56
  // some values are split up over multiple lines, these won't be broken
57
57
  // by split(':'), and should be folded into the last seen valid value
58
58
  function collapseMultilineValues(li) {
59
- var tmp = []
60
- var last
61
- for (var i = 0; i < li.length; ++i) {
59
+ const tmp = []
60
+ let last
61
+ for (let i = 0; i < li.length; ++i) {
62
62
  if (li[i].length === 2) {
63
63
  // store the last valid entry to append invalid entries to
64
64
  last = li[i]
@@ -74,11 +74,11 @@ function collapseMultilineValues(li) {
74
74
  // walk through the processed list of key, value pairs and populate
75
75
  // objects till you find a collision
76
76
  function seperateProcessors(processorData) {
77
- var processors = []
78
- var processor = Object.create(null)
79
- for (var i = 0; i < processorData.length; ++i) {
80
- var key = processorData[i][0]
81
- var value = processorData[i][1]
77
+ const processors = []
78
+ let processor = Object.create(null)
79
+ for (let i = 0; i < processorData.length; ++i) {
80
+ const key = processorData[i][0]
81
+ const value = processorData[i][1]
82
82
  if (processor[key] !== undefined) {
83
83
  processors.push(processor)
84
84
  processor = Object.create(null)
@@ -90,11 +90,11 @@ function seperateProcessors(processorData) {
90
90
  }
91
91
 
92
92
  function countProcessorStats(processors) {
93
- var phys = []
94
- var cores = []
93
+ const phys = []
94
+ const cores = []
95
95
 
96
- for (var i = 0; i < processors.length; i++) {
97
- var processor = processors[i]
96
+ for (let i = 0; i < processors.length; i++) {
97
+ const processor = processors[i]
98
98
  if (
99
99
  processor['physical id'] &&
100
100
  processor['cpu cores'] &&
@@ -5,12 +5,12 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- var logger = require('./logger.js').child({ component: 'proc-meminfo' })
8
+ const logger = require('./logger.js').child({ component: 'proc-meminfo' })
9
9
 
10
10
  module.exports = parseProcMeminfo
11
11
 
12
12
  function parseProcMeminfo(data) {
13
- var memTotal = parseInt(data.replace(/MemTotal:\s*(\d*)\skB/, '$1'), 10)
13
+ const memTotal = parseInt(data.replace(/MemTotal:\s*(\d*)\skB/, '$1'), 10)
14
14
 
15
15
  if (memTotal) {
16
16
  return memTotal / 1024
@@ -35,7 +35,7 @@ class PrioritizedAttributes {
35
35
  get(dest) {
36
36
  const attrs = Object.create(null)
37
37
 
38
- for (let [key, attr] of this.attributes) {
38
+ for (const [key, attr] of this.attributes) {
39
39
  if (!(attr.destinations & dest)) {
40
40
  continue
41
41
  }
@@ -127,7 +127,7 @@ class PrioritizedAttributes {
127
127
  }
128
128
 
129
129
  addAttributes(destinations, attrs) {
130
- for (let key in attrs) {
130
+ for (const key in attrs) {
131
131
  if (properties.hasOwn(attrs, key)) {
132
132
  this.addAttribute(destinations, key, attrs[key])
133
133
  }
@@ -5,7 +5,7 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- var Heap = require('@tyriar/fibonacci-heap').FibonacciHeap
8
+ const Heap = require('@tyriar/fibonacci-heap').FibonacciHeap
9
9
 
10
10
  function PriorityQueue(limit) {
11
11
  this.limit = limit == null ? 10 : limit
@@ -20,7 +20,7 @@ function PriorityQueue(limit) {
20
20
  }
21
21
 
22
22
  PriorityQueue.prototype.overflow = function overflow() {
23
- var diff = this.seen - this.limit
23
+ const diff = this.seen - this.limit
24
24
  return diff >= 0 ? diff : 0
25
25
  }
26
26
 
@@ -51,8 +51,8 @@ PriorityQueue.prototype._replace = function _replace(value, priority) {
51
51
  }
52
52
 
53
53
  PriorityQueue.prototype.getRawEvents = function getRawEvents() {
54
- var events = []
55
- var min = this._data.findMinimum()
54
+ const events = []
55
+ const min = this._data.findMinimum()
56
56
 
57
57
  if (min) {
58
58
  _getRawEvents(min, events)
@@ -61,7 +61,7 @@ PriorityQueue.prototype.getRawEvents = function getRawEvents() {
61
61
  return events
62
62
 
63
63
  function _getRawEvents(head, evts) {
64
- var current = head
64
+ let current = head
65
65
 
66
66
  do {
67
67
  evts.push({ value: current.value, priority: current.key })
@@ -74,8 +74,8 @@ PriorityQueue.prototype.getRawEvents = function getRawEvents() {
74
74
  }
75
75
 
76
76
  PriorityQueue.prototype.toArray = function toArray() {
77
- var nodes = []
78
- var min = this._data.findMinimum()
77
+ const nodes = []
78
+ const min = this._data.findMinimum()
79
79
 
80
80
  if (min) {
81
81
  serializeHeap(min, nodes)
@@ -84,7 +84,7 @@ PriorityQueue.prototype.toArray = function toArray() {
84
84
  return nodes
85
85
 
86
86
  function serializeHeap(head, arr) {
87
- var current = head
87
+ let current = head
88
88
 
89
89
  do {
90
90
  arr.push(current.value)
@@ -110,11 +110,11 @@ PriorityQueue.prototype.merge = function merge(events) {
110
110
 
111
111
  if (events instanceof PriorityQueue) {
112
112
  while (events.length) {
113
- var current = events._data.extractMinimum()
113
+ const current = events._data.extractMinimum()
114
114
  this.add(current.value, current.key)
115
115
  }
116
116
  } else {
117
- for (var i = 0; i < events.length; ++i) {
117
+ for (let i = 0; i < events.length; ++i) {
118
118
  this.add(events[i].value, events[i].priority)
119
119
  }
120
120
  }
package/lib/reservoir.js CHANGED
@@ -14,7 +14,7 @@ function Reservoir(limit) {
14
14
  }
15
15
 
16
16
  Reservoir.prototype.overflow = function overflow() {
17
- var diff = this.seen - this.limit
17
+ const diff = this.seen - this.limit
18
18
  return diff >= 0 ? diff : 0
19
19
  }
20
20
 
@@ -29,7 +29,7 @@ Reservoir.prototype.add = function add(item) {
29
29
  // This is effectively the same as adding the new element to the
30
30
  // end, swapping the last element (the new one) with a random element in the list,
31
31
  // then dropping the last element (the potentially swapped one) in the list.
32
- var toReplace = Math.floor(Math.random() * (this.seen + 2))
32
+ const toReplace = Math.floor(Math.random() * (this.seen + 2))
33
33
  if (toReplace < this.limit) {
34
34
  this._data[toReplace] = item
35
35
  }
@@ -48,7 +48,7 @@ Reservoir.prototype.merge = function merge(items) {
48
48
  if (items === this._data) {
49
49
  return
50
50
  }
51
- for (var i = 0; i < items.length; i++) {
51
+ for (let i = 0; i < items.length; i++) {
52
52
  this.add(items[i])
53
53
  }
54
54
  }
package/lib/sampler.js CHANGED
@@ -5,22 +5,22 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- var NAMES = require('./metrics/names')
9
- var logger = require('./logger').child({ component: 'sampler' })
10
- var Timer = require('./timer')
11
- var os = require('os')
8
+ const NAMES = require('./metrics/names')
9
+ const logger = require('./logger').child({ component: 'sampler' })
10
+ const Timer = require('./timer')
11
+ const os = require('os')
12
12
 
13
13
  /*
14
14
  *
15
15
  * CONSTANTS
16
16
  *
17
17
  */
18
- var MILLIS = 1e3
19
- var MICROS = 1e6
20
- var CPUS = os.cpus().length
21
- var SAMPLE_INTERVAL = 15 * MILLIS
18
+ const MILLIS = 1e3
19
+ const MICROS = 1e6
20
+ const CPUS = os.cpus().length
21
+ const SAMPLE_INTERVAL = 15 * MILLIS
22
22
 
23
- var samplers = []
23
+ let samplers = []
24
24
 
25
25
  function Sampler(sampler, interval) {
26
26
  this.id = setInterval(sampler, interval)
@@ -39,7 +39,7 @@ function recordQueueTime(agent, timer) {
39
39
  function sampleMemory(agent) {
40
40
  return function memorySampler() {
41
41
  try {
42
- var mem = process.memoryUsage()
42
+ const mem = process.memoryUsage()
43
43
  agent.metrics.measureBytes(NAMES.MEMORY.PHYSICAL, mem.rss)
44
44
  agent.metrics.measureBytes(NAMES.MEMORY.USED_HEAP, mem.heapUsed)
45
45
  agent.metrics.measureBytes(NAMES.MEMORY.MAX_HEAP, mem.heapTotal)
@@ -54,7 +54,7 @@ function sampleMemory(agent) {
54
54
 
55
55
  function checkEvents(agent) {
56
56
  return function eventSampler() {
57
- var timer = new Timer()
57
+ const timer = new Timer()
58
58
  timer.begin()
59
59
  setTimeout(recordQueueTime.bind(null, agent, timer), 0)
60
60
  }
@@ -70,22 +70,22 @@ function getCpuSample(lastSample) {
70
70
  }
71
71
 
72
72
  function generateCPUMetricRecorder(agent) {
73
- var lastSampleTime
73
+ let lastSampleTime
74
74
  // userTime and sysTime are in seconds
75
75
  return function recordCPUMetrics(userTime, sysTime) {
76
- var elapsedUptime
76
+ let elapsedUptime
77
77
  if (!lastSampleTime) {
78
78
  elapsedUptime = process.uptime()
79
79
  } else {
80
80
  elapsedUptime = (Date.now() - lastSampleTime) / MILLIS
81
81
  }
82
82
 
83
- var totalCpuTime = CPUS * elapsedUptime
83
+ const totalCpuTime = CPUS * elapsedUptime
84
84
 
85
85
  lastSampleTime = Date.now()
86
86
 
87
- var userUtil = userTime / totalCpuTime
88
- var sysUtil = sysTime / totalCpuTime
87
+ const userUtil = userTime / totalCpuTime
88
+ const sysUtil = sysTime / totalCpuTime
89
89
 
90
90
  recordValue(agent, NAMES.CPU.USER_TIME, userTime)
91
91
  recordValue(agent, NAMES.CPU.SYSTEM_TIME, sysTime)
@@ -95,10 +95,10 @@ function generateCPUMetricRecorder(agent) {
95
95
  }
96
96
 
97
97
  function sampleCpu(agent) {
98
- var lastSample
99
- var recordCPU = generateCPUMetricRecorder(agent)
98
+ let lastSample
99
+ const recordCPU = generateCPUMetricRecorder(agent)
100
100
  return function cpuSampler() {
101
- var cpuSample = getCpuSample(lastSample)
101
+ const cpuSample = getCpuSample(lastSample)
102
102
  lastSample = getCpuSample()
103
103
 
104
104
  if (lastSample == null) {
@@ -110,7 +110,7 @@ function sampleCpu(agent) {
110
110
  }
111
111
 
112
112
  function sampleCpuNative(agent, nativeMetrics) {
113
- var recordCPU = generateCPUMetricRecorder(agent)
113
+ const recordCPU = generateCPUMetricRecorder(agent)
114
114
  nativeMetrics.on('usage', function collectResourceUsage(usage) {
115
115
  recordCPU(usage.diff.ru_utime / MILLIS, usage.diff.ru_stime / MILLIS)
116
116
  })
@@ -149,7 +149,7 @@ function sampleGc(agent, nativeMetrics) {
149
149
  }
150
150
  }
151
151
 
152
- var sampler = (module.exports = {
152
+ module.exports = {
153
153
  state: 'stopped',
154
154
  sampleMemory: sampleMemory,
155
155
  checkEvents: checkEvents,
@@ -206,7 +206,7 @@ var sampler = (module.exports = {
206
206
  logger.debug('Not adding CPU metric sampler.')
207
207
  }
208
208
 
209
- sampler.state = 'running'
209
+ this.state = 'running'
210
210
  },
211
211
 
212
212
  stop: function stop() {
@@ -214,7 +214,7 @@ var sampler = (module.exports = {
214
214
  s.stop()
215
215
  })
216
216
  samplers = []
217
- sampler.state = 'stopped'
217
+ this.state = 'stopped'
218
218
  if (this.nativeMetrics) {
219
219
  this.nativeMetrics.unbind()
220
220
  this.nativeMetrics.removeAllListeners()
@@ -224,16 +224,16 @@ var sampler = (module.exports = {
224
224
  this.nativeMetrics = null
225
225
  }
226
226
  }
227
- })
227
+ }
228
228
 
229
229
  function recordValue(agent, metric, value) {
230
- var stats = agent.metrics.getOrCreateMetric(metric)
230
+ const stats = agent.metrics.getOrCreateMetric(metric)
231
231
  stats.recordValue(value)
232
232
  logger.trace('Recorded metric %s: %j', metric, value)
233
233
  }
234
234
 
235
235
  function recordCompleteMetric(agent, metricName, metric) {
236
- var stats = agent.metrics.getOrCreateMetric(metricName)
236
+ const stats = agent.metrics.getOrCreateMetric(metricName)
237
237
  stats.merge(metric)
238
238
  logger.trace('Recorded metric %s: %j', metricName, metric)
239
239
  }