Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(host-metrics): macOS bundling fix #2071

Merged
merged 45 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2c6d8cf
fix: semcov alignment & reduce import bundle
Netail Mar 29, 2024
60e0933
fix: types?
Netail Apr 2, 2024
65aabe7
Merge branch 'main' into fix/host-metrics-bundling
Netail Apr 2, 2024
ae578fc
fix: ci/cd
Netail Apr 2, 2024
ce92ffe
Merge branch 'main' into fix/host-metrics-bundling
Netail Apr 2, 2024
e818ba5
Merge branch 'main' into fix/host-metrics-bundling
Netail Apr 3, 2024
2484ef6
Merge branch 'main' into fix/host-metrics-bundling
Netail Apr 4, 2024
1106e97
docs: specify semantic conventions
Netail Apr 4, 2024
8f65520
revert some changes
Netail Apr 5, 2024
08506a4
Merge branch 'main' into fix/host-metrics-bundling
Netail Apr 8, 2024
63cc39d
fix: small type improvement
Netail Apr 9, 2024
03e2237
docs: add small comment
Netail Apr 9, 2024
9cbe462
Merge branch 'main' into fix/host-metrics-bundling
Netail Apr 10, 2024
a2aaa4b
Merge branch 'main' into fix/host-metrics-bundling
Netail Apr 11, 2024
744ea1d
fix: feedback
Netail Apr 16, 2024
cc8aafe
Merge branch 'main' into fix/host-metrics-bundling
Netail Apr 16, 2024
d1c1fca
Merge branch 'main' into fix/host-metrics-bundling
Netail Apr 18, 2024
a3b898f
Merge branch 'main' into fix/host-metrics-bundling
Netail Apr 20, 2024
a8196e4
fix: feedback
Netail Apr 20, 2024
304dc98
Merge branch 'main' into fix/host-metrics-bundling
Netail Apr 24, 2024
9f81a2d
Merge branch 'main' into fix/host-metrics-bundling
Netail Apr 27, 2024
769de9e
Merge branch 'main' into fix/host-metrics-bundling
Netail Apr 29, 2024
4fd1f8f
Merge branch 'main' into fix/host-metrics-bundling
Netail Apr 29, 2024
9c30315
Merge branch 'main' into fix/host-metrics-bundling
Netail Apr 30, 2024
83c58a3
Merge branch 'main' into fix/host-metrics-bundling
Netail May 1, 2024
2ac772e
Merge branch 'main' into fix/host-metrics-bundling
Netail May 2, 2024
343733e
Merge branch 'main' into fix/host-metrics-bundling
Netail May 3, 2024
fd50fe5
Merge branch 'main' into fix/host-metrics-bundling
Netail May 5, 2024
38b80b1
Merge branch 'main' into fix/host-metrics-bundling
Netail May 7, 2024
b642766
Merge branch 'main' into fix/host-metrics-bundling
Netail May 8, 2024
5e6370a
Merge branch 'main' into fix/host-metrics-bundling
Netail May 17, 2024
deb3257
Merge branch 'main' into fix/host-metrics-bundling
Netail May 21, 2024
5922334
fix: feedback
Netail May 22, 2024
06ac5e7
Merge branch 'main' into fix/host-metrics-bundling
Netail May 22, 2024
a3f9a61
Merge branch 'main' into fix/host-metrics-bundling
Netail May 22, 2024
fc23083
Merge branch 'main' into fix/host-metrics-bundling
Netail May 24, 2024
f675811
fix: remove subpath
Netail May 24, 2024
9c14d64
Merge branch 'main' into fix/host-metrics-bundling
Netail May 30, 2024
72ba6f9
feedback
Netail May 30, 2024
4c0c3c9
lint
Netail May 30, 2024
f0a7187
Merge branch 'main' into fix/host-metrics-bundling
Netail May 30, 2024
c0fbc8b
remove node import prefix
Netail May 30, 2024
5338456
lint
Netail May 30, 2024
3df9163
eof
Netail May 30, 2024
79555fc
Merge branch 'main' into fix/host-metrics-bundling
Netail May 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

