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

NAS-132705 / 25.04 / Adopts middleware changes to CPU and memory reporting on the dashboard widgets #11317

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions src/app/interfaces/events/memory-stats-event.interface.ts

This file was deleted.

66 changes: 12 additions & 54 deletions src/app/interfaces/reporting.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,22 @@ export interface ReportingRealtimeUpdate {
disks: DisksUpdate;
interfaces: AllNetworkInterfacesUpdate;
memory: MemoryUpdate;
virtual_memory: VirtualMemoryUpdate;
zfs: ZfsUpdate;
}

export interface AllCpusUpdate {
[cpuNumber: number]: CpuUpdate;
average: CpuUpdate;
temperature_celsius: number[];
}

export interface CpuUpdate {
guest: number;
guest_nice: number;
user: number;
nice: number;
system: number;
idle: number;
iowait: number;
irq: number;
nice: number;
softirq: number;
steal: number;
system: number;
usage: number;
user: number;
guest: number;
guest_nice: number;
aggregated_usage: number;
[key: `core${number}_usage`]: number;
temperature_celsius: number[];
}

export interface DisksUpdate {
Expand All @@ -49,47 +43,11 @@ export interface NetworkInterfaceUpdate {
}

export interface MemoryUpdate {
classes: {
apps: number;
arc: number;
buffers: number;
cache: number;
page_tables: number;
slab_cache: number;
swap_cache: number;
unused: number;
};
extra: {
active: number;
committed: number;
inactive: number;
mapped: number;
vmalloc_used: number;
};
swap: {
total: number;
used: number;
};
}

export interface VirtualMemoryUpdate {
active: number;
available: number;
buffers: number;
cached: number;
free: number;
inactive: number;
percent: number;
shared: number;
slab: number;
total: number;
used: number;
}

export interface ZfsUpdate {
arc_max_size: number;
arc_size: number;
cache_hit_ratio: number;
arc_free_memory: number;
arc_available_memory: number;
physical_memory_total: number;
physical_memory_available: number;
}

export interface ReportingQueryOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { TranslateModule } from '@ngx-translate/core';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
import { map, throttleTime } from 'rxjs';
import { MemoryStatsEventData } from 'app/interfaces/events/memory-stats-event.interface';
import { MemoryUpdate } from 'app/interfaces/reporting.interface';
import { FileSizePipe } from 'app/modules/pipes/file-size/file-size.pipe';
import { ApiService } from 'app/modules/websocket/api.service';
import { DockerStore } from 'app/pages/apps/store/docker.store';
Expand Down Expand Up @@ -50,20 +50,16 @@ export class AppResourcesCardComponent implements OnInit {
throttleTime(2000),
untilDestroyed(this),
).subscribe((update) => {
if (update?.cpu?.average) {
this.cpuPercentage.set(parseInt(update.cpu.average.usage.toFixed(1)));
if (update?.cpu?.aggregated_usage) {
this.cpuPercentage.set(parseInt(update.cpu.aggregated_usage.toFixed(1)));
}

if (update?.virtual_memory) {
const memStats: MemoryStatsEventData = { ...update.virtual_memory };
if (update?.memory) {
const memStats: MemoryUpdate = { ...update.memory };

// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
if (update.zfs && update.zfs.arc_size !== null) {
memStats.arc_size = update.zfs.arc_size;
}
const services = memStats.total - memStats.free - memStats.arc_size;
const services = memStats.physical_memory_total - memStats.physical_memory_available - memStats.arc_size;
this.memoryUsed.set(memStats.arc_size + services);
this.memoryTotal.set(memStats.total);
this.memoryTotal.set(memStats.physical_memory_total);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ describe('getDefaultWidgets', () => {
it('should return all default widgets when isHaLicensed is true', () => {
const result: WidgetGroup[] = getDefaultWidgets(true);

expect(result).toHaveLength(9);
expect(result).toHaveLength(8);
expect(result[0].slots[0]!.type).toBe(WidgetType.SystemInfoActive);
expect(result[1].slots[0]!.type).toBe(WidgetType.SystemInfoPassive);
});

it('should return default widgets without the second widget when isHaLicensed is false', () => {
const result: WidgetGroup[] = getDefaultWidgets(false);

expect(result).toHaveLength(8);
expect(result).toHaveLength(7);
expect(result[0].slots[0]!.type).toBe(WidgetType.SystemInfoActive);
expect(result[1].slots[0]!.type).toBe(WidgetType.CpuUsageBar);
});
});
7 changes: 0 additions & 7 deletions src/app/pages/dashboard/services/get-default-widgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ const defaultWidgets: WidgetGroup[] = [
{ type: WidgetType.SystemInfoPassive },
],
},
{
layout: WidgetGroupLayout.Halves,
slots: [
{ type: WidgetType.CpuUsageBar },
{ type: WidgetType.CpuTemperatureBar },
],
},
{
layout: WidgetGroupLayout.QuartersAndHalf,
slots: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { subHours, subMinutes } from 'date-fns';
import {
Observable, Subject, catchError, combineLatestWith, debounceTime,
filter,
forkJoin, map, of, repeat, shareReplay, switchMap, take, throttleTime, timer, startWith,
forkJoin, map, of, repeat, shareReplay, startWith, switchMap, take, throttleTime, timer,
} from 'rxjs';
import { SystemUpdateStatus } from 'app/enums/system-update.enum';
import { LoadingState, toLoadingState } from 'app/helpers/operators/to-loading-state.helper';
Expand Down
1 change: 0 additions & 1 deletion src/app/pages/dashboard/types/widget.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export enum WidgetType {
CpuUsageGauge = 'cpu-usage-gauge',
CpuUsageRecent = 'cpu-usage-recent',
CpuUsageBar = 'cpu-usage-bar',
CpuTemperatureBar = 'cpu-temperature-bar',
Storage = 'storage',
SystemInfoActive = 'system-info-active',
SystemInfoPassive = 'system-info-passive',
Expand Down
2 changes: 0 additions & 2 deletions src/app/pages/dashboard/widgets/all-widgets.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { appNetworkWidget } from 'app/pages/dashboard/widgets/apps/widget-app-ne
import { backupTasksWidget } from 'app/pages/dashboard/widgets/backup/widget-backup/widget-backup.definition';
import { cpuWidget } from 'app/pages/dashboard/widgets/cpu/widget-cpu/widget-cpu.definition';
import { cpuModelWidget } from 'app/pages/dashboard/widgets/cpu/widget-cpu-model/widget-cpu-model.definition';
import { cpuTemperatureBarWidget } from 'app/pages/dashboard/widgets/cpu/widget-cpu-temperature-bar/widget-cpu-temperature-bar.definition';
import { cpuUsageBarWidget } from 'app/pages/dashboard/widgets/cpu/widget-cpu-usage-bar/widget-cpu-usage-bar.definition';
import { cpuUsageGaugeWidget } from 'app/pages/dashboard/widgets/cpu/widget-cpu-usage-gauge/widget-cpu-usage-gauge.definition';
import { cpuUsageRecentWidget } from 'app/pages/dashboard/widgets/cpu/widget-cpu-usage-recent/widget-cpu-usage-recent.definition';
Expand Down Expand Up @@ -59,7 +58,6 @@ export const widgetRegistry = {
[WidgetType.CpuUsageGauge]: cpuUsageGaugeWidget,
[WidgetType.CpuUsageRecent]: cpuUsageRecentWidget,
[WidgetType.CpuUsageBar]: cpuUsageBarWidget,
[WidgetType.CpuTemperatureBar]: cpuTemperatureBarWidget,
[WidgetType.Storage]: storageWidget,
[WidgetType.SystemInfoActive]: systemInfoActiveWidget,
[WidgetType.SystemInfoPassive]: systemInfoPassiveWidget,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ describe('CpuChartGaugeComponent', () => {
realtimeUpdates$: of({
fields: {
cpu: {
0: { usage: 6 },
1: { usage: 30 },
2: { usage: 70 },
3: { usage: 9 },
average: { usage: 75 },
temperature_celsius: [31, 83],
core0_usage: 6,
core1_usage: 30,
core2_usage: 70,
core3_usage: 9,
aggregated_usage: 75,
},
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class CpuChartGaugeComponent {
protected isLoading = computed(() => !this.cpuData());

protected cpuAvg: Signal<GaugeConfig> = computed(() => {
const data = ['Load', parseInt(this.cpuData().average.usage.toFixed(1))];
const data = ['Load', parseInt(this.cpuData().aggregated_usage.toFixed(1))];
return {
label: false,
data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ describe('CpuCoreBarComponent', () => {
realtimeUpdates$: of({
fields: {
cpu: {
0: { usage: 6 },
1: { usage: 30 },
2: { usage: 70 },
3: { usage: 9 },
average: { usage: 75 },
temperature_celsius: [31, 83],
core0_usage: 6,
core1_usage: 30,
core2_usage: 70,
core3_usage: 9,
aggregated_usage: 75,
},
},
}),
Expand All @@ -56,7 +55,6 @@ describe('CpuCoreBarComponent', () => {
labels: ['1', '2', '3', '4'],
datasets: [
{ data: [6, 30, 70, 9] },
{ data: [31, 83, 0, 0] },
],
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
ChangeDetectionStrategy, Component,
computed,
input,
} from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { TinyColor } from '@ctrl/tinycolor';
Expand All @@ -22,17 +21,18 @@ import { WidgetResourcesService } from 'app/pages/dashboard/services/widget-reso
imports: [NgxSkeletonLoaderModule, BaseChartDirective],
})
export class CpuCoreBarComponent {
hideTemperature = input<boolean>(false);
hideUsage = input<boolean>(false);

protected cpuData = toSignal(this.resources.realtimeUpdates$.pipe(
map((update) => update.fields.cpu),
));

protected isLoading = computed(() => !this.cpuData());
protected coreCount = computed(() => {
const cpus = Object.keys(this.cpuData())
.map(Number)
.filter((key) => key.startsWith('core'))
.map((key) => {
const splitCoreTitle = key.split('_')[0];
return Number(splitCoreTitle.replace('core', ''));
})
.filter((key) => !Number.isNaN(key));

return Math.max(...cpus) + 1;
Expand Down Expand Up @@ -115,19 +115,13 @@ export class CpuCoreBarComponent {

protected parseCpuData(cpuData: AllCpusUpdate): GaugeData[] {
const usageColumn: GaugeData = ['Usage'];
const temperatureColumn: GaugeData = ['Temperature'];

for (let i = 0; i < this.coreCount(); i++) {
const usage = parseInt(cpuData[i]?.usage?.toFixed(1) || '0');
const temperature = parseInt(cpuData.temperature_celsius?.[i]?.toFixed(0) || '0');
const usage = parseInt(cpuData[`core${i}_usage`]?.toFixed(1) || '0');

usageColumn.push(usage);
temperatureColumn.push(temperature);
}

return [
this.hideUsage() ? [] : usageColumn,
this.hideTemperature() ? [] : temperatureColumn,
];
return [usageColumn];
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading