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

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

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

我托管了一个用于Web托管的小型服务器集群.我需要在ASP.NET中创建一个硬件视图,以尽可能接近实时快照.

我听说过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.

点赞