2
0

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.

Splunk: _timeの値の形式は「UNIX時間」である

Posted at

時々忘れがちなのでメモ。

実施環境: Splunk Free 8.2.2

Splunk のログイベントは、デフォルトで _time というフィールドを持ちます。
検索結果を見た際、この値は基本的には一般的な日時形式で表示されます。

Splunk
| makeresults count=1

スクリーンショット 2021-11-28 20.32.37.png

ですが実際は内部的には _time は UNIX 時間として格納されています。
以下のように行と列を入れ替えるとよくわかります。

Splunk
| makeresults count=1
| transpose

スクリーンショット 2021-11-28 20.35.17.png

「 _time フィールドの値」である限り、実際の中身が UNIX 時間であっても Splunk は上記のように一般的な日時の形式で表示してくれます。
そのため、通常の検索ではこのことをあまり意識する必要はありません。
ただ、「 _time フィールドの値」でなくなる場合は話は別です。
例えば、 rename コマンドを使用してフィールド名を _time から別の名前に変更した場合、その値は元の UNIX 時間の形式で表示されてしまいます。

Splunk
| makeresults count=1
| rename _time AS "ログ出力日時"

スクリーンショット 2021-11-28 20.41.53.png

他にも、先ほどのように transpose で行と列を入れ替えたり、 _time の値を別のフィールドにコピーした際にも同様のことが起こります。
このような場合、 eval コマンドの strftime 関数を使用して、 UNIX 時間を任意の日付形式に変換する必要があります。

Splunk
| makeresults count=1
| eval _time = strftime(_time, "%Y/%m/%d %H:%M:%S")
| rename _time AS "ログ出力日時"

スクリーンショット 2021-11-28 20.45.22.png

結果の列名を日本語名に変換する際等意外とひっかかるので、気をつけましょう。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?