Added basic dashboard
This commit is contained in:
parent
7cfa457103
commit
4efbbe8a4e
3 changed files with 182 additions and 0 deletions
|
@ -43,6 +43,7 @@
|
||||||
<PackageReference Include="rix0rrr.BeaconLib" Version="1.0.2" />
|
<PackageReference Include="rix0rrr.BeaconLib" Version="1.0.2" />
|
||||||
<PackageReference Include="swashbuckle" Version="5.6.0" />
|
<PackageReference Include="swashbuckle" Version="5.6.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />
|
||||||
|
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="7.0.0" />
|
||||||
<PackageReference Include="YamlDotNet" Version="12.3.1" />
|
<PackageReference Include="YamlDotNet" Version="12.3.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
35
LANCommander/Models/PerformanceChartData.cs
Normal file
35
LANCommander/Models/PerformanceChartData.cs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
using MudBlazor;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace LANCommander.Models
|
||||||
|
{
|
||||||
|
public class PerformanceChartData
|
||||||
|
{
|
||||||
|
public PerformanceCounterData ProcessorUtilization { get; set; }
|
||||||
|
public Dictionary<string, PerformanceCounterData> NetworkUploadRate { get; set; }
|
||||||
|
public Dictionary<string, PerformanceCounterData> NetworkDownloadRate { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PerformanceCounterData
|
||||||
|
{
|
||||||
|
public PerformanceCounter PerformanceCounter { get; set; }
|
||||||
|
public double[] Data { get; set; }
|
||||||
|
|
||||||
|
public ChartSeries ToSeries(string name)
|
||||||
|
{
|
||||||
|
return new ChartSeries
|
||||||
|
{
|
||||||
|
Name = name,
|
||||||
|
Data = Data
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ChartSeries> ToSeriesList(string name)
|
||||||
|
{
|
||||||
|
return new List<ChartSeries>
|
||||||
|
{
|
||||||
|
ToSeries(name)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
146
LANCommander/Pages/Dashboard.razor
Normal file
146
LANCommander/Pages/Dashboard.razor
Normal file
|
@ -0,0 +1,146 @@
|
||||||
|
@page "/Dashboard"
|
||||||
|
|
||||||
|
@using System.Diagnostics;
|
||||||
|
@using LANCommander.Models;
|
||||||
|
|
||||||
|
<MudGrid Justify="Justify.Center">
|
||||||
|
<MudItem>
|
||||||
|
<MudCard>
|
||||||
|
<MudCardHeader>
|
||||||
|
<CardHeaderContent>
|
||||||
|
<MudText Typo="Typo.h6">CPU Utilization (%)</MudText>
|
||||||
|
</CardHeaderContent>
|
||||||
|
</MudCardHeader>
|
||||||
|
<MudCardContent>
|
||||||
|
@if (PerformanceChartData.ProcessorUtilization != null && PerformanceChartData.ProcessorUtilization.PerformanceCounter != null)
|
||||||
|
{
|
||||||
|
<MudChart ChartType="ChartType.Line" ChartSeries="@(PerformanceChartData.ProcessorUtilization.ToSeriesList("CPU %"))" Width="100%" Height="250px"></MudChart>
|
||||||
|
}
|
||||||
|
</MudCardContent>
|
||||||
|
</MudCard>
|
||||||
|
</MudItem>
|
||||||
|
|
||||||
|
<MudItem>
|
||||||
|
<MudCard>
|
||||||
|
<MudCardHeader>
|
||||||
|
<CardHeaderContent>
|
||||||
|
<MudText Typo="Typo.h6">Upload Rate (MB/s)</MudText>
|
||||||
|
</CardHeaderContent>
|
||||||
|
</MudCardHeader>
|
||||||
|
<MudCardContent>
|
||||||
|
<MudChart ChartType="ChartType.Line" ChartSeries="@PerformanceChartData.NetworkUploadRate.Select(x => x.Value.ToSeries(x.Key)).ToList()" Width="100%" Height="250px"></MudChart>
|
||||||
|
</MudCardContent>
|
||||||
|
</MudCard>
|
||||||
|
</MudItem>
|
||||||
|
|
||||||
|
<MudItem>
|
||||||
|
<MudCard>
|
||||||
|
<MudCardHeader>
|
||||||
|
<CardHeaderContent>
|
||||||
|
<MudText Typo="Typo.h6">Download Rate (MB/s)</MudText>
|
||||||
|
</CardHeaderContent>
|
||||||
|
</MudCardHeader>
|
||||||
|
<MudCardContent>
|
||||||
|
<MudChart ChartType="ChartType.Line" ChartSeries="@PerformanceChartData.NetworkDownloadRate.Select(x => x.Value.ToSeries(x.Key)).ToList()" Width="100%" Height="250px"></MudChart>
|
||||||
|
</MudCardContent>
|
||||||
|
</MudCard>
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
int cpuTime = 0;
|
||||||
|
|
||||||
|
int RecordTime = 60;
|
||||||
|
|
||||||
|
private PerformanceChartData PerformanceChartData = new PerformanceChartData()
|
||||||
|
{
|
||||||
|
ProcessorUtilization = new PerformanceCounterData(),
|
||||||
|
NetworkUploadRate = new Dictionary<string, PerformanceCounterData>(),
|
||||||
|
NetworkDownloadRate = new Dictionary<string, PerformanceCounterData>()
|
||||||
|
};
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
var timer = new System.Timers.Timer();
|
||||||
|
|
||||||
|
timer.Interval = 1000;
|
||||||
|
|
||||||
|
timer.Elapsed += async (s, e) =>
|
||||||
|
{
|
||||||
|
RefreshLiveData();
|
||||||
|
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
};
|
||||||
|
|
||||||
|
timer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshLiveData()
|
||||||
|
{
|
||||||
|
RefreshProcessorUtilization();
|
||||||
|
RefreshNetworkUsage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshProcessorUtilization()
|
||||||
|
{
|
||||||
|
if (PerformanceChartData.ProcessorUtilization.PerformanceCounter == null)
|
||||||
|
PerformanceChartData.ProcessorUtilization.PerformanceCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
|
||||||
|
|
||||||
|
PerformanceChartData.ProcessorUtilization.Data = ShiftArrayAndInsert<double>(PerformanceChartData.ProcessorUtilization.Data, PerformanceChartData.ProcessorUtilization.PerformanceCounter.NextValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshNetworkUsage()
|
||||||
|
{
|
||||||
|
var category = new PerformanceCounterCategory("Network Interface");
|
||||||
|
|
||||||
|
foreach (var instance in category.GetInstanceNames())
|
||||||
|
{
|
||||||
|
if (!PerformanceChartData.NetworkUploadRate.ContainsKey(instance))
|
||||||
|
PerformanceChartData.NetworkUploadRate[instance] = new PerformanceCounterData()
|
||||||
|
{
|
||||||
|
PerformanceCounter = new PerformanceCounter("Network Interface", "Bytes Sent/sec", instance),
|
||||||
|
Data = new double[RecordTime]
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!PerformanceChartData.NetworkDownloadRate.ContainsKey(instance))
|
||||||
|
PerformanceChartData.NetworkDownloadRate[instance] = new PerformanceCounterData()
|
||||||
|
{
|
||||||
|
PerformanceCounter = new PerformanceCounter("Network Interface", "Bytes Received/sec", instance),
|
||||||
|
Data = new double[RecordTime]
|
||||||
|
};
|
||||||
|
|
||||||
|
PerformanceChartData.NetworkUploadRate[instance].Data = ShiftArrayAndInsert<double>(PerformanceChartData.NetworkUploadRate[instance].Data, (double)PerformanceChartData.NetworkUploadRate[instance].PerformanceCounter.NextValue() / (1024 * 1024));
|
||||||
|
PerformanceChartData.NetworkDownloadRate[instance].Data = ShiftArrayAndInsert<double>(PerformanceChartData.NetworkDownloadRate[instance].Data, (double)PerformanceChartData.NetworkDownloadRate[instance].PerformanceCounter.NextValue() / (1024 * 1024));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private T[] ShiftArrayAndInsert<T>(T[] array, T input)
|
||||||
|
{
|
||||||
|
if (array == null || array.Length < RecordTime)
|
||||||
|
{
|
||||||
|
array = new T[RecordTime];
|
||||||
|
}
|
||||||
|
|
||||||
|
Array.Copy(array, 1, array, 0, array.Length - 1);
|
||||||
|
|
||||||
|
array[array.Length - 1] = input;
|
||||||
|
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PerformanceCounter[] GetCounters(string categoryName)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var category = PerformanceCounterCategory.GetCategories().First(c => c.CategoryName == categoryName);
|
||||||
|
|
||||||
|
var instanceName = Process.GetCurrentProcess().ProcessName;
|
||||||
|
|
||||||
|
return category.GetCounters(instanceName);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return new PerformanceCounter[] { };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue