添加系统版本
This commit is contained in:
parent
4394a97332
commit
edf737dc74
|
|
@ -1,6 +1,9 @@
|
|||
using CodeRelease.Model;
|
||||
using CodeRelease.Utile;
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
|
@ -29,4 +32,26 @@ app.MapGet("/", () =>
|
|||
{
|
||||
return "请求成功";
|
||||
}).WithName("默认请求");
|
||||
|
||||
var startDateTime = DateTime.Now;
|
||||
var InformationalVersion = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
|
||||
//Console.WriteLine($"version:{InformationalVersion}");
|
||||
app.MapGet("/system", () =>
|
||||
{
|
||||
|
||||
using Process currentProcess = Process.GetCurrentProcess();
|
||||
// CPU使用率 (一般是一个0-100之间的值,但实际是时间占比,需要转换)
|
||||
double cpuUsage = currentProcess.TotalProcessorTime.TotalMilliseconds / Environment.TickCount * 100;
|
||||
// 已用内存 (字节)
|
||||
long memoryUsage = currentProcess.WorkingSet64;
|
||||
return new
|
||||
{
|
||||
msg = $"系统版本:{InformationalVersion},启动时间:{startDateTime.ToString("yyyy-MM-dd HH:mm:ss")},已安全运行时间:{DateTime.Now.Subtract(startDateTime).TotalMinutes.ToString("#.##")}分钟",
|
||||
InformationalVersion,
|
||||
startDateTime,
|
||||
MemoryUsage = $"{memoryUsage / (1024.0 * 1024.0):F2}MB",
|
||||
CPUUsage = $"{cpuUsage:F2}%"
|
||||
|
||||
};
|
||||
}).WithName("获取系统数据");
|
||||
app.Run();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user