1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

New Relic初心者 logs parsingについて

Last updated at Posted at 2020-09-12

0.はじめに

newrelic infrastructure agentを利用し、ログをnewrelicへ転送することが可能。
あらゆるログデータをnewrelicへ転送することで、インフラ系のデータもアプリケーション系のデータも可視化することができる。
今回はapacheのアクセスログをnewrelicへ転送し、log parsingの機能を利用して必要なデータを切り出す。

1.infrastructure agentをインストール

infrastucture agent が version 1.11.14以上であることを確認する

rpm -qa | grep newrelic
newrelic-infra-1.12.3-1.el8.x86_64

2.ログ転送

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

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

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

configuration fileを作成

configuration fileを作成し、上記ディレクトリ配下に配置。
ログ識別ができるよう、カスタム属性を付加しておく。

logs:
- name: "apache"
  file: /var/log/httpd/access_log
  attributes:
    log_type: apache

ログ更新

以下、クーロンにより定期的にapacheへアクセスしアクセスログを更新

# access apache
*/2 * * * * devops curl "http://192.168.11.18:80"

ダッシュボード確認

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

3.logs parsing

parsingルールの作成

Create parsing ruleボタンを押す
img2.bmp

Manage parsing rules

parsing を実施するログの絞り込みを実施。
今回は転送したapacheのアクセスに、カスタム属性log_type:apacheを付与しているため、この値を利用。
img3.bmp

Parsing logic

parsing logicはgrok patternで表現される。
例えば、apacheは以下の通り

Log formats
SYSLOGBASE %{SYSLOGTIMESTAMP:timestamp} (?:%{SYSLOGFACILITY} )?%{SYSLOGHOST:logsource} %{SYSLOGPROG}:
COMMONAPACHELOG %{IPORHOST:clientip} %{USER:ident} %{USER:auth} [%{HTTPDATE:timestamp}] "(?:%{WORD:verb} %{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})" %{NUMBER:response} (?:%{NUMBER:bytes}|-)
COMBINEDAPACHELOG %{COMMONAPACHELOG} %{QS:referrer} %{QS:agent}

今回はCOMMONAPACHELOGを適用
img4.bmp

結果

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

4.まとめ

今回は、apacheのアクセスログを利用したnewrelic logsのparsing機能を実装した。
grok patternの検証をすべく、他フォーマットのログに対しても適用を試みる。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?