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

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
37 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
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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 |
| --------------------------- | --------------------------------------------------------- |
| `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` | |
Netail marked this conversation as resolved.
Show resolved Hide resolved
| `system.network.dropped` | Count of packets that are dropped |
| `system.network.errors` | Count of network errors detected |
| `system.network.io` | |
Netail marked this conversation as resolved.
Show resolved Hide resolved
| `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 |

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
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

@@ -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
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"
}
}
12 changes: 6 additions & 6 deletions packages/opentelemetry-host-metrics/src/BaseMetrics.ts
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';

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
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_IO_DIRECTION = 'network.io.direction',
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