@sesamecare-oss/opentelemetry-node-metrics 1.0.0 → 1.1.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.
- package/.eslintrc.js +1 -1
- package/.github/workflows/nodejs.yml +58 -0
- package/.prettierrc.js +1 -1
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +5 -2
- package/build/{metrics/util.js → helpers/counterNames.js} +2 -3
- package/build/helpers/counterNames.js.map +1 -0
- package/build/helpers/processMetricsHelpers.d.ts +2 -0
- package/build/helpers/processMetricsHelpers.js +21 -0
- package/build/helpers/processMetricsHelpers.js.map +1 -0
- package/build/helpers/safeMemoryUsage.d.ts +1 -0
- package/build/helpers/safeMemoryUsage.js +12 -0
- package/build/helpers/safeMemoryUsage.js.map +1 -0
- package/build/index.d.ts +1 -1
- package/build/index.js +5 -4
- package/build/index.js.map +1 -1
- package/build/metrics/eventLoopLag.d.ts +3 -1
- package/build/metrics/eventLoopLag.js +10 -11
- package/build/metrics/eventLoopLag.js.map +1 -1
- package/build/metrics/gc.d.ts +6 -0
- package/build/metrics/gc.js +32 -0
- package/build/metrics/gc.js.map +1 -0
- package/build/metrics/heapSizeAndUsed.d.ts +6 -0
- package/build/metrics/heapSizeAndUsed.js +59 -0
- package/build/metrics/heapSizeAndUsed.js.map +1 -0
- package/build/metrics/heapSpacesSizeAndUsed.d.ts +6 -0
- package/build/metrics/heapSpacesSizeAndUsed.js +81 -0
- package/build/metrics/heapSpacesSizeAndUsed.js.map +1 -0
- package/build/metrics/index.d.ts +7 -0
- package/build/metrics/index.js +7 -0
- package/build/metrics/index.js.map +1 -1
- package/build/metrics/osMemoryHeap.d.ts +6 -0
- package/build/metrics/osMemoryHeap.js +27 -0
- package/build/metrics/osMemoryHeap.js.map +1 -0
- package/build/metrics/osMemoryHeapLinux.d.ts +6 -0
- package/build/metrics/osMemoryHeapLinux.js +83 -0
- package/build/metrics/osMemoryHeapLinux.js.map +1 -0
- package/build/metrics/processCpuTotal.d.ts +6 -0
- package/build/metrics/processCpuTotal.js +37 -0
- package/build/metrics/processCpuTotal.js.map +1 -0
- package/build/metrics/processMaxFileDescriptors.d.ts +3 -0
- package/build/metrics/processMaxFileDescriptors.js +38 -0
- package/build/metrics/processMaxFileDescriptors.js.map +1 -0
- package/build/metrics/processOpenFileDescriptors.d.ts +6 -0
- package/build/metrics/processOpenFileDescriptors.js +31 -0
- package/build/metrics/processOpenFileDescriptors.js.map +1 -0
- package/build/metrics/processResources.d.ts +6 -0
- package/build/metrics/processResources.js +36 -0
- package/build/metrics/processResources.js.map +1 -0
- package/build/metrics/processStartTime.d.ts +3 -0
- package/build/metrics/processStartTime.js +4 -4
- package/build/metrics/processStartTime.js.map +1 -1
- package/build/metrics/version.d.ts +3 -0
- package/build/metrics/version.js +4 -4
- package/build/metrics/version.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +17 -19
- package/src/helpers/processMetricsHelpers.ts +25 -0
- package/src/helpers/safeMemoryUsage.ts +7 -0
- package/src/index.ts +4 -4
- package/src/metrics/eventLoopLag.ts +3 -7
- package/src/metrics/gc.ts +39 -0
- package/src/metrics/heapSizeAndUsed.ts +64 -0
- package/src/metrics/heapSpacesSizeAndUsed.ts +104 -0
- package/src/metrics/index.ts +7 -0
- package/src/metrics/osMemoryHeap.ts +31 -0
- package/src/metrics/osMemoryHeapLinux.ts +92 -0
- package/src/metrics/processCpuTotal.ts +47 -0
- package/src/metrics/processMaxFileDescriptors.ts +39 -0
- package/src/metrics/processOpenFileDescriptors.ts +30 -0
- package/src/metrics/processResources.ts +40 -0
- package/src/metrics/processStartTime.ts +3 -2
- package/src/metrics/version.ts +3 -2
- package/tsconfig.json +4 -2
- package/vitest.config.ts +1 -1
- package/.github/workflows/publish.yml +0 -49
- package/.github/workflows/pull_requests.yml +0 -26
- package/build/metrics/util.js.map +0 -1
- /package/build/{metrics/util.d.ts → helpers/counterNames.d.ts} +0 -0
- /package/src/{metrics/util.ts → helpers/counterNames.ts} +0 -0
package/.eslintrc.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Instead, edit the coconfig.js or coconfig.ts file in your project root.
|
|
4
4
|
*
|
|
5
5
|
* See https://github.com/gas-buddy/coconfig for more information.
|
|
6
|
-
* @version coconfig@
|
|
6
|
+
* @version coconfig@1.5.2
|
|
7
7
|
*/
|
|
8
8
|
const configModule = require('@openapi-typescript-infra/coconfig');
|
|
9
9
|
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
name: Node build, test and publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [assigned, opened, synchronize, reopened]
|
|
6
|
+
push:
|
|
7
|
+
branches:
|
|
8
|
+
- main
|
|
9
|
+
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
|
|
13
|
+
concurrency:
|
|
14
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
15
|
+
cancel-in-progress: true
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
build:
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
- name: Use Node.js 20
|
|
23
|
+
uses: actions/setup-node@v4
|
|
24
|
+
with:
|
|
25
|
+
node-version: 20
|
|
26
|
+
cache: yarn
|
|
27
|
+
- name: npm install, lint, build, and test
|
|
28
|
+
run: |
|
|
29
|
+
yarn install --immutable
|
|
30
|
+
yarn build
|
|
31
|
+
yarn lint
|
|
32
|
+
yarn test
|
|
33
|
+
env:
|
|
34
|
+
CI: true
|
|
35
|
+
|
|
36
|
+
publish-npm:
|
|
37
|
+
needs: build
|
|
38
|
+
if: github.ref == 'refs/heads/main'
|
|
39
|
+
permissions:
|
|
40
|
+
contents: write
|
|
41
|
+
issues: write
|
|
42
|
+
id-token: write
|
|
43
|
+
pull-requests: write
|
|
44
|
+
runs-on: ubuntu-latest
|
|
45
|
+
steps:
|
|
46
|
+
- uses: actions/checkout@v4
|
|
47
|
+
- uses: actions/setup-node@v4
|
|
48
|
+
with:
|
|
49
|
+
node-version: 20
|
|
50
|
+
cache: yarn
|
|
51
|
+
- run: yarn install --immutable
|
|
52
|
+
- run: yarn build
|
|
53
|
+
- name: Release
|
|
54
|
+
env:
|
|
55
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
56
|
+
NPM_TOKEN: ${{ secrets.SESAMECARE_OSS_NPM_TOKEN }}
|
|
57
|
+
run: |
|
|
58
|
+
yarn dlx semantic-release
|
package/.prettierrc.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Instead, edit the coconfig.js or coconfig.ts file in your project root.
|
|
4
4
|
*
|
|
5
5
|
* See https://github.com/gas-buddy/coconfig for more information.
|
|
6
|
-
* @version coconfig@
|
|
6
|
+
* @version coconfig@1.5.2
|
|
7
7
|
*/
|
|
8
8
|
const configModule = require('@openapi-typescript-infra/coconfig');
|
|
9
9
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.0.1](https://github.com/sesamecare/opentelemetry-node-metrics/compare/v1.0.0...v1.0.1) (2023-10-13)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **metrics:** add the rest of the metrics ([5448bf8](https://github.com/sesamecare/opentelemetry-node-metrics/commit/5448bf81296850b76552765253f47105ccc8cec0))
|
|
7
|
+
|
|
1
8
|
# 1.0.0 (2023-10-13)
|
|
2
9
|
|
|
3
10
|
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Sesame, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
A modernized set of node metrics for OpenTelemetry. Based on two excellent modules:
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
- [Marc Bachmann's opentelemetry-node-metrics](https://github.com/marcbachmann/opentelemetry-node-metrics)
|
|
6
|
+
- [Simon Nyberg's prom-client](https://github.com/siimon/prom-client)
|
|
7
7
|
|
|
8
8
|
Usage:
|
|
9
|
+
|
|
9
10
|
```sh
|
|
10
11
|
yarn add @sesamecare-oss/opentelemetry-node-metrics
|
|
11
12
|
```
|
|
@@ -21,3 +22,5 @@ setupNodeMetrics(meter);
|
|
|
21
22
|
```
|
|
22
23
|
|
|
23
24
|
Now your Prometheus-exported metrics should be included along with whatever other metrics you ahve selected. See [openapi-typescript-infra/service](https://github.com/openapi-typescript-infra/service) for a more complete example of metrics integrated with an express service host.
|
|
25
|
+
|
|
26
|
+
One notable change from the existing libraries - they divide active handles and active 'requests' using deprecated Node APIs. I've chosed to merge these into 'resources' using the new getActiveResourcesInfo API, which is Node17+. It should fail gracefully if that function is not available.
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prefixedName =
|
|
3
|
+
exports.prefixedName = prefixedName;
|
|
4
4
|
function prefixedName(config, name) {
|
|
5
5
|
return `${config?.prefix || ''}${name}`;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
//# sourceMappingURL=util.js.map
|
|
7
|
+
//# sourceMappingURL=counterNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"counterNames.js","sourceRoot":"","sources":["../../src/helpers/counterNames.ts"],"names":[],"mappings":";;AAEA,oCAEC;AAFD,SAAgB,YAAY,CAAC,MAAoC,EAAE,IAAY;IAC7E,OAAO,GAAG,MAAM,EAAE,MAAM,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAggregatorByObjectName = createAggregatorByObjectName;
|
|
4
|
+
function createAggregatorByObjectName() {
|
|
5
|
+
const all = new Map();
|
|
6
|
+
return function aggregateByObjectName(metric, labels, list) {
|
|
7
|
+
const current = new Map();
|
|
8
|
+
for (const key of all.keys()) {
|
|
9
|
+
current.set(key, 0);
|
|
10
|
+
}
|
|
11
|
+
for (let i = 0; i < list.length; i++) {
|
|
12
|
+
current.set(list[i], (current.get(list[i]) || 0) + 1);
|
|
13
|
+
}
|
|
14
|
+
for (const [key, value] of current) {
|
|
15
|
+
const metricLabels = all.get(key) || { ...labels, type: key };
|
|
16
|
+
metric.observe(value, metricLabels);
|
|
17
|
+
all.set(key, metricLabels);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=processMetricsHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processMetricsHelpers.js","sourceRoot":"","sources":["../../src/helpers/processMetricsHelpers.ts"],"names":[],"mappings":";;AAEA,oEAsBC;AAtBD,SAAgB,4BAA4B;IAC1C,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;IACtB,OAAO,SAAS,qBAAqB,CACnC,MAAoC,EACpC,MAA0C,EAC1C,IAAc;QAEd,MAAM,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;QAC1B,KAAK,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;YAC7B,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACtB,CAAC;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACrC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACxD,CAAC;QAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;YACnC,MAAM,YAAY,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;YAC9D,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;YACpC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function safeMemoryUsage(): NodeJS.MemoryUsage | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.safeMemoryUsage = safeMemoryUsage;
|
|
4
|
+
function safeMemoryUsage() {
|
|
5
|
+
try {
|
|
6
|
+
return process.memoryUsage();
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
// Nothing to do here
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=safeMemoryUsage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safeMemoryUsage.js","sourceRoot":"","sources":["../../src/helpers/safeMemoryUsage.ts"],"names":[],"mappings":";;AAAA,0CAMC;AAND,SAAgB,eAAe;IAC7B,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,WAAW,EAAE,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,qBAAqB;IACvB,CAAC;AACH,CAAC"}
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Meter } from '@opentelemetry/api';
|
|
2
2
|
import * as metrics from './metrics';
|
|
3
3
|
import { NodeMetricConfig } from './types';
|
|
4
|
-
export declare function setupNodeMetrics(meter: Meter, config
|
|
4
|
+
export declare function setupNodeMetrics(meter: Meter, config?: NodeMetricConfig): void;
|
|
5
5
|
export * from './types';
|
|
6
6
|
export declare const NodeMetrics: typeof metrics;
|
package/build/index.js
CHANGED
|
@@ -26,13 +26,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
26
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.NodeMetrics =
|
|
29
|
+
exports.NodeMetrics = void 0;
|
|
30
|
+
exports.setupNodeMetrics = setupNodeMetrics;
|
|
30
31
|
const metrics = __importStar(require("./metrics"));
|
|
31
32
|
function setupNodeMetrics(meter, config) {
|
|
32
|
-
metrics.
|
|
33
|
-
|
|
33
|
+
Object.values(metrics).forEach((metric) => {
|
|
34
|
+
metric(meter, config);
|
|
35
|
+
});
|
|
34
36
|
}
|
|
35
|
-
exports.setupNodeMetrics = setupNodeMetrics;
|
|
36
37
|
__exportStar(require("./types"), exports);
|
|
37
38
|
exports.NodeMetrics = metrics;
|
|
38
39
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,4CAIC;AAPD,mDAAqC;AAGrC,SAAgB,gBAAgB,CAAC,KAAY,EAAE,MAAyB;IACtE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QACxC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,0CAAwB;AAEX,QAAA,WAAW,GAAG,OAAO,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Meter } from '@opentelemetry/api';
|
|
2
2
|
import { NodeMetricConfig } from '../types';
|
|
3
3
|
export declare function eventLoopLagMetric(meter: Meter, config?: NodeMetricConfig): void;
|
|
4
|
-
export declare
|
|
4
|
+
export declare namespace eventLoopLagMetric {
|
|
5
|
+
var metricNames: string[];
|
|
6
|
+
}
|
|
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.eventLoopLagMetric = eventLoopLagMetric;
|
|
7
7
|
const perf_hooks_1 = __importDefault(require("perf_hooks"));
|
|
8
|
-
const
|
|
8
|
+
const counterNames_1 = require("../helpers/counterNames");
|
|
9
9
|
// Reported always.
|
|
10
10
|
const NODEJS_EVENTLOOP_LAG = 'nodejs_eventloop_lag_seconds';
|
|
11
11
|
// Reported only when perf_hooks is available.
|
|
@@ -22,57 +22,56 @@ function eventLoopLagMetric(meter, config) {
|
|
|
22
22
|
});
|
|
23
23
|
histogram.enable();
|
|
24
24
|
meter
|
|
25
|
-
.createObservableGauge((0,
|
|
25
|
+
.createObservableGauge((0, counterNames_1.prefixedName)(config, NODEJS_EVENTLOOP_LAG_MIN), {
|
|
26
26
|
description: 'The minimum recorded event loop delay.',
|
|
27
27
|
})
|
|
28
28
|
.addCallback((observable) => {
|
|
29
29
|
observable.observe(histogram.min / 1e9, config?.labels);
|
|
30
30
|
});
|
|
31
31
|
meter
|
|
32
|
-
.createObservableGauge((0,
|
|
32
|
+
.createObservableGauge((0, counterNames_1.prefixedName)(config, NODEJS_EVENTLOOP_LAG_MAX), {
|
|
33
33
|
description: 'The maximum recorded event loop delay.',
|
|
34
34
|
})
|
|
35
35
|
.addCallback((observable) => {
|
|
36
36
|
observable.observe(histogram.max / 1e9, config?.labels);
|
|
37
37
|
});
|
|
38
38
|
meter
|
|
39
|
-
.createObservableGauge((0,
|
|
39
|
+
.createObservableGauge((0, counterNames_1.prefixedName)(config, NODEJS_EVENTLOOP_LAG_MEAN), {
|
|
40
40
|
description: 'The mean of the recorded event loop delays.',
|
|
41
41
|
})
|
|
42
42
|
.addCallback((observable) => {
|
|
43
43
|
observable.observe(histogram.mean / 1e9, config?.labels);
|
|
44
44
|
});
|
|
45
45
|
meter
|
|
46
|
-
.createObservableGauge((0,
|
|
46
|
+
.createObservableGauge((0, counterNames_1.prefixedName)(config, NODEJS_EVENTLOOP_LAG_STDDEV), {
|
|
47
47
|
description: 'The standard deviation of the recorded event loop delays.',
|
|
48
48
|
})
|
|
49
49
|
.addCallback((observable) => {
|
|
50
50
|
observable.observe(histogram.stddev / 1e9, config?.labels);
|
|
51
51
|
});
|
|
52
52
|
meter
|
|
53
|
-
.createObservableGauge((0,
|
|
53
|
+
.createObservableGauge((0, counterNames_1.prefixedName)(config, NODEJS_EVENTLOOP_LAG_P50), {
|
|
54
54
|
description: 'The 50th percentile of the recorded event loop delays.',
|
|
55
55
|
})
|
|
56
56
|
.addCallback((observable) => {
|
|
57
57
|
observable.observe(histogram.percentile(50) / 1e9, config?.labels);
|
|
58
58
|
});
|
|
59
59
|
meter
|
|
60
|
-
.createObservableGauge((0,
|
|
60
|
+
.createObservableGauge((0, counterNames_1.prefixedName)(config, NODEJS_EVENTLOOP_LAG_P90), {
|
|
61
61
|
description: 'The 90th percentile of the recorded event loop delays.',
|
|
62
62
|
})
|
|
63
63
|
.addCallback((observable) => {
|
|
64
64
|
observable.observe(histogram.percentile(90) / 1e9, config?.labels);
|
|
65
65
|
});
|
|
66
66
|
meter
|
|
67
|
-
.createObservableGauge((0,
|
|
67
|
+
.createObservableGauge((0, counterNames_1.prefixedName)(config, NODEJS_EVENTLOOP_LAG_P99), {
|
|
68
68
|
description: 'The 99th percentile of the recorded event loop delays.',
|
|
69
69
|
})
|
|
70
70
|
.addCallback((observable) => {
|
|
71
71
|
observable.observe(histogram.percentile(99) / 1e9, config?.labels);
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
exports.EventLoopMetricNames = [
|
|
74
|
+
eventLoopLagMetric.metricNames = [
|
|
76
75
|
NODEJS_EVENTLOOP_LAG,
|
|
77
76
|
NODEJS_EVENTLOOP_LAG_MIN,
|
|
78
77
|
NODEJS_EVENTLOOP_LAG_MAX,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventLoopLag.js","sourceRoot":"","sources":["../../src/metrics/eventLo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;IAEL,KAAK;SACF,qBAAqB,CAAC,IAAA,2BAAY,EAAC,MAAM,EAAE,wBAAwB,CAAC,EAAE;QACrE,WAAW,EAAE,wDAAwD;KACtE,CAAC;SACD,WAAW,CAAC,CAAC,UAAU,EAAE,EAAE;QAC1B,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;AACP,CAAC;AAED,kBAAkB,CAAC,WAAW,GAAG;IAC/B,oBAAoB;IACpB,wBAAwB;IACxB,wBAAwB;IACxB,yBAAyB;IACzB,2BAA2B;IAC3B,wBAAwB;IACxB,wBAAwB;IACxB,wBAAwB;CACzB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gcMetric = gcMetric;
|
|
4
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
5
|
+
const counterNames_1 = require("../helpers/counterNames");
|
|
6
|
+
const NODEJS_GC_DURATION_SECONDS = 'nodejs_gc_duration_seconds';
|
|
7
|
+
function keyForDetail(detail) {
|
|
8
|
+
if (typeof detail === 'object' && detail !== null && 'kind' in detail) {
|
|
9
|
+
return detail.kind || 'other';
|
|
10
|
+
}
|
|
11
|
+
return 'other';
|
|
12
|
+
}
|
|
13
|
+
function gcMetric(meter, config) {
|
|
14
|
+
const histogram = meter.createHistogram((0, counterNames_1.prefixedName)(config, NODEJS_GC_DURATION_SECONDS), {
|
|
15
|
+
description: 'Garbage collection duration by kind, one of major, minor, incremental or weakcb.',
|
|
16
|
+
});
|
|
17
|
+
const kinds = {};
|
|
18
|
+
kinds[perf_hooks_1.constants.NODE_PERFORMANCE_GC_MAJOR] = { ...config?.labels, kind: 'major' };
|
|
19
|
+
kinds[perf_hooks_1.constants.NODE_PERFORMANCE_GC_MINOR] = { ...config?.labels, kind: 'minor' };
|
|
20
|
+
kinds[perf_hooks_1.constants.NODE_PERFORMANCE_GC_INCREMENTAL] = { ...config?.labels, kind: 'incremental' };
|
|
21
|
+
kinds[perf_hooks_1.constants.NODE_PERFORMANCE_GC_WEAKCB] = { ...config?.labels, kind: 'weakcb' };
|
|
22
|
+
kinds['other'] = { ...config?.labels, kind: 'other' };
|
|
23
|
+
const obs = new perf_hooks_1.PerformanceObserver((list) => {
|
|
24
|
+
const entry = list.getEntries()[0];
|
|
25
|
+
// Convert duration from milliseconds to seconds
|
|
26
|
+
histogram.record(entry.duration / 1000, kinds[keyForDetail(entry.detail)]);
|
|
27
|
+
});
|
|
28
|
+
// We do not expect too many gc events per second, so we do not use buffering
|
|
29
|
+
obs.observe({ entryTypes: ['gc'], buffered: false });
|
|
30
|
+
}
|
|
31
|
+
gcMetric.metricNames = [NODEJS_GC_DURATION_SECONDS];
|
|
32
|
+
//# sourceMappingURL=gc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gc.js","sourceRoot":"","sources":["../../src/metrics/gc.ts"],"names":[],"mappings":";;AAgBA,4BAoBC;AApCD,2CAA0F;AAK1F,0DAAuD;AAEvD,MAAM,0BAA0B,GAAG,4BAA4B,CAAC;AAEhE,SAAS,YAAY,CAAC,MAAqD;IACzE,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;QACtE,OAAQ,MAAkC,CAAC,IAAI,IAAI,OAAO,CAAC;IAC7D,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAgB,QAAQ,CAAC,KAAY,EAAE,MAAyB;IAC9D,MAAM,SAAS,GAAG,KAAK,CAAC,eAAe,CAAC,IAAA,2BAAY,EAAC,MAAM,EAAE,0BAA0B,CAAC,EAAE;QACxF,WAAW,EAAE,kFAAkF;KAChG,CAAC,CAAC;IAEH,MAAM,KAAK,GAAoD,EAAE,CAAC;IAClE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Config): void;
|
|
4
|
+
export declare namespace heapSizeAndUsedMetric {
|
|
5
|
+
var metricNames: string[];
|
|
6
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.heapSizeAndUsedMetric = heapSizeAndUsedMetric;
|
|
4
|
+
const safeMemoryUsage_1 = require("../helpers/safeMemoryUsage");
|
|
5
|
+
const counterNames_1 = require("../helpers/counterNames");
|
|
6
|
+
const NODEJS_HEAP_SIZE_TOTAL = 'nodejs_heap_size_total_bytes';
|
|
7
|
+
const NODEJS_HEAP_SIZE_USED = 'nodejs_heap_size_used_bytes';
|
|
8
|
+
const NODEJS_EXTERNAL_MEMORY = 'nodejs_external_memory_bytes';
|
|
9
|
+
function heapSizeAndUsedMetric(meter, config) {
|
|
10
|
+
let stats;
|
|
11
|
+
function getStats() {
|
|
12
|
+
if (stats !== undefined)
|
|
13
|
+
return stats;
|
|
14
|
+
stats = (0, safeMemoryUsage_1.safeMemoryUsage)() || false;
|
|
15
|
+
setTimeout(() => {
|
|
16
|
+
stats = undefined;
|
|
17
|
+
}, 1000).unref();
|
|
18
|
+
return stats;
|
|
19
|
+
}
|
|
20
|
+
meter
|
|
21
|
+
.createObservableGauge((0, counterNames_1.prefixedName)(config, NODEJS_HEAP_SIZE_TOTAL), {
|
|
22
|
+
description: 'Process heap size from Node.js in bytes.',
|
|
23
|
+
})
|
|
24
|
+
.addCallback((observable) => {
|
|
25
|
+
if (!getStats() || !stats) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
observable.observe(stats.heapTotal, config?.labels);
|
|
29
|
+
});
|
|
30
|
+
meter
|
|
31
|
+
.createObservableGauge((0, counterNames_1.prefixedName)(config, NODEJS_HEAP_SIZE_USED), {
|
|
32
|
+
description: 'Process heap size used from Node.js in bytes.',
|
|
33
|
+
})
|
|
34
|
+
.addCallback((observable) => {
|
|
35
|
+
if (!getStats() || !stats) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
observable.observe(stats.heapUsed, config?.labels);
|
|
39
|
+
});
|
|
40
|
+
meter
|
|
41
|
+
.createObservableGauge((0, counterNames_1.prefixedName)(config, NODEJS_EXTERNAL_MEMORY), {
|
|
42
|
+
description: 'Node.js external memory size in bytes.',
|
|
43
|
+
})
|
|
44
|
+
.addCallback((observable) => {
|
|
45
|
+
if (!getStats() || !stats) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (stats.external === undefined) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
observable.observe(stats.external, config?.labels);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
heapSizeAndUsedMetric.metricNames = [
|
|
55
|
+
NODEJS_HEAP_SIZE_TOTAL,
|
|
56
|
+
NODEJS_HEAP_SIZE_USED,
|
|
57
|
+
NODEJS_EXTERNAL_MEMORY,
|
|
58
|
+
];
|
|
59
|
+
//# sourceMappingURL=heapSizeAndUsed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heapSizeAndUsed.js","sourceRoot":"","sources":["../../src/metrics/heapSizeAndUsed.ts"],"names":[],"mappings":";;AAUA,sDA+CC;AAtDD,gEAA6D;AAC7D,0DAAuD;AAEvD,MAAM,sBAAsB,GAAG,8BAA8B,CAAC;AAC9D,MAAM,qBAAqB,GAAG,6BAA6B,CAAC;AAC5D,MAAM,sBAAsB,GAAG,8BAA8B,CAAC;AAE9D,SAAgB,qBAAqB,CAAC,KAAY,EAAE,MAAyB;IAC3E,IAAI,KAA6D,CAAC;IAElE,SAAS,QAAQ;QACf,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;QACtC,KAAK,GAAG,IAAA,iCAAe,GAAE,IAAI,KAAK,CAAC;QACnC,UAAU,CAAC,GAAG,EAAE;YACd,KAAK,GAAG,SAAS,CAAC;QACpB,CAAC,EAAE,IAAI,CAAC,CAAC,KAA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,GAAG;IAClC,sBAAsB;IACtB,qBAAqB;IACrB,sBAAsB;CACvB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Meter } from '@opentelemetry/api';
|
|
2
|
+
import { NodeMetricConfig } from '../types';
|
|
3
|
+
export declare function heapSpacesSizeAndUsedMetric(meter: Meter, config?: NodeMetricConfig): void;
|
|
4
|
+
export declare namespace heapSpacesSizeAndUsedMetric {
|
|
5
|
+
var metricNames: string[];
|
|
6
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.heapSpacesSizeAndUsedMetric = heapSpacesSizeAndUsedMetric;
|
|
7
|
+
const v8_1 = __importDefault(require("v8"));
|
|
8
|
+
const counterNames_1 = require("../helpers/counterNames");
|
|
9
|
+
const METRICS = ['total', 'used', 'available'];
|
|
10
|
+
const NODEJS_HEAP_SIZE = {};
|
|
11
|
+
for (const metricType of METRICS) {
|
|
12
|
+
NODEJS_HEAP_SIZE[metricType] = `nodejs_heap_space_size_${metricType}_bytes`;
|
|
13
|
+
}
|
|
14
|
+
function heapSpacesSizeAndUsedMetric(meter, config) {
|
|
15
|
+
const labelsBySpace = {};
|
|
16
|
+
let stats;
|
|
17
|
+
function getStats() {
|
|
18
|
+
if (stats !== undefined) {
|
|
19
|
+
return stats;
|
|
20
|
+
}
|
|
21
|
+
stats = v8_1.default.getHeapSpaceStatistics().map((space) => {
|
|
22
|
+
const spaceLabels = labelsBySpace[space.space_name] ||
|
|
23
|
+
(function () {
|
|
24
|
+
const spaceName = space.space_name.replace(/_space$/, '');
|
|
25
|
+
labelsBySpace[space.space_name] = {
|
|
26
|
+
total: { ...config?.labels, space: spaceName },
|
|
27
|
+
used: { ...config?.labels, space: spaceName },
|
|
28
|
+
available: { ...config?.labels, space: spaceName },
|
|
29
|
+
};
|
|
30
|
+
return labelsBySpace[space.space_name];
|
|
31
|
+
})();
|
|
32
|
+
return {
|
|
33
|
+
total: { value: space.space_size, labels: spaceLabels.total },
|
|
34
|
+
used: { value: space.space_used_size, labels: spaceLabels.used },
|
|
35
|
+
available: { value: space.space_available_size, labels: spaceLabels.available },
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
stats = undefined;
|
|
40
|
+
}, 1000).unref();
|
|
41
|
+
return stats;
|
|
42
|
+
}
|
|
43
|
+
meter
|
|
44
|
+
.createObservableGauge((0, counterNames_1.prefixedName)(config, NODEJS_HEAP_SIZE.total), {
|
|
45
|
+
description: 'Process heap space size total from Node.js in bytes.',
|
|
46
|
+
})
|
|
47
|
+
.addCallback((observable) => {
|
|
48
|
+
if (!getStats() || !stats) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
for (let i = 0; i < stats.length; i++) {
|
|
52
|
+
observable.observe(stats[i].total.value, stats[i].total.labels);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
meter
|
|
56
|
+
.createObservableGauge((0, counterNames_1.prefixedName)(config, NODEJS_HEAP_SIZE.used), {
|
|
57
|
+
description: 'Process heap space size used from Node.js in bytes.',
|
|
58
|
+
})
|
|
59
|
+
.addCallback((observable) => {
|
|
60
|
+
if (!getStats() || !stats) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
for (let i = 0; i < stats.length; i++) {
|
|
64
|
+
observable.observe(stats[i].used.value, stats[i].used.labels);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
meter
|
|
68
|
+
.createObservableGauge((0, counterNames_1.prefixedName)(config, NODEJS_HEAP_SIZE.available), {
|
|
69
|
+
description: 'Process heap space size available from Node.js in bytes.',
|
|
70
|
+
})
|
|
71
|
+
.addCallback((observable) => {
|
|
72
|
+
if (!getStats() || !stats) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
for (let i = 0; i < stats.length; i++) {
|
|
76
|
+
observable.observe(stats[i].available.value, stats[i].available.labels);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
heapSpacesSizeAndUsedMetric.metricNames = Object.values(NODEJS_HEAP_SIZE);
|
|
81
|
+
//# sourceMappingURL=heapSpacesSizeAndUsed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heapSpacesSizeAndUsed.js","sourceRoot":"","sources":["../../src/metrics/heapSpacesSizeAndUsed.ts"],"names":[],"mappings":";;;;;AA8BA,kEAuEC;AArGD,4CAAoB;AAKpB,0DAAuD;AAEvD,MAAM,OAAO,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AAC/C,MAAM,gBAAgB,GAA2B,EAAE,CAAC;AAEpD,KAAK,MAAM,UAAU,IAAI,OAAO,EAAE,CAAC;IACjC,gBAAgB,CAAC,UAAU,CAAC,GAAG,0BAA0B,UAAU,QAAQ,CAAC;AAC9E,CAAC;AAkBD,SAAgB,2BAA2B,CAAC,KAAY,EAAE,MAAyB;IACjF,MAAM,aAAa,GAAsC,EAAE,CAAC;IAC5D,IAAI,KAAoC,CAAC;IACzC,SAAS,QAAQ;QACf,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,KAAK,GAAG,YAAE,CAAC,sBAAsB,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAChD,MAAM,WAAW,GACf,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC;gBAC/B,CAAC;oBACC,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;oBAC1D,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG;wBAChC,KAAK,EAAE,EAAE,GAAG,MAAM,EA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AAC,MAAM,CAAC,gBAAgB,CAAC,CAAC"}
|
package/build/metrics/index.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
export * from './version';
|
|
2
2
|
export * from './processStartTime';
|
|
3
3
|
export * from './eventLoopLag';
|
|
4
|
+
export * from './gc';
|
|
5
|
+
export * from './heapSizeAndUsed';
|
|
6
|
+
export * from './heapSpacesSizeAndUsed';
|
|
7
|
+
export * from './osMemoryHeap';
|
|
8
|
+
export * from './processCpuTotal';
|
|
9
|
+
export * from './processResources';
|
|
10
|
+
export * from './processMaxFileDescriptors';
|
package/build/metrics/index.js
CHANGED
|
@@ -17,4 +17,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./version"), exports);
|
|
18
18
|
__exportStar(require("./processStartTime"), exports);
|
|
19
19
|
__exportStar(require("./eventLoopLag"), exports);
|
|
20
|
+
__exportStar(require("./gc"), exports);
|
|
21
|
+
__exportStar(require("./heapSizeAndUsed"), exports);
|
|
22
|
+
__exportStar(require("./heapSpacesSizeAndUsed"), exports);
|
|
23
|
+
__exportStar(require("./osMemoryHeap"), exports);
|
|
24
|
+
__exportStar(require("./processCpuTotal"), exports);
|
|
25
|
+
__exportStar(require("./processResources"), exports);
|
|
26
|
+
__exportStar(require("./processMaxFileDescriptors"), exports);
|
|
20
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/metrics/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,qDAAmC;AACnC,iDAA+B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/metrics/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,qDAAmC;AACnC,iDAA+B;AAC/B,uCAAqB;AACrB,oDAAkC;AAClC,0DAAwC;AACxC,iDAA+B;AAC/B,oDAAkC;AAClC,qDAAmC;AACnC,8DAA4C"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.osMemoryHeapMetric = osMemoryHeapMetric;
|
|
4
|
+
const counterNames_1 = require("../helpers/counterNames");
|
|
5
|
+
const safeMemoryUsage_1 = require("../helpers/safeMemoryUsage");
|
|
6
|
+
const osMemoryHeapLinux_1 = require("./osMemoryHeapLinux");
|
|
7
|
+
const PROCESS_RESIDENT_MEMORY = 'process_resident_memory_bytes';
|
|
8
|
+
function osMemoryHeapMetric(meter, config) {
|
|
9
|
+
if (process.platform === 'linux') {
|
|
10
|
+
return (0, osMemoryHeapLinux_1.osMemoryHeapLinuxMetric)(meter, config);
|
|
11
|
+
}
|
|
12
|
+
meter
|
|
13
|
+
.createObservableGauge((0, counterNames_1.prefixedName)(config, PROCESS_RESIDENT_MEMORY), {
|
|
14
|
+
description: 'Resident memory size in bytes.',
|
|
15
|
+
})
|
|
16
|
+
.addCallback((observable) => {
|
|
17
|
+
const memUsage = (0, safeMemoryUsage_1.safeMemoryUsage)();
|
|
18
|
+
// I don't think the other things returned from
|
|
19
|
+
// `process.memoryUsage()` is relevant to a standard export
|
|
20
|
+
if (memUsage) {
|
|
21
|
+
observable.observe(memUsage.rss, config?.labels);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
osMemoryHeapMetric.metricNames =
|
|
26
|
+
process.platform === 'linux' ? osMemoryHeapLinux_1.osMemoryHeapLinuxMetric.metricNames : [PROCESS_RESIDENT_MEMORY];
|
|
27
|
+
//# sourceMappingURL=osMemoryHeap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"osMemoryHeap.js","sourceRoot":"","sources":["../../src/metrics/osMemoryHeap.ts"],"names":[],"mappings":";;AAUA,gDAiBC;AAxBD,0DAAuD;AACvD,gEAA6D;AAE7D,2DAA8D;AAE9D,MAAM,uBAAuB,GAAG,+BAA+B,CAAC;AAEhE,SAAgB,kBAAkB,CAAC,KAAY,EAAE,MAAyB;IACxE,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,OAAO,IAAA,2CAAuB,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;IAED,KAAK;SACF,qBAAqB,CAAC,IAAA,2BAAY,EAAC,MAAM,EAAE,uBAAuB,CAAC,EAAE;QACpE,WAAW,EAAE,gCAAgC;KAC9C,CAAC;SACD,WAAW,CAAC,CAAC,UAAU,EAAE,EAAE;QAC1B,MAAM,QAAQ,GAAG,IAAA,iCAAe,GAAE,CAAC;QACnC,+CAA+C;QAC/C,2DAA2D;QAC3D,IAAI,QAAQ,EAAE,CAAC;YACb,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACnD,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC;AAED,kBAAkB,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,2CAAuB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Meter } from '@opentelemetry/api';
|
|
2
|
+
import { NodeMetricConfig } from '../types';
|
|
3
|
+
export declare function osMemoryHeapLinuxMetric(meter: Meter, config?: NodeMetricConfig): void;
|
|
4
|
+
export declare namespace osMemoryHeapLinuxMetric {
|
|
5
|
+
var metricNames: string[];
|
|
6
|
+
}
|