Determine memory used by asp.net cache in shared hosting

谁都会走 提交于 2019-11-30 21:02:23
Aristos

One fast way to see how many working memory your application use is to direct ask the garbage collection.

long bytes = GC.GetTotalMemory(false);
txtMemoryUsed.Text = bytes.ToString();

and use this literal <asp:Literal runat="server" ID="txtMemorysUsed" EnableViewState="false" />

But you can get more details using the PerformanceCounter, for example you can get how many virtual memory the pools used by this code:

 var oPerfCounter = new PerformanceCounter();
oPerfCounter.CategoryName = "Process";
oPerfCounter.CounterName = "Virtual Bytes";
oPerfCounter.InstanceName = "aspnet_wp";
txtMemorysUsed.Text = "Virtual Bytes: " + oPerfCounter.RawValue + " bytes";

You can use all this parameters to get information's for your pool.

Processor(_Total)\% Processor Time
Process(aspnet_wp)\% Processor Time
Process(aspnet_wp)\Private Bytes
Process(aspnet_wp)\Virtual Bytes
Process(aspnet_wp)\Handle Count
Microsoft® .NET CLR Exceptions\# Exceps thrown / sec
ASP.NET\Application Restarts
ASP.NET\Requests Rejected
ASP.NET\Worker Process Restarts (not applicable to IIS 6.0)
Memory\Available Mbytes
Web Service\Current Connections
Web Service\ISAPI Extension Requests/sec

for example, this parametres get the cpu load.

oPerfCounter.CategoryName = "Processor";
oPerfCounter.CounterName = "% Processor Time";
oPerfCounter.InstanceName = "_Total";
txtOutPut.Text = "Current CPU Usage: " + oPerfCounter.NextValue() + "%";

reference: http://msdn.microsoft.com/en-us/library/ms972959.aspx

relative: Monitoring ASP.NET application memory from within the application

I have test that on local iis and works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!