Skip to content

Commit

Permalink
feat(host-metrics): upgrade api-metrics to v0.28.0 (open-telemetry#990)
Browse files Browse the repository at this point in the history
Co-authored-by: Gerhard Stöbich <deb2001-github@yahoo.de>
Co-authored-by: Rauno Viskus <Rauno56@users.noreply.github.com>
  • Loading branch information
3 people authored May 5, 2022
1 parent 2ea76cc commit 669d34b
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 186 deletions.
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

0 comments on commit 669d34b

Please sign in to comment.