Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Netail committed May 30, 2024
1 parent 9c14d64 commit 72ba6f9
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 16 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions packages/opentelemetry-host-metrics/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
declare module 'systeminformation/lib/network' {
export { networkStats } from 'systeminformation';
}
2 changes: 1 addition & 1 deletion packages/opentelemetry-host-metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
"dependencies": {
"@opentelemetry/sdk-metrics": "^1.8.0",
"systeminformation": "^5.22.7"
"systeminformation": "5.22.9"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/opentelemetry-host-metrics#readme"
}
4 changes: 2 additions & 2 deletions packages/opentelemetry-host-metrics/src/stats/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import { cpus, totalmem, freemem } from 'os';
import type { CpuInfo } from 'os';
import { cpus, totalmem, freemem } from 'node:os';
import type { CpuInfo } from 'node:os';
import type { CpuUsageData, MemoryData, ProcessCpuUsageData } from '../types';

const MILLISECOND = 1 / 1e3;
Expand Down
6 changes: 5 additions & 1 deletion packages/opentelemetry-host-metrics/src/stats/si.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
* limitations under the License.
*/

import { networkStats } from 'systeminformation';

// Import from the network file directly as bundlers trigger the 'osx-temperature-sensor' import in the systeminformation/lib/cpu.js,
// resulting in the following warning: "Can't resolve 'osx-temperature-sensor'"
// See https://github.com/open-telemetry/opentelemetry-js-contrib/pull/2071
import { networkStats } from 'systeminformation/lib/network';
import type { Systeminformation } from 'systeminformation';

export function getNetworkData() {
Expand Down
6 changes: 3 additions & 3 deletions packages/opentelemetry-host-metrics/test/metric.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import * as SI from 'systeminformation';
import * as Network from 'systeminformation/lib/network';
import type { Systeminformation } from 'systeminformation';
import { Attributes } from '@opentelemetry/api';
import {
Expand All @@ -26,7 +26,7 @@ import {
MetricReader,
} from '@opentelemetry/sdk-metrics';
import * as assert from 'assert';
import * as os from 'os';
import * as os from 'node:os';
import * as sinon from 'sinon';
import { ATTRIBUTE_NAMES } from '../src/enum';
import { HostMetrics } from '../src';
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('Host Metrics', () => {
sandbox
.stub(process.memoryUsage, 'rss')
.callsFake(mockedProcess.memoryUsage.rss);
sandbox.stub(SI, 'networkStats').callsFake(mockedSI.networkStats);
sandbox.stub(Network, 'networkStats').callsFake(mockedSI.networkStats);

reader = new TestMetricReader();

Expand Down
3 changes: 2 additions & 1 deletion packages/opentelemetry-host-metrics/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"include": [
"src/**/*.ts",
"test/**/*.ts"
"test/**/*.ts",
"global.d.ts"
]
}

0 comments on commit 72ba6f9

Please sign in to comment.