1
2

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 5 years have passed since last update.

HerokuのログをSplunkに食わせてみる

Last updated at Posted at 2017-10-23

はじめに

HerokuのLog Drainsを使ってSplunkにログ取り込んでみた

設定してみる

ということで、早速設定してみた

Splunkでログ受け取りの準備

インデックス作成(≒ Herokuのログを保存するディレクトリ)

Splunk GUIからherokuインデックスを作成
※ GUIのスクリーンキャプチャは省略、代わりにGUI経由で作成される設定ファイル(*.conf)貼っときますね

indexes.conf
[heroku]
coldPath = $SPLUNK_DB/heroku/colddb
enableDataIntegrityControl = 0
enableTsidxReduction = 0
homePath = $SPLUNK_DB/heroku/db
maxTotalDataSizeMB = 512000
thawedPath = $SPLUNK_DB/heroku/thaweddb

ソースタイプ作成

既定のソースタイプ syslog からクローンして heroku:syslog を作成
これもGUIから作成

props.conf
[heroku:syslog]
DATETIME_CONFIG = 
MAX_TIMESTAMP_LOOKAHEAD = 42
NO_BINARY_CHECK = true
REPORT-syslog = syslog-extractions
SHOULD_LINEMERGE = false
TIME_FORMAT = %Y-%m-%dT%H:%M:%S.%6N
TRANSFORMS = syslog-host
TZ = UTC
category = Application
description = Syslog Drain by Heroku
disabled = false
maxDist = 3
pulldown_type = 1

更新した箇所は MAX_TIMESTAMP_LOOKAHEAD TIME_FORMAT くらいかな
description とか category は適当でおk

データインプット作成

TCP 10514ポートでデータを受け取る
これもGUIからs (ry

inputs.conf
[tcp://10514]
connection_host = dns
index = heroku
source = myherokuapp
sourcetype = heroku:syslog

indexsourcetype に先ほど設定したものを指定するのを忘れずに

HerokuでLog Drains設定

その前に...

Heroku CLIインストール

まだHeroku CLI入ってなかったので、Macにインストール

$ brew install heroku/brew/heroku
==> Tapping heroku/brew
Cloning into '/usr/local/Homebrew/Library/Taps/heroku/homebrew-brew'...
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 9 (delta 0), reused 7 (delta 0), pack-reused 0
Unpacking objects: 100% (9/9), done.
Tapped 2 formulae (36 files, 23.6KB)
==> Installing heroku from heroku/brew
==> Installing dependencies for heroku/brew/heroku: heroku/brew/heroku-node
==> Installing heroku/brew/heroku dependency: heroku/brew/heroku-node
==> Downloading https://cli-assets.heroku.com/homebrew/node-8.7.0.tar.xz
######################################################################## 100.0%
🍺  /usr/local/Cellar/heroku-node/8.7.0: 3 files, 34MB, built in 6 seconds
==> Installing heroku/brew/heroku
==> Downloading https://cli-assets.heroku.com/homebrew/heroku-6.14.36.tar.xz
######################################################################## 100.0%
🍺  /usr/local/Cellar/heroku/6.14.36: 8,177 files, 43.5MB, built in 8 seconds

Log Drains設定

Splunkで作成したデータインプット(TCP 10514ポート)に投げるようにCLIで設定

$ heroku drains:add syslog://<splunk_ip>:10514 --app myherokuapp

以上!!

Splunkで検索してみる

Screen Shot 2017-10-23 3.44.52 PM_mosaic.png

Herokuのログがインデックスされてる
若干文字コードが合ってないのかな...? ここは要対応かも

とはいえ、ログはSplunkに貯めることができるので、これでアプリケーションの稼働状況とかHeroku利用状況を監視できそう

(おまけ)フィールド抽出

こんなフィールド抽出してみた

([^\s]+\s){3}(?P<token>[^\s]+)\s(?P<category>[^\s]+)\s(?<dyno>[^\s]+)\s([^\s]+\s){2}(?P<message>[\s\S]+$)

ログ行の先頭からスペース区切り4つ目がtoken、5つ目がcategory、6つ目がdyno、9つ目がmessageという感じ

1
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?