33 changes: 33 additions & 0 deletions packages/opentelemetry-host-metrics/README.md
Netail marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,39 @@ const hostMetrics = new HostMetrics({ meterProvider, name: 'example-host-metrics
hostMetrics.start();
```

## Semantic Conventions

This package uses Semantic Conventions [Version 1.25.0](https://github.com/open-telemetry/semantic-conventions/tree/v1.25.0/docs/system).
As for now the Semantic Conventions are bundled in this package but eventually will be imported from `@opentelemetry/semantic-conventions` package when it is updated to latest version.
Ref: [opentelemetry-js/issues/4235](https://github.com/open-telemetry/opentelemetry-js/issues/4235)

Metrics collected:

| Metric | Short Description | Notes |
| --------------------------- | --------------------------------------------------------- | ----- |
| `system.cpu.time` | Seconds each logical CPU spent on each mode | |
| `system.cpu.utilization` | Difference in system.cpu.time since the last measurement | |
| `system.memory.usage` | Reports memory in use by state | |
| `system.memory.utilization` | | |
| `system.network.dropped` | Count of packets that are dropped | |
| `system.network.errors` | Count of network errors detected | |
| `system.network.io` | | |
| `process.cpu.time` | Total CPU seconds | |
| `process.cpu.utilization` | Difference in process.cpu.time since the last measurement | |
| `process.memory.usage` | The amount of physical memory in use | |
Netail marked this conversation as resolved.
Show resolved Hide resolved

Attributes collected:

| Metric | Short Description | Notes |
Netail marked this conversation as resolved.
Show resolved Hide resolved
| --------------------------- | ---------------------------------- | ----- |
| `system.cpu.logical_number` | The logical CPU number | |
| `system.cpu.state` | The state of the CPU | |
| `system.memory.state` | The memory state | |
| `system.device` | The device identifier | |
| `network.io.direction` | The network IO operation direction | |
| `system.network.state` | The network state | |
| `process.cpu.state` | The CPU state | |

## Useful links

* For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
Expand Down
3 changes: 3 additions & 0 deletions packages/opentelemetry-host-metrics/global.d.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess with the change suggested by @pichlermarc in ./src/stats/si.ts

- import { networkStats } from 'systeminformation/lib/network';
+ import { networkStats } from 'systeminformation';

this file is no needed. I see the .d.ts file from systeminformation exporting networkStats function already

Copy link
Contributor Author

@Netail Netail Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I use import { networkStats } from 'systeminformation';, it still tries to import the underlying cpu.js file, thus throwing an error on macOS. :( By targeting the file directly it won't.

The systeminformation/lib/cpu.js file tries to import osx-temperature-sensor for macOS, which you additionally have to install for macOS temperatures as it's not included in the dependencies, however osx-temp-sensor package breaks something else. But the cpu.js file isn't even used for host-metrics, so installing this package besides systeminformation is unecessary

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module 'systeminformation/lib/network' {
export { networkStats } from 'systeminformation';
}
4 changes: 2 additions & 2 deletions 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.21.20"
"systeminformation": "^5.22.7"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/opentelemetry-host-metrics#readme"
}
}
trentm marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 6 additions & 6 deletions packages/opentelemetry-host-metrics/src/BaseMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import * as api from '@opentelemetry/api';
import * as metrics from '@opentelemetry/sdk-metrics';
import { Meter, diag, metrics } from '@opentelemetry/api';
import { MeterProvider } from '@opentelemetry/sdk-metrics';
legendecas marked this conversation as resolved.
Show resolved Hide resolved

import { VERSION } from './version';

Expand All @@ -24,7 +24,7 @@ import { VERSION } from './version';
*/
export interface MetricsCollectorConfig {
// Meter Provider
meterProvider?: metrics.MeterProvider;
meterProvider?: MeterProvider;
// Character to be used to join metrics - default is "."
metricNameSeparator?: string;
// Name of component
Expand All @@ -39,14 +39,14 @@ const DEFAULT_NAME = '@opentelemetry/host-metrics';
* Base Class for metrics
*/
export abstract class BaseMetrics {
protected _logger = api.diag;
protected _meter: api.Meter;
protected _logger = diag;
protected _meter: Meter;
private _name: string;

constructor(config: MetricsCollectorConfig) {
this._name = config.name || DEFAULT_NAME;
const meterProvider =
config.meterProvider || api.metrics.getMeterProvider();
config.meterProvider || metrics.getMeterProvider();
if (!config.meterProvider) {
this._logger.warn('No meter provider, using default');
}
Expand Down
6 changes: 2 additions & 4 deletions packages/opentelemetry-host-metrics/src/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ export enum ATTRIBUTE_NAMES {
SYSTEM_CPU_STATE = 'system.cpu.state',
SYSTEM_MEMORY_STATE = 'system.memory.state',
SYSTEM_DEVICE = 'system.device',
SYSTEM_NETWORK_DIRECTION = 'system.network.direction',
NETWORK_NETWORK_DIRECTION = 'network.io.direction',
Netail marked this conversation as resolved.
Show resolved Hide resolved
SYSTEM_NETWORK_STATE = 'system.network.state',
// TODO: change value if semconv changes
// https://github.com/open-telemetry/opentelemetry-specification/issues/3776
PROCESS_CPU_STATE = 'state',
PROCESS_CPU_STATE = 'process.cpu.state',
}

export enum CPU_LABELS {
Expand Down
Loading
Loading