gpt4 book ai didi

asp.net - 通过 asp.net 网页进行 Web 服务器监控

转载 作者:行者123 更新时间:2023-12-02 21:04:24 25 4
gpt4 key购买 nike

我想在网页上监控以下内容:

  • 总响应时间
  • 总字节
  • 吞吐量(请求/秒)
  • 使用的内存
  • 硬盘空间和 IO 问题
  • 服务器 CPU 开销
  • 错误(按错误代码)
  • MSSQL 加载
  • IIS 错误

我托管一小群服务器用于网络托管。我需要在 ASP.NET 中创建一个硬件 View ,以尽可能接近实时快照所发生的情况。

我听说过 Spiceworks 或其他完成此任务的方法。我同意这些都是很棒的工具,但我想对其进行编码并保持简单。

这是我想出/发现的一些现有代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string[] logicalDrives = System.Environment.GetLogicalDrives();
//do stuff to put it in the view.
}
protected static string ToSizeString(double bytes)
{
var culture = CultureInfo.CurrentUICulture;
const string format = "#,0.0";

if (bytes < 1024)
return bytes.ToString("#,0", culture);
bytes /= 1024;
if (bytes < 1024)
return bytes.ToString(format, culture) + " KB";
bytes /= 1024;
if (bytes < 1024)
return bytes.ToString(format, culture) + " MB";
bytes /= 1024;
if (bytes < 1024)
return bytes.ToString(format, culture) + " GB";
bytes /= 1024;
return bytes.ToString(format, culture) + " TB";
}
public static string ToApproximateString(this TimeSpan time)
{
if (time.TotalDays > 14)
return ((int)(time.TotalDays / 7)).ToString("#,0.0") + " weeks";
if (14 - time.TotalDays < .75)
return "two weeks";
if (time.TotalDays > 1)
return time.TotalDays.ToString("#,0.0") + " days";
else if (time.TotalHours > 1)
return time.TotalHours.ToString("#,0.0") + " hours";
else if (time.TotalMinutes > 1)
return time.TotalMinutes.ToString("#,0.0") + " minutes";
else
return time.TotalSeconds.ToString("#,0.0") + " seconds";
}
}
}

最佳答案

性能计数器通过 System.Diagnostics.PerformanceCounter 类公开。 Here是 ASP.NET 的一些性能计数器。并且,另一个how-to .

关于asp.net - 通过 asp.net 网页进行 Web 服务器监控,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11317498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com