首頁  >  文章  >  後端開發  >  ASP.NET中怎樣用MVC5的MiniProfiler對MVC進行效能監控

ASP.NET中怎樣用MVC5的MiniProfiler對MVC進行效能監控

巴扎黑
巴扎黑原創
2017-08-06 10:48:041192瀏覽

這篇文章主要為大家詳細介紹了ASP.NET MVC5使用MiniProfiler監控MVC性能,具有一定的參考價值,感興趣的小伙伴們可以參考一下

MiniProfiler ,一個簡單而有效的迷你剖析器,可以有效的即時監控頁面。透過直接引用、Ajax、Iframe形式存取的其它頁面進行監控,監控內容包括資料庫內容,並可以顯示資料庫存取的SQL。

1.安裝

先新建一個 asp.net mvc 項目

右鍵項目,管理NuGet套件。 安裝MiniProfiler.Mvc4和MiniProfiler

ps:MiniProfiler.MVC4的NuGet套件(此MVC4套件支援MVC5)

#或也可以開啟程式包管理控制台輸入指令進行安裝

Install-Package MiniProfiler -Version 3.2.0.157

##Install-Package MiniProfiler.Mvc4 -Version 3.0.11

2.將以下內容加入到Application_Start()Global.asax中

##

protected void Application_Start()
{
 ...
 GlobalFilters.Filters.Add(new ProfilingActionFilter());

 var copy = ViewEngines.Engines.ToList();
 ViewEngines.Engines.Clear();
 foreach (var item in copy)
 {
  ViewEngines.Engines.Add(new ProfilingViewEngine(item));
 }
}

3.將以下內容新增至“Application_BeginRequest()”和“Application_EndRequest()”,也在Global.asax中

##
protected void Application_BeginRequest()
{
 if (Request.IsLocal)
 {
  MiniProfiler.Start();
 }
}

protected void Application_EndRequest()
{
 MiniProfiler.Stop();
}


#4.將以下內容新增到_Layout.cshtml(就在36cc49f0c466276486e50c850b7e4956標籤之前):

 @StackExchange.Profiling.MiniProfiler.RenderIncludes()
</body>
</html>


5.將以下內容加入2861eb3f6fae88c0d4805c26e0048c48 Web.config 的部分中

<system.webServer>
 ...
 <handlers>
  ...
  <add name="MiniProfiler" path="mini-profiler-resources/*" verb="*"
    type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified"
    preCondition="integratedMode" />
  ...
 </handlers>
</system.webServer>

如果你在專案中使用了Entity Framework ,那麼你可以安裝MiniProfiler.EF6軟體包,在Application_Start()在Global.asax 結尾添加了以下內容: MiniProfilerEF6.Initialize();

一個簡單的對MVC性能的監控就這樣了,其實他還有很多功能,比如說能夠通過不同的參數檢測並反白顯示執行相同查詢的區域。這樣您就可以快速找到可能批量的查詢。

還可以記錄所有的ajax的調用,查看最近100個分析請求的分析資訊等。

結果展示:

以上是ASP.NET中怎樣用MVC5的MiniProfiler對MVC進行效能監控的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn