ログストリーミング: New Relic Logs
最終更新日 2021-11-01
New Relic Logs のリアルタイムログストリーミング機能によって、Scalyr にログファイルを送信することができます。
Fastly ではサードパーティのサービスに関する直接のサポートは行っておりません。詳細については、Fastly サービスの利用規約をご参照ください。
前提条件
Fastly サービスのログエンドポイントとして New Relic Logs を追加する前に、以下が必要です。
- New Relic アカウント を登録します。
- ライセンスキーを取得するか、任意で Insert API キーを作成します。
ログエンドポイントとして New Relic Logs を追加する
以下の手順で New Relic Logs をログエンドポイントとして追加します。
- リモートログストリーミングの設定に関するガイドの情報をご参照ください。
- New Relic Logs の Create endpoint ボタンをクリックします。Create a New Relic Logs endpoint ページが表示されます。
- 以下の要領で Create a New Relic Logs endpoint ページの各フィールドに入力します。
- Name フィールドに分かりやすいエンドポイントの名前を入力します。
- Placement セクションでは、生成される VCL にログコールが配置される場所を選択します。有効な値は Format Version Default、waf_debug (waf_debug_log)、None です。詳細については、ログ配置の変更に関するガイドをご参照ください。
- Log format フィールドに、ログの形式に使用する Apache 形式の文字列や VCL 変数を任意で入力します。詳細については、フォーマットの例をご参照ください。
- License key / Insert key フィールドに、New Relic のライセンスキーまたは Insert API キーを入力します。
- Region コントロールから、ログを配信するリージョンを選択します。
- Create ボタンをクリックすると、新しいログエンドポイントが作成されます。
- Activate ボタンをクリックして設定変更をデプロイします。
Elasticsearch の形式例
New Relic Logs に送られるデータは、JSON オブジェクトとして直列化する必要があります。以下は New Relic Logs にデータを送信するための文字列の形式例です。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"timestamp": "%{strftime(\{"%Y-%m-%dT%H:%M:%S%z"\}, time.start)}V",
"client_ip": "%{req.http.Fastly-Client-IP}V",
"geo_country": "%{client.geo.country_name}V",
"geo_city": "%{client.geo.city}V",
"host": "%{if(req.http.Fastly-Orig-Host, req.http.Fastly-Orig-Host, req.http.Host)}V",
"url": "%{json.escape(req.url)}V",
"request_method": "%{json.escape(req.method)}V",
"request_protocol": "%{json.escape(req.proto)}V",
"request_referer": "%{json.escape(req.http.referer)}V",
"request_user_agent": "%{json.escape(req.http.User-Agent)}V",
"response_state": "%{json.escape(fastly_info.state)}V",
"response_status": %{resp.status}V,
"response_reason": %{if(resp.response, "%22"+json.escape(resp.response)+"%22", "null")}V,
"response_body_size": %{resp.body_bytes_written}V,
"fastly_server": "%{json.escape(server.identity)}V",
"fastly_is_edge": %{if(fastly.ff.visits_this_service == 0, "true", "false")}V
}
タイムスタンプをログに記録する
Fastly のログにタイムスタンプフィールドがある場合、エポックからのミリ秒または秒数として指定し、New Relic のタイムスタンプをオーバーライドする必要があります。含まれていない場合は、Fastly によってタイムスタンプが生成されます。
New Relic Instant Observability の事前構築 Fastly ダッシュボードの使用
New Relic I/O は、何百ものツールとテクノロジー向けにコミュニティが貢献したクイックスタートのオープンソースエコシステムです。New Relic と協力して、重要と考えられる特定の重要な指標をハイライトする事前作成済みダッシュボードを開発しました。ダッシュボードの設定が簡単で、カスタマイズしたい場合にはコードはオープンソースです。
推奨される拡張ログ形式を使用するようにサービスを設定する
事前作成済みダッシュボードが特定のフィールドを表示する必要があるため、ロギング形式を使用することをお勧めします。ただし、自分自身の目的でフィールドを追加したり、作成した既存のダッシュボードとの後方互換性を維持するのを止める必要はありません。一部のフィールドを送信しなかった場合、ダッシュボードは壊れないものの、特定のチャートにはデータが含まれません。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{
"timestamp": %{time.start.msec}V,
"logtype": "accesslogs",
"cache_status":"%{regsub(fastly_info.state, "^(HIT-(SYNTH)|(HITPASS|HIT|MISS|PASS|ERROR|PIPE)).*", "\\2\\3") }V",
"client_ip":"%h",
"client_device_type":"%{client.platform.hwtype}V",
"client_os_name":"%{client.os.name}V",
"client_os_version":"%{client.os.version}V",
"client_browser_name":"%{client.browser.name}V",
"client_browser_version":"%{client.browser.version}V",
"client_as_name":"%{client.as.name}V",
"client_as_number":"%{client.as.number}V",
"client_connection_speed": "%{client.geo.conn_speed}V",
"client_port": %{client.port}V,
"client_rate_bps":%{client.socket.tcpi_delivery_rate}V,
"client_recv_bytes":%{client.socket.tcpi_bytes_received}V,
"client_requests_count":%{client.requests}V,
"client_resp_body_size_write": %{resp.body_bytes_written}V,
"client_resp_header_size_write": %{resp.header_bytes_written}V,
"client_resp_ttfb": %{time.to_first_byte}V,
"client_rtt_us":%{client.socket.tcpi_rtt}V,
"content_type":"%{Content-Type}o",
"domain": "%{Fastly-Orig-Host}i",
"fastly_datacenter": "%{server.datacenter}V",
"fastly_host": "%{server.hostname}V",
"fastly_region": "%{server.region}V",
"host": "%v",
"origin_host":"%v",
"origin_name":"%{req.backend.name}V",
"request":"%{req.request}V",
"request_method":"%m",
"request_accept_charset":"%{json.escape(req.http.Accept-Charset)}V",
"request_accept_language":"%{json.escape(req.http.Accept-Language)}V",
"request_referer":"%{json.escape(req.http.Referer)}V",
"request_user_agent":"%{json.escape(req.http.User-Agent)}V",
"resp_status":"%s",
"response": "%{resp.response}V",
"service_id":"%{req.service_id}V",
"service_version": "%{req.vcl.version}V",
"status":"%s",
"time_start":"%{begin:%Y-%m-%dT%H:%M:%SZ}t",
"time_end":"%{end:%Y-%m-%dT%H:%M:%SZ}t",
"time_elapsed":%D,
"timestamp": %{time.start.msec}V,
"tls_cipher":"%{json.escape(tls.client.cipher)}V",
"tls_version":"%{json.escape(tls.client.protocol)}V",
"url":"%{json.escape(req.url)}V",
"user_agent":"%{json.escape(req.http.User-Agent)}V",
"user_city":"%{client.geo.city.utf8}V",
"user_country_code":"%{client.geo.country_code}V",
"user_continent_code":"%{client.geo.continent_code}V",
"user_region":"%{client.geo.region}V"
}
Fastly ダッシュボードをインストールする
Fastly ダッシュボードクイックスタートをインストールする手順に従ってください。
-
New Relic マーケットプレイスから Fastly ダッシュボードクイックスタートを選択します。
または、Fastly ダッシュボードページに直接移動します。
-
Install quickstart ボタンをクリックします。
-
Begin installation ボタンをクリックします。
-
Done ボタンまたは Skip this step リンクをクリックします。
-
See your data ボタンをクリックします。
Fastly ダッシュボードが表示されます。