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

Improve size storage and memory #122

Merged
merged 1 commit into from
Jan 10, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@ else
<MudDataGridPager T="DataVmEx" />
</PagerContent>
</AHDataGrid>
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
* SPDX-License-Identifier: AGPL-3.0-only
*/
Expand Down Expand Up @@ -89,44 +89,44 @@ protected override async Task OnInitializedAsync()
.GroupBy(a => a.VmId)
.Select(a => new DataVmEx
{
Data = a.ToList(),
Data = [.. a],
RrdData = a.Select(a => new VmRrdData()
{
Time = new DateTimeOffset(a.Date).ToUnixTimeSeconds(),
CpuSize = a.CpuSize,
CpuUsagePercentage = a.CpuUsagePercentage,
MemorySize = a.MemorySize,
MemoryUsage = a.MemoryUsage,
MemorySize = Convert.ToUInt64(a.MemorySize),
MemoryUsage = Convert.ToUInt64(a.MemoryUsage),
}),

VmId = a.Key,
VmName = string.Join(",", a.Select(a => a.VmName).Distinct()),
Node = string.Join(",", a.Select(a => a.Node).Distinct()),
CpuSize = a.Max(a => a.CpuSize),
CpuUsagePercentage = a.Average(a => a.CpuUsagePercentage),
MemorySize = a.Max(a => a.MemorySize),
MemoryUsage = Convert.ToInt64(a.Average(a => a.MemoryUsage)),
VmName = string.Join(",", a.Select(b => b.VmName).Distinct()),
Node = string.Join(",", a.Select(b => b.Node).Distinct()),
CpuSize = a.Max(b => b.CpuSize),
CpuUsagePercentage = a.Average(b => b.CpuUsagePercentage),
MemorySize = a.Max(b => b.MemorySize),
MemoryUsage = Convert.ToInt64(a.Average(b => b.MemoryUsage)),

StorageMax = a.Max(a => a.Storages.Sum(a => a.Size)),
StorageMax = a.Max(b => b.Storages.Select(a => a.Size).Sum()),

CpuCost = Math.Round(a.Select(a => a.CpuSize *
(a.CpuUsagePercentage == 0
CpuCost = Math.Round(a.Select(b => b.CpuSize *
(b.CpuUsagePercentage == 0
? moduleClusterOptions.CostDayCpuStopped
: moduleClusterOptions.CostDayCpuRunning))
.Sum(), 2),

MemoryCost = Math.Round(a.Select(a => a.MemorySize / 1024.0 / 1024.0 / 1024.0 *
(a.CpuUsagePercentage == 0
MemoryCost = Math.Round(a.Select(b => b.MemorySize / 1024.0 / 1024.0 / 1024.0 *
(b.CpuUsagePercentage == 0
? moduleClusterOptions.CostDayMemoryGbStopped
: moduleClusterOptions.CostDayMemoryGbRunning))
.Sum(), 2),

StorageCost = Math.Round(a.SelectMany(a => a.Storages)
.Select(a => a.Size / 1024.0 / 1024.0 / 1024.0 *
(a.DataVm.CpuUsagePercentage == 0
? GetData(a.Storage).CostDayGbStopped
: GetData(a.Storage).CostDayGbRunning))
.Sum(), 2)
StorageCost = Math.Round(a.SelectMany(b => b.Storages)
.Select(b => b.Size / 1024.0 / 1024.0 / 1024.0 *
(b.DataVm.CpuUsagePercentage == 0
? GetData(b.Storage).CostDayGbStopped
: GetData(b.Storage).CostDayGbRunning))
.Sum(), 2)
})
.ToArray();

Expand Down Expand Up @@ -154,4 +154,4 @@ private void Scan()
JobService.Schedule<Job>(a => a.ScanAsync(ClusterName), TimeSpan.FromSeconds(10));
UINotifier.Show(L["Scan jobs started!"], UINotifierSeverity.Info);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/*
/*
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
* SPDX-License-Identifier: AGPL-3.0-only
*/
using Corsinvest.ProxmoxVE.Admin.Core.Extensions;

namespace Corsinvest.ProxmoxVE.Admin.ClusterUsage.Components;

public partial class RenderOptions
Expand All @@ -19,4 +17,4 @@ public override async Task SaveAsync()

await base.SaveAsync();
}
}
}
5 changes: 2 additions & 3 deletions src/Corsinvest.ProxmoxVE.Admin.ClusterUsage/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
using Corsinvest.ProxmoxVE.Admin.ClusterUsage.Repository;
using Corsinvest.ProxmoxVE.Admin.Core.Extensions;
using Corsinvest.ProxmoxVE.Admin.Core.Models;
using Corsinvest.ProxmoxVE.Api;
using Corsinvest.ProxmoxVE.Api.Extension;
Expand Down Expand Up @@ -81,8 +80,8 @@ public static async Task ScanAsync(IServiceScope scope, string clusterName)
Node = vm.Node,
CpuSize = Convert.ToInt32(vm.CpuSize),
CpuUsagePercentage = rrdData.Select(a => a.CpuUsagePercentage).DefaultIfEmpty(0).Average(),
MemorySize = vm.MemorySize,
MemoryUsage = Convert.ToInt64(rrdData.Select(a => a.MemoryUsage).DefaultIfEmpty(0).Average())
MemorySize = Convert.ToInt64(vm.MemorySize),
MemoryUsage = Convert.ToInt64(rrdData.Average(a => Convert.ToInt64(a.MemoryUsage)))
};

//storages
Expand Down
3 changes: 2 additions & 1 deletion src/Corsinvest.ProxmoxVE.Admin.ClusterUsage/_Imports.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
* SPDX-License-Identifier: AGPL-3.0-only
*/
Expand All @@ -12,4 +12,5 @@
global using Microsoft.Extensions.Options;
global using MudBlazor;
global using System.ComponentModel.DataAnnotations;
global using Corsinvest.ProxmoxVE.Admin.Core.Extensions;