Skip to content

Commit

Permalink
NAS-132758 / 25.04 / Container Metrics | Limit data aggregator with l…
Browse files Browse the repository at this point in the history
…et's say 300 latest items (#11111)

* NAS-132758: Container Metrics | Limit data aggregator with let's say 300 latest items

* NAS-132758: PR Update
  • Loading branch information
AlexKarpov98 authored Dec 2, 2024
1 parent 8f8ac70 commit 036fc6c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { VirtualizationStatus } from 'app/enums/virtualization.enum';
import { VirtualizationInstance, VirtualizationInstanceMetrics } from 'app/interfaces/virtualization.interface';
import { IxFormatterService } from 'app/modules/forms/ix-forms/services/ix-formatter.service';
import { InstanceMetricsLineChartComponent } from 'app/pages/virtualization/components/all-instances/instance-details/instance-metrics/instance-metrics-linechart/instance-metrics-linechart.component';
import { metricsMaxItemsCount } from 'app/pages/virtualization/virtualization.constants';
import { ApiService } from 'app/services/websocket/api.service';

@UntilDestroy()
Expand Down Expand Up @@ -74,26 +75,26 @@ export class InstanceMetricsComponent {
private updateData(fields: VirtualizationInstanceMetrics): void {
const now = Date.now();

const updateArray = <T>(current: T[], newValue: T): T[] => {
const updated = [...current, newValue];
return updated.length > metricsMaxItemsCount ? updated.slice(-metricsMaxItemsCount) : updated;
};

if (fields.cpu?.cpu_user_percentage !== undefined) {
this.cpuData.update((current) => ([
...current, fields.cpu.cpu_user_percentage,
]));
this.cpuData.update((current) => updateArray(current, fields.cpu.cpu_user_percentage));
}

if (fields.mem_usage?.mem_usage_ram_mib !== undefined) {
this.memoryData.update((current) => ([
...current,
fields.mem_usage.mem_usage_ram_mib,
]));
this.memoryData.update((current) => updateArray(current, fields.mem_usage.mem_usage_ram_mib));
}

if (fields.io_full_pressure?.io_full_pressure_full_60_percentage !== undefined) {
this.ioPressureData.update((current) => ([
...current,
this.ioPressureData.update((current) => updateArray(
current,
fields.io_full_pressure.io_full_pressure_full_60_percentage,
]));
));
}

this.timeLabels.update((current) => ([...current, now]));
this.timeLabels.update((current) => updateArray(current, now));
}
}
6 changes: 6 additions & 0 deletions src/app/pages/virtualization/virtualization.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @type {number}
* @description
* Latest 10 minutes on the chart (2 seconds API interval)
*/
export const metricsMaxItemsCount = 60 * 10 / 2;

0 comments on commit 036fc6c

Please sign in to comment.