LoginSignup
1
1

More than 3 years have passed since last update.

New Relic初心者 logs parsingについて②

Posted at

0.はじめに

newrelic infrastructure agentを利用し、各種ログをnewrelicへ転送。logs parsing機能を利用して情報の切り出しが可能。
前回はapacheのアクセスログをnewrelicへ転送しparsing ruleを適用したが、今回は任意の形式のログに対してparsing ruleを適用する。

1.ログ転送

定義ファイル格納用ディレクトリ

ログ転送の定義ファイルが格納されているディレクトリへ移動

cd  /etc/newrelic-infra/logging.d/

configuration fileを作成

ログ識別ができるよう、カスタム属性を付加しておく。

logs:
- name: "random"
  file: /home/devops/random
  attributes:
    log_type: random

ログ更新

以下、クーロンにより定期的にrandomファイルを更新

#write date and randomnum
*/2 * * * * devops echo `date '+\%Y \%m \%d'` $RANDOM >> /home/devops/random

ダッシュボード確認

少し待つとダッシュボードにアクセスログが更新される。
img1

3.log parsing

Manage parsing rules

parsing を実施するログの絞り込みを実施。
今回は転送したファイルに、log_type:randomを付与しているため、この値を利用。

Parsing logic

ログの形式に則り、parsing logicをgrok patternで表現。
img2

結果

結果は以下の通り。message領域のアクセスログに対してparsing logicが適用されている。
img3.bmp

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1