实时监控iis网站流量

  • 格式:doc
  • 大小:82.00 KB
  • 文档页数:3

站办理员通常在维护好多iis站点的时间(成百上千),每每会遇到iis 占用带宽或体系资源较多的环境,而导致整个iis相应迟钝。

这种环境我们非常想知道是iis中哪些站点占用资源这么大,从而找出问题的源头。

许多站长一样平常都市在这时间打开iis 日志记录成果,来分析iis日志记录,在汪洋大海中征采我们必要的信息,而在这个进程中有80%的人

徒劳无获。

为了解决这个问题:在这里把最近写的一个iis网站全面信息实时监控程序和大家分享,希望给需要者帮助。

程序是用.net 开发的,下面讲讲具体的实现。

步调实现:

想必各人都有听说过wmi这个东西,你猜对了我们步调便是读取wmi性能技能器参数,实现的iis站点监控的。

WMI 阐明参见/view/442461.htm 网上一大堆,本身看看就明确了。

其实我们议决WMI 可以干许多事情,比方像得到本地和远程谋略机硬件信息,当前进程信息,远程重启,等成果。

是不是听起来挺故意思吧,呵呵,其实好多体系办理软件都是议决WMI来实现的---优化各人等等。

新打仗WMI以为它是很难一样,其实不尽然。WMI其实便是一个数据库,存放着谋略机全部的信息,它还提供了

一种类似于sql 的数据查问语言,叫WQL 我们可以议决这个语言查找数据。 附个WQL查问器,各人可用来查问一下信息试试,其实要害是参数的熟习。

言反正传,我们连续实现我们的步调,其实有了刚才的根本我们就很简略了,我们便是议决WQL去查问性能计数器的属性值了。

看代码:

//页面绑定方法

private void bind()

{

int i = 0;

try

{

//下面就是.net 操作WMI 的代码了

//Win32_PerfFormattedData_W3SVC_WebService就是我们说的性能计数器实体,我们用WQL执行查询就行

ManagementObjectSearcher query = new ManagementObjectSearcher(

@" oot\cimv2","SELECT

Name,TotalBytesReceived,TotalBytesSent,TotalBytesTransfered," +

"TotalFilesSent,TotalFilesReceived,TotalFilesTransferred,TotalGetRequests,TotalPostRequests,TotalMethodRequests,TotalNotFoundErrors," +

"CurrentConnections FROM Win32_PerfFormattedData_W3SVC_WebService");

ManagementObjectCollection queryCollection = query.Get(); //Get获取集合并赋给

Collention

foreach (ManagementObject mo in queryCollection) //偏历集合

{

i++;

DataRow webInfo = dataTable.NewRow();

webInfo["ID"] = i;

webInfo["Name"] = mo.Properties["Name"].Value.ToString();

double receivedBytes =

Convert.ToDouble(mo.Properties["TotalBytesReceived"].Value);

receivedBytes = receivedBytes / 1024;

webInfo["TotalBytesReceived"] =

Convert.ToDouble(receivedBytes.ToString("0.0")); double sendBytes = Convert.ToDouble(mo.Properties["TotalBytesSent"].Value);

sendBytes = sendBytes / 1024;

webInfo["TotalBytesSent"] = Convert.ToDouble(sendBytes.ToString("0.0"));

double sendReciveSUM =

Convert.ToDouble(mo.Properties["TotalBytesTransfered"].Value);

sendReciveSUM = sendReciveSUM / 1024;

webInfo["TotalBytesTransfered"] =

Convert.ToDouble(sendReciveSUM.ToString("0.0"));

webInfo["TotalFilesSent"] =

Convert.ToInt64(mo.Properties["TotalFilesSent"].Value);

webInfo["TotalFilesReceived"] =

Convert.ToInt64(mo.Properties["TotalFilesReceived"].Value);

webInfo["TotalFilesTransferred"] =

Convert.ToInt64(mo.Properties["TotalFilesTransferred"].Value);

webInfo["TotalGetRequests"] =

Convert.ToInt64(mo.Properties["TotalGetRequests"].Value);

webInfo["TotalPostRequests"] =

Convert.ToInt64(mo.Properties["TotalPostRequests"].Value);

webInfo["TotalMethodRequests"] =

Convert.ToInt64(mo.Properties["TotalMethodRequests"].Value);

webInfo["TotalNotFoundErrors"] =

Convert.ToInt64(mo.Properties["TotalNotFoundErrors"].Value);

webInfo["CurrentConnections"] =

Convert.ToInt64(mo.Properties["CurrentConnections"].Value);

dataTable.Rows.Add(webInfo);

}

this.dataGridView1.DataSource = dataTable;

Refresh();

}

catch (System.Exception ex)

{

MessageBox.Show(error);

}

}