forked from marcbachmann/opentelemetry-node-metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Simplify the labels and prefix usage
- Loading branch information
1 parent
3efd636
commit b354ecc
Showing
16 changed files
with
77 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
function aggregateByObjectName (list) { | ||
const data = {} | ||
function createAggregatorByObjectName () { | ||
const all = new Map() | ||
return function aggregateByObjectName (list) { | ||
const current = new Map() | ||
|
||
for (let i = 0; i < list.length; i++) { | ||
const listElement = list[i] | ||
|
||
if (!listElement || typeof listElement.constructor === 'undefined') { | ||
continue | ||
for (let i = 0; i < list.length; i++) { | ||
const listElementConstructor = list[i] && list[i].constructor | ||
if (typeof listElementConstructor === 'undefined') continue | ||
current.set(listElementConstructor.name, (current.get(listElementConstructor.name) || 0) + 1) | ||
} | ||
|
||
if (Object.hasOwnProperty.call(data, listElement.constructor.name)) { | ||
data[listElement.constructor.name] += 1 | ||
} else { | ||
data[listElement.constructor.name] = 1 | ||
} | ||
for (const key of all.keys()) all.set(key, 0) | ||
for (const [key, value] of current) all.set(key, value) | ||
return current | ||
} | ||
return data | ||
} | ||
|
||
module.exports = { | ||
aggregateByObjectName | ||
createAggregatorByObjectName | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,10 @@ | ||
const startInSeconds = Math.round((Date.now() / 1000) - process.uptime()) | ||
const PROCESS_START_TIME = 'process_start_time_seconds' | ||
|
||
module.exports = (meter, config = {}) => { | ||
const namePrefix = config.prefix ? config.prefix : '' | ||
const labels = config.labels ? config.labels : {} | ||
|
||
meter.createValueObserver(namePrefix + PROCESS_START_TIME, { | ||
module.exports = (meter, {prefix, labels}) => { | ||
meter.createUpDownCounter(prefix + PROCESS_START_TIME, { | ||
description: 'Start time of the process since unix epoch in seconds.' | ||
}, (observerResult) => { | ||
observerResult.observe(startInSeconds, labels) | ||
}) | ||
}).bind(labels).add(startInSeconds) | ||
} | ||
|
||
module.exports.metricNames = [PROCESS_START_TIME] |
Oops, something went wrong.