2017-06-22 71 views
0

我们希望使用Azure Application Insights监视我们的应用程序之一。它与网页API一个ASP.Net MVC 4应用2.我在Azure中创建了一个新的应用程序洞察资源,我已经安装了以下的NuGet包到项目:应用程序洞察使用ASP.Net MVC和Web Api的Live Metrics

<package id="Microsoft.ApplicationInsights" version="2.3.0" targetFramework="net462" /> 
<package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.0.7" targetFramework="net462" /> 
<package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.3.0" targetFramework="net462" /> 
<package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.3.0" targetFramework="net462" /> 
<package id="Microsoft.ApplicationInsights.TraceListener" version="2.2.0" targetFramework="net462" /> 
<package id="Microsoft.ApplicationInsights.Web" version="2.3.0" targetFramework="net462" /> 
<package id="Microsoft.ApplicationInsights.WindowsServer" version="2.3.0" targetFramework="net462" /> 
<package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.3.0" targetFramework="net462" /> 

的ApplicationInsights.config外观如下所示:

<?xml version="1.0" encoding="utf-8"?> 
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings"> 
<!-- This key is for Application Insights resource 'PlanningTool.Web' in resource group 'Default-ApplicationInsights-CentralUS' --> 
<InstrumentationKey>Our key</InstrumentationKey> 
<TelemetryModules> 
    <Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector" /> 
    <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector"> 
    <!-- 
    Use the following syntax here to collect additional performance counters: 

    <Counters> 
     <Add PerformanceCounter="\Process(??APP_WIN32_PROC??)\Handle Count" ReportAs="Process handle count" /> 
     ... 
    </Counters> 

    PerformanceCounter must be either \CategoryName(InstanceName)\CounterName or \CategoryName\CounterName 

    NOTE: performance counters configuration will be lost upon NuGet upgrade. 

    The following placeholders are supported as InstanceName: 
     ??APP_WIN32_PROC?? - instance name of the application process for Win32 counters. 
     ??APP_W3SVC_PROC?? - instance name of the application IIS worker process for IIS/ASP.NET counters. 
     ??APP_CLR_PROC?? - instance name of the application CLR process for .NET counters. 
    --> 
    </Add> 
    <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector" /> 
    <Add Type="Microsoft.ApplicationInsights.WindowsServer.DeveloperModeWithDebuggerAttachedTelemetryModule, Microsoft.AI.WindowsServer" /> 
    <Add Type="Microsoft.ApplicationInsights.WindowsServer.UnhandledExceptionTelemetryModule, Microsoft.AI.WindowsServer" /> 
    <Add Type="Microsoft.ApplicationInsights.WindowsServer.UnobservedExceptionTelemetryModule, Microsoft.AI.WindowsServer" /> 
    <Add Type="Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule, Microsoft.AI.Web"> 
    <Handlers> 
     <!-- 
     Add entries here to filter out additional handlers: 

     NOTE: handler configuration will be lost upon NuGet upgrade. 
     --> 
     <Add>System.Web.Handlers.TransferRequestHandler</Add> 
     <Add>Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.RequestDataHttpHandler</Add> 
     <Add>System.Web.StaticFileHandler</Add> 
     <Add>System.Web.Handlers.AssemblyResourceLoader</Add> 
     <Add>System.Web.Optimization.BundleHandler</Add> 
     <Add>System.Web.Script.Services.ScriptHandlerFactory</Add> 
     <Add>System.Web.Handlers.TraceHandler</Add> 
     <Add>System.Web.Services.Discovery.DiscoveryRequestHandler</Add> 
     <Add>System.Web.HttpDebugHandler</Add> 
    </Handlers> 
    </Add> 
    <Add Type="Microsoft.ApplicationInsights.Web.ExceptionTrackingTelemetryModule, Microsoft.AI.Web" /> 
</TelemetryModules> 
<TelemetryProcessors> 
    <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryProcessor, Microsoft.AI.PerfCounterCollector" /> 
    <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector"/> 
    <Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel"> 
    <MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond> 
    </Add> 
</TelemetryProcessors> 
<TelemetryChannel Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.ServerTelemetryChannel, Microsoft.AI.ServerTelemetryChannel" /> 
<!-- 
    Learn more about Application Insights configuration with ApplicationInsights.config here: 
    http://go.microsoft.com/fwlink/?LinkID=513840 

    Note: If not present, please add <InstrumentationKey>Your Key</InstrumentationKey> to the top of this file. 
--> 
<TelemetryInitializers> 
    <Add Type="Microsoft.ApplicationInsights.WindowsServer.AzureRoleEnvironmentTelemetryInitializer, Microsoft.AI.WindowsServer" /> 
    <Add Type="Microsoft.ApplicationInsights.WindowsServer.DomainNameRoleInstanceTelemetryInitializer, Microsoft.AI.WindowsServer" /> 
    <Add Type="Microsoft.ApplicationInsights.WindowsServer.BuildInfoConfigComponentVersionTelemetryInitializer, Microsoft.AI.WindowsServer" /> 
    <Add Type="Microsoft.ApplicationInsights.Web.WebTestTelemetryInitializer, Microsoft.AI.Web" /> 
    <Add Type="Microsoft.ApplicationInsights.Web.SyntheticUserAgentTelemetryInitializer, Microsoft.AI.Web"> 
    <Filters>search|spider|crawl|Bot|Monitor|BrowserMob|BingPreview|PagePeeker|WebThumb|URL2PNG|ZooShot|GomezA|Google SketchUp|Read Later|KTXN|KHTE|Keynote|Pingdom|AlwaysOn|zao|borg|oegp|silk|Xenu|zeal|NING|htdig|lycos|slurp|teoma|voila|yahoo|Sogou|CiBra|Nutch|Java|JNLP|Daumoa|Genieo|ichiro|larbin|pompos|Scrapy|snappy|speedy|vortex|favicon|indexer|Riddler|scooter|scraper|scrubby|WhatWeb|WinHTTP|voyager|archiver|Icarus6j|mogimogi|Netvibes|altavista|charlotte|findlinks|Retreiver|TLSProber|WordPress|wsr-agent|http client|Python-urllib|AppEngine-Google|semanticdiscovery|facebookexternalhit|web/snippet|Google-HTTP-Java-Client</Filters> 
    </Add> 
    <Add Type="Microsoft.ApplicationInsights.Web.ClientIpHeaderTelemetryInitializer, Microsoft.AI.Web" /> 
    <Add Type="Microsoft.ApplicationInsights.Web.OperationNameTelemetryInitializer, Microsoft.AI.Web" /> 
    <Add Type="Microsoft.ApplicationInsights.Web.OperationCorrelationTelemetryInitializer, Microsoft.AI.Web" /> 
    <Add Type="Microsoft.ApplicationInsights.Web.UserTelemetryInitializer, Microsoft.AI.Web" /> 
    <Add Type="Microsoft.ApplicationInsights.Web.AuthenticatedUserIdTelemetryInitializer, Microsoft.AI.Web" /> 
    <Add Type="Microsoft.ApplicationInsights.Web.AccountIdTelemetryInitializer, Microsoft.AI.Web" /> 
    <Add Type="Microsoft.ApplicationInsights.Web.SessionTelemetryInitializer, Microsoft.AI.Web" /> 
</TelemetryInitializers> 
</ApplicationInsights> 

但是Application Insights确实没有显示实时指标或服务器请求。

我试过通过测试程序访问App Insights,这些程序正在运行,所有数据(实时指标,请求等)都正确显示: using Microsoft.ApplicationInsights;使用系统的 ;

namespace AppInsightsTest 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      Console.WriteLine("Application Insights Test"); 
      var e = new Exception("This is a App Insights test"); 
      var ai = new TelemetryClient(); 
      ai.TrackException(e); 
      Console.WriteLine("Finished..."); 
      Console.ReadKey(); 
     } 
    } 
} 

如何在MVC/Web Api项目中配置App Insights以使其正常工作。

在此先感谢。

更新与截图形成的Visual Studio(2017年)和Azure的门户网站: VS: enter image description here

Azure的门户网站(德文): enter image description here

+0

是实况量度只是不工作的事情吗?你看到常规遥测(请求,依赖,事件,例外)吗? 我在配置中看到的一件奇怪的事情是QuickPul​​seTelemetryModule被提及两次,一旦正确,并且一次位于标记内。尝试删除第二次出现,看看它是否改变了行为。 – tokaplan

+0

@tokaplan:感谢QuickPul​​seTelemetryModule的提示。我已将其删除。而在Application Insights中,我根本没有看到任何东西,也没有请求等。我现在已经建立了一个基于Visual Studio MVC模板的最小示例。我已经通过NuGet安装了所有的应用程序见解包,但是这个项目也不会发送任何遥测数据。 – Fabian

回答

0

我添加应用程序洞察到我现有的MVC项目与以下步骤可以获得实时指标流和服务器请求指标,请参阅它。

  • 右键单击在Solution Explorer Web应用程序项目,并选择Add> 应用洞察遥测...,然后注册 应用洞察应用程序和配置应用见解。 (这将有助于我们安装应用程序洞察相关的包和配置项目。)

  • 打开网页生成一些遥测

  • 在Azure门户网站,我可以看到在线的服务器和动态度量流的数量。

    enter image description here

  • 添加图表显示服务器请求

    enter image description here

    enter image description here

此外,您还可以参考this article显示如何配置ASP.NET web应用程序将遥测发送到Azure应用程序见解ervice。

+0

在Visual Studio中,我可以看到请求等(请参阅我的问题的更新)。但是在天蓝色的门户里,什么都没有。我看不到任何在线服务器。我在哪里可以更改图表详细信息?当我使用我的测试控制台应用程序时,我能够看到实时指标以及其他任何内容。 – Fabian

+0

在* Metrics Explorer *刀片下,您会在网页顶部找到[添加图表]按钮。 –

+0

我已经更改了图表设置,但根本没有记录请求。我也重做了我们链接中描述的设置。 – Fabian

0

您的Azure应用程序洞察资源未链接到您的Web应用程序。

在Azure门户中找到您的Application Insights资源并导航到Configure-> Properties。

在那里您会看到“INSTRUMENTATION KEY”。

复制该关键看你applicationInsights.config部分:

<InstrumentationKey>Our key</InstrumentationKey> 
+0

我已经在这里删除了我们真实的密钥。本地我输入了正确的密钥。 – Fabian

+0

好的。在您的Azure门户中,在您的Web应用程序属性中,您能看到Application Insights选项吗?你有没有配置它来使用你的应用程序见解资源? –