我想知道是否有方法可以监视独立.NET桌面应用程序的性能? (例如,foobar.exe
)使用New Relic的独立.NET桌面应用程序的性能监视
这是一个客户端应用程序,最终可能会与Web服务或数据库交互,所以在数据库连接的情况下,理想情况下,我想;
- 监视器应用程序的性能(例如,花或被叫的方法数等时间)
- 监视器SQL查询/程序被执行
任何帮助不胜感激。
谢谢,
我想知道是否有方法可以监视独立.NET桌面应用程序的性能? (例如,foobar.exe
)使用New Relic的独立.NET桌面应用程序的性能监视
这是一个客户端应用程序,最终可能会与Web服务或数据库交互,所以在数据库连接的情况下,理想情况下,我想;
任何帮助不胜感激。
谢谢,
我为New Relic工作。
这是可能的,只要符合这些要求监测的是非IIS应用程序的性能:
仪器上的所有.NET应用程序功能必须有
App.config中和/或newrelic.config将需要配置该.exe
您可以在此处详细了解我们的文档站点以下要求: https://docs.newrelic.com/docs/dotnet/instrumenting-custom-applications
您可能需要通过使用我们的.NET代理API来收集自定义指标。 RecordMetric,RecordResponseTimeMetric和IncrementCounter方法专门用于非Web应用程序。 我们的.NET代理API文档位于:https://docs.newrelic.com/docs/dotnet/net-agent-api
您还可以设置自定义事务来跟踪非Web事务。我们通常可以跟踪使用HttpObjects的函数,但以下是代理版本2.24.218.0中实现的新功能。 对于没有事务上下文的非Web应用程序和异步调用的情况,可以使用以下功能来创建代理通常不会执行的事务。这是通过自定义检测文件的手动过程。
在CoreInstrumentation.xml的C:\ ProgramData \ New Relic.NET Agent \ Extensions中创建名为CustomInstrumentation.xml的自定义检测文件。下面的内容添加到您的自定义的仪器文件:
<?xml version="1.0" encoding="utf-8"?>
<extension xmlns="urn:newrelic-extension">
<instrumentation>
<tracerFactory name="NewRelic.Agent.Core.Tracer.Factories.BackgroundThreadTracerFactory" metricName="Category/Name">
<match assemblyName="AssemblyName" className="NameSpace.ClassName">
<exactMethodMatcher methodName="MethodName" />
</match>
</tracerFactory>
</instrumentation>
</extension>
您必须更改属性值类别/名称,的AssemblyName,NameSpace.ClassName和方法名以上:
交易开始时类型命名空间的对象程序集AssemblyName中的.ClassName调用方法MethodName。事务在方法返回或抛出异常时结束。该交易将被命名为Name并将被分组到由Category指定的交易类型中。在New Relic UI中,您可以在查看监控>交易页面时从类型下拉菜单中选择交易类型。
请注意,类别和名称必须存在,并且必须用斜杠分隔。
正如您所期望的那样,在方法调用期间发生的插装活动(方法,数据库,外部)将显示在事务的分解表和事务跟踪中。
下面是一个更具体的例子。首先,仪表文件:
<?xml version="1.0" encoding="utf-8"?>
<extension xmlns="urn:newrelic-extension">
<instrumentation>
<tracerFactory name="NewRelic.Agent.Core.Tracer.Factories.BackgroundThreadTracerFactory" metricName="Background/Bars">
<match assemblyName="Foo" className="Foo.Bar">
<exactMethodMatcher methodName="Bar1" />
<exactMethodMatcher methodName="Bar2" />
</match>
</tracerFactory>
<tracerFactory metricName="Custom/some custom metric name">
<match assemblyName="Foo" className="Foo.Bar">
<exactMethodMatcher methodName="Bar3" />
</match>
</tracerFactory>
</instrumentation>
</extension>
现在一些代码:
var foo = new Foo();
foo.Bar1(); // Creates a transaction named Bars in category Background
foo.Bar2(); // Same here.
foo.Bar3(); // Won't create a new transaction. See notes below.
public class Foo
{
// this will result in a transaction with an External Service request segment in the transaction trace
public void Bar1()
{
new WebClient().DownloadString("http://www.google.com/);
}
// this will result in a transaction that has one segment with a category of "Custom" and a name of "some custom metric name"
public void Bar2()
{
// the segment for Bar3 will contain your SQL query inside of it and possibly an execution plan
Bar3();
}
// if Bar3 is called directly, it won't get a transaction made for it.
// However, if it is called inside of Bar1 or Bar2 then it will show up as a segment containing the SQL query
private void Bar3()
{
using (var connection = new SqlConnection(ConnectionStrings["MsSqlConnection"].ConnectionString))
{
connection.Open();
using (var command = new SqlCommand("SELECT * FROM table", connection))
using (var reader = command.ExecuteReader())
{
reader.Read();
}
}
}
}
下面是一个简单的控制台应用程序,演示了自定义的交易:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Custom Transactions");
var t = new CustomTransaction();
for (int i = 0; i < 100; ++i)
t.StartTransaction();
}
}
class CustomTransaction
{
public void StartTransaction()
{
Console.WriteLine("StartTransaction");
Dummy();
}
void Dummy()
{
System.Threading.Thread.Sleep(5000);
}
}
}
使用下列自定义的仪器文件:
<?xml version="1.0" encoding="utf-8"?>
<extension xmlns="urn:newrelic-extension">
<instrumentation>
<tracerFactory name="NewRelic.Agent.Core.Tracer.Factories.BackgroundThreadTracerFactory" metricName="Background/CustomTransaction">
<match assemblyName="ConsoleApplication1" className="ConsoleApplication1.CustomTransaction">
<exactMethodMatcher methodName="StartTransaction" />
</match>
</tracerFactory>
<tracerFactory metricName="Custom/Dummy">
<match assemblyName="ConsoleApplication1" className="ConsoleApplication1.CustomTransaction">
<exactMethodMatcher methodName="Dummy" />
</match>
</tracerFactory>
</instrumentation>
</extension>
谢谢为详细的答案。这几乎总结了我整天在文档中阅读的内容。在这一点上,我的理解是,无法使用某种全局模式方法来监视所有代码。 (即'*')在任何给定类中调用的任何方法都将被监视,而不会对应用程序域做出如此特定的说明。你可否确认? – Ali
嗨,你说的没有办法用*来跟踪所有的东西,因为它太耗费资源。 – karlpcrowley
我会继续并肯定接受你的答案。你能否也请告诉我是否有某种.NET SDK的计划,以便我们可以在我们的项目中包含_automagically_?谢谢。 – Ali