3

カスタム インストルメンテーションを追加する必要があることがわかっている New Relic を使用したバックグラウンド プロセスである .NET アプリ内のメソッドを監視しようとしています。

.NET Agent を再インストールし、「Instrument all .NET Applications」を設定し、app.config ファイルと newrelic.config ファイル内で変更を行った後、新しい Relic ダッシュボードでバックグラウンド プロセスの基本データを取得しています。

ここで、カスタム インストルメンテーションを追加するために、extensions ディレクトリ内に別のインストルメンテーション構成ファイルを追加しました。アプリを再起動しましたが、監視しようとしている新しい/カスタム メソッドが表示されません。

これは私の計測ファイル MyInstrumentation.xml です

<?xml version="1.0" encoding="utf-8"?>

<!-- instrument EngineService.BestAgentSolver.Solve inside EngineService.BestAgentSolver -->
<tracerFactory metricName="Cast-a-Net.EngineService.BestAgentSolver.Solve-Metric">
  <match assemblyName="Cast-a-Net.EngineService" className="Cast-a-Net.EngineService.BestAgentSolver">
    <exactMethodMatcher methodName="Solve" />
  </match>
</tracerFactory>

<!-- instrument EngineService.SessonManager.BroadcastLeadCounts inside EngineService.SessionManager -->
<tracerFactory metricName="Cast-a-Net.EngineService.SessionManager.BroadcastLeadCounts-Metric">
  <match assemblyName="Cast-a-Net.EngineService" className="Cast-a-Net.EngineService.SessionManager">
    <exactMethodMatcher methodName="BroadcastLeadCounts" />
  </match>
</tracerFactory>

<tracerFactory metricName="myapp.Web.Controllers.CallListController.ActionResult-Metric">
  <match assemblyName="myapp.Web" className="myapp.Web.Controllers.CallListController">
    <exactMethodMatcher methodName="ActionResult" />
  </match>
</tracerFactory>

手順が間違っているか、何か間違っていますか?

4

1 に答える 1

4

.NET エージェントのカスタム インストルメンテーションは、HttpContext オブジェクトを使用する Web トランザクションで動作します。一方、.NET エージェント API を使用すると、カスタム ダッシュボードに表示できるメトリックを収集できます。特に、RecordMetric、RecordResponseTimeMetric、および IncrementCounter は、Web 以外のアプリケーションで機能するため便利です。

ただし、.NET エージェントのバージョン 2.24.218.0 以降では、新しい機能を使用して、通常はエージェントが作成しないトランザクションを作成できます。これは、カスタム インストルメンテーション ファイルによる手動プロセスです。

C:\ProgramData\New Relic.NET Agent\Extensions に、CoreInstrumentation.xml と並んで 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>

上記の属性値 Category/Name、AssemblyName、NameSpace.ClassName、および MethodName を変更する必要があります。

アセンブリ AssemblyName の NameSpace.ClassName 型のオブジェクトがメソッド MethodName を呼び出すと、トランザクションが開始されます。メソッドが例外を返すかスローすると、トランザクションは終了します。トランザクションは Name という名前になり、Category で指定されたトランザクション タイプにグループ化されます。New Relic UI では、Monitoring > Transactions ページを表示しているときに、Type ドロップダウン メニューからトランザクション タイプを選択できます。

カテゴリと名前の両方が存在し、スラッシュで区切られている必要があることに注意してください。

ご想像のとおり、メソッドの呼び出し中に発生するインストルメント化されたアクティビティ (メソッド、データベース、外部) は、トランザクションのブレークダウン テーブルとトランザクション トレースに表示されます。

より具体的な例を次に示します。まず、インストルメンテーション ファイル:

<?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>

アプリケーションを数回実行すると、[その他のトランザクション] の [バックグラウンド] カテゴリにカスタム トランザクションが表示されます。トランザクション内訳テーブルとトランザクション追跡にダミー セグメントが表示されます。

于 2014-04-15T10:58:39.773 に答える