我想知道是否有一种方法可以监视独立的.NET桌面应用程序的性能?(例如,foobar.exe)
这是一个客户端应用程序,最终可能与web服务或数据库交互,因此,如果涉及到数据库连接,理想情况下我想要;
任何帮助都是非常感谢的。
谢谢,
发布于 2014-05-15 14:06:43
我为新文物公司工作。
只要非IIS应用程序满足以下要求,就可以监视它们的性能:
您可以在我们的文档站点上阅读更多关于这些需求的信息: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应用程序和异步调用的情况下,可以使用以下特性来创建通常代理不会这样做的事务。这是通过自定义工具文件进行的手动处理。
沿侧CustomInstrumentation.xml在C:\ProgramData\New Relic.NET代理\扩展名中创建一个名为“例如CoreInstrumentation.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和MethodName:
当来自程序集AssemblyName的类型为AssemblyName的对象调用方法MethodName时,事务就开始了。当方法返回或抛出异常时,事务结束。事务将命名为名称,并将分组为由类别指定的事务类型。在New中,您可以在查看“监视”>“事务”页面时从“类型”下拉菜单中选择事务类型。
请注意,“类别”和“名称”都必须存在,并且必须用斜杠分隔。
如您所料,在方法调用期间发生的仪器化活动(方法、数据库、外部活动)将显示在事务的细分表和事务跟踪中。
下面是一个更具体的例子。首先,检测文件:
<?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>https://stackoverflow.com/questions/23676371
复制相似问题