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

feat(host-metrics): upgrade api-metrics to v0.28.0 #990

Merged
merged 3 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/component_owners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ components:
metapackages/auto-instrumentations-web:
- obecny
packages/opentelemetry-host-metrics:
- obecny
- legendecas
packages/opentelemetry-id-generator-aws-xray:
- NathanielRN
- willarmiros
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-host-metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
"typescript": "4.3.5"
},
"dependencies": {
"@opentelemetry/api-metrics": "^0.27.0",
"@opentelemetry/api-metrics": "^0.28.0",
"@opentelemetry/core": "^1.0.0",
"@opentelemetry/sdk-metrics-base": "^0.27.0",
"@opentelemetry/sdk-metrics-base": "^0.28.0",
"systeminformation": "^5.0.0"
}
}
4 changes: 2 additions & 2 deletions packages/opentelemetry-host-metrics/src/BaseMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface MetricsCollectorConfig {
url?: string;
}

const DEFAULT_MAX_TIMEOUT_UPDATE_MS = 500;
export const DEFAULT_MAX_TIMEOUT_UPDATE_MS = 500;
const DEFAULT_NAME = 'opentelemetry-host-metrics';

/**
Expand All @@ -45,7 +45,7 @@ const DEFAULT_NAME = 'opentelemetry-host-metrics';
export abstract class BaseMetrics {
protected _logger = api.diag;
protected _maxTimeoutUpdateMS: number;
protected _meter: metrics.Meter;
protected _meter: apiMetrics.Meter;
private _name: string;

constructor(config: MetricsCollectorConfig) {
Expand Down
53 changes: 24 additions & 29 deletions packages/opentelemetry-host-metrics/src/metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,73 +166,73 @@ export class HostMetrics extends BaseMetrics {
protected _createMetrics(): void {
this._meter.createObservableCounter(
enums.METRIC_NAMES.CPU_TIME,
{
description: 'Cpu time in seconds',
unit: 's',
},
observableResult => {
const cpuUsageData = this._getCpuUsageData();
this._updateCpuTime(observableResult, cpuUsageData);
},
{
description: 'Cpu time in seconds',
unit: 's',
}
);
this._meter.createObservableGauge(
enums.METRIC_NAMES.CPU_UTILIZATION,
{
description: 'Cpu usage time 0-1',
},
observableResult => {
const cpuUsageData = this._getCpuUsageData();
this._updateCpuUtilisation(observableResult, cpuUsageData);
},
{
description: 'Cpu usage time 0-1',
}
);
this._meter.createObservableUpDownCounter(
this._meter.createObservableGauge(
enums.METRIC_NAMES.MEMORY_USAGE,
{
description: 'Memory usage in bytes',
},
observableResult => {
const memoryUsageData = this._getMemoryData();
this._updateMemUsage(observableResult, memoryUsageData);
},
{
description: 'Memory usage in bytes',
}
);
this._meter.createObservableGauge(
enums.METRIC_NAMES.MEMORY_UTILIZATION,
{
description: 'Memory usage 0-1',
},
observableResult => {
const memoryUsageData = this._getMemoryData();
this._updateMemUtilization(observableResult, memoryUsageData);
},
{
description: 'Memory usage 0-1',
}
);
this._meter.createObservableCounter(
enums.METRIC_NAMES.NETWORK_DROPPED,
{
description: 'Network dropped packets',
},
async observableResult => {
const networkData = await this._getNetworkData();
this._updateNetworkDropped(observableResult, networkData);
},
{
description: 'Network dropped packets',
}
);
this._meter.createObservableCounter(
enums.METRIC_NAMES.NETWORK_ERRORS,
{
description: 'Network errors counter',
},
async observableResult => {
const networkData = await this._getNetworkData();
this._updateNetworkErrors(observableResult, networkData);
},
{
description: 'Network errors counter',
}
);
this._meter.createObservableCounter(
enums.METRIC_NAMES.NETWORK_IO,
{
description: 'Network transmit and received bytes',
},
async observableResult => {
const networkData = await this._getNetworkData();
this._updateNetworkIO(observableResult, networkData);
},
{
description: 'Network transmit and received bytes',
}
);
}
Expand All @@ -241,12 +241,7 @@ export class HostMetrics extends BaseMetrics {
* Starts collecting metrics
*/
start() {
// initial collection
Promise.all([getMemoryData(), getCpuUsageData(), getNetworkData()]).then(
() => {
this._createMetrics();
}
);
this._createMetrics();
}

private _getMemoryData = throttle(getMemoryData, this._maxTimeoutUpdateMS);
Expand Down
Loading