New Relic For .Net¶
New Relic の .Net Agent は .Net テクノロジーフレームワークをベースにしたオープンソースプロジェクトで、.NET テクノロジーフレームワークの App を包括的に可観測化できます。C#、VB.NET、CLI など、.NET テクノロジーフレームワークに対応するすべての言語にも使用できます。
前提条件¶
- ドメインの準備と証明書の生成およびインストール
- New Relic アカウントを登録
- New Relic Agent をインストールします。現在の対応バージョンは 6.27.0 です
- .Net Framework をインストールします。現在の対応バージョンは 3.0 です
New Relic .NET Agent のインストールと設定¶
まず、現在 Windows OS にインストールされている DotNet Framework のバージョンを確認します。
cmd を実行し、reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP" を入力して、現在 OS にインストールされているすべてのバージョンを確認します。
その後、New Relic Agent をインストールします。
- 個人の
New Relicアカウントにログインしてインストールすることもできます:
アカウントに入ったら、左側のメニュー下にあるデータ追加 + Add Data サブメニューをクリックし、右側の Data source サブメニュー内の Application monitoring から .Net を選び、インストールガイドに従ってインストールします。
- インストーラーを使ってインストールすることもできます:
ダウンロードディレクトリ を開いて dotnet agent バージョン 6.27.0 をダウンロードし、対応するインストーラーを選択します。
New Relic Agent の設定
- 必要な環境変数を設定する
デスクトップ左下の Windows ロゴを右クリックして システム を選択し、詳細システム設定 を選択、環境変数 を選択して、システム変数 リストに以下の環境変数設定が含まれているか確認します。
- `COR_ENABLE_PROFILING`: 数値 1、デフォルトで有効
- `COR_PROFILER`: 文字列値。既定ではシステムが自動入力する `ID`
- `CORECLR_ENABLE_PROFILING`: 数値 1、デフォルトで有効
- `NEW_RELIC_APP_NAME`: 文字列値。監視対象の `APP` 名を入力(任意)
- `NEWRELIC_INSTALL_PATH`: `New Relic Agent` のインストールパス
- 設定ファイルで
New Relicを設定する
New Relic Agent のインストールディレクトリ下の newrelic.config を開き、以下の例の {サンプル値} を実際の値に置き換え、その他の値は例に従って入力します。
<?xml version="1.0"?>
<!-- Copyright (c) 2008-2017 New Relic, Inc. All rights reserved. -->
<!-- For more information see: https://newrelic.com/docs/dotnet/dotnet-agent-configuration -->
<configuration xmlns="urn:newrelic-config" agentEnabled="true" agentRunID="{agent id (任意で指定可、未入力可)}">
<service licenseKey="{実際の license key}" ssl="true" host="{www.your-domain-name.com}" port="{Datakit のポート番号}" />
<application>
<name>{監視対象の APP 名}</name>
</application>
<log level="debug" />
<transactionTracer enabled="true" transactionThreshold="apdex_f" stackTraceThreshold="500" recordSql="obfuscated" explainEnabled="false" explainThreshold="500" />
<crossApplicationTracer enabled="true" />
<errorCollector enabled="true">
<ignoreErrors>
<exception>System.IO.FileNotFoundException</exception>
<exception>System.Threading.ThreadAbortException</exception>
</ignoreErrors>
<ignoreStatusCodes>
<code>401</code>
<code>404</code>
</ignoreStatusCodes>
</errorCollector>
<browserMonitoring autoInstrument="true" />
<threadProfiling>
<ignoreMethod>System.Threading.WaitHandle:InternalWaitOne</ignoreMethod>
<ignoreMethod>System.Threading.WaitHandle:WaitAny</ignoreMethod>
</threadProfiling>
</configuration>
起こりうる問題:
New Relic license keyはどこにあるか
公式サイトの案内に従って New Relic をインストールした場合、license key は自動で入力されます。手動でインストールする場合は、インストーラーの実行中に license key の入力を求められます。license key はアカウント作成またはデータ作成の際に表示されるため、保存しておくことをおすすめします。
- TLS バージョンの不整合
New Relic Agent のデプロイ中にデータが送信されず、New Relic のログに以下のような ERROR 情報が表示される場合があります。
NewRelic ERROR: Unable to connect to the New Relic service at collector.newrelic.com:443 : System.Net.WebException:
The request was aborted: Could not create SSL/TLS secure channel.
NewRelic ERROR: Unable to connect to the New Relic service at collector.newrelic.com:443 : System.Net.WebException:
The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException:
Received an unexpected EOF or 0 bytes from the transport stream.
NewRelic ERROR: Unable to connect to the New Relic service at collector.newrelic.com:443 : System.Net.WebException:
The underlying connection was closed: An unexpected error occurred on a receive. ---> System.ComponentModel.Win32Exception:
The client and server cannot communicate, because they do not possess a common algorithm.
問題の切り分けには、TLS 1.0 を無効にした後にデータが表示されない を参照してください。
ホストの設定¶
New Relic Agent はデータ転送のために HTTPS を設定する必要があるため、ホスト設定の前にまず証明書の申請を完了します。New Relic Agent の起動時には証明書の正当性検証も必要になるため、ここでは CA の自己署名と、自己署名 CA による証明書発行を完了しておく必要があります。証明書チェーンの発行が完了したら、Guance を使って NewRelic .NET プローブを導入する と Windows サーバーにルート証明書と中間証明書をインポートするには? を参考に証明書を配置します。
証明書の配置が完了したら、hosts ファイルを適切に設定してローカルでドメイン解決できるようにします。hosts の設定は次のとおりです。
ここで www.your-domain-name.com は newrelic.config 設定ファイルの service.host 項で指定したドメインです。
Datakit の設定¶
DataKit のインストールディレクトリ下の conf.d/ ディレクトリに移動し、.conf.sample をコピーして .conf に名前を変更します。例は次のとおりです。
設定後、Datakit と IIS を再起動します。