Splunk Search

複数のフィールドの日付をカウントし、チャートに積算で表示したい。(不具合死滅曲線の作成)

yanagihara
New Member

開始日と終了日を持つソースから、それぞれの日付の個数を積算で一つのグラフに重ねて以下の様なイメージで表示ができればと考えております。
ソースには、開始日、終了日やそのほかステータスが存在し開始日、終了日だけの曲線は以下のようなコマンドで表示ができました。
ですが、開始日と終了日両方を別々のフィールドにカウントし、どちらかが存在する日付で、積算で表示することができませんでした。
日にちは、ある一定の間の毎日でも構いません。
どうか、ご教授をお願いします。

|stats count by 開始日
|streamstats sum(count)
|table 開始日 sum(count)

alt text

Tags (1)
0 Karma
1 Solution

melonman
Motivator

サンプルログとして以下を利用してやってみました。

start=2015/12/09-15:31:11 end=2015/12/13-15:31:11 status=0
start=2015/12/10-15:31:11 end=2015/12/17-15:31:11 status=0
start=2015/12/11-15:31:11 end=2015/12/15-15:31:11 status=0
start=2015/12/12-15:31:11 end=2015/12/14-15:31:11 status=0
start=2015/12/13-15:31:11 end=2015/12/15-15:31:11 status=0
start=2015/12/14-15:31:11 end=2015/12/18-15:31:11 status=0
start=2015/12/15-15:31:11 end=2015/12/16-15:31:11 status=1
start=2015/12/16-15:31:11 end=2015/12/21-15:31:11 status=0
start=2015/12/17-15:31:11 end=2015/12/25-15:31:11 status=0
start=2015/12/18-15:31:11 end=2015/12/24-15:31:11 status=1

start=の部分の日付は、イベント(ログの各行)のタイムスタンプとして、認識されているので、そのままtimechart span=1d countをすれば1日ごとの集計は可能です。次に、endをタイムスタンプとして設定して、timechart span=1d count とすれば、endを元にした日付ごとの集計が可能です。それぞれの積算が必要なので、streamstats sum(count)で積算を出します。最後に、もう一回timechartで2つの結果を日付でひも付けますが、first()コマンドでその日の値を取得し、start/endとしてそれぞれ名前を振り直します。最後にstartの値がendの終了日まで存在しないので、startの最後の値をつかって、nullの部分を埋めます。

と書きましたが、以下がそのサーチと図です。サーチを分解して、append前と[]内をそれぞれ実行してみて、動きを確認いただければとおもいます。

source="*sample.log" sourcetype=test 
| timechart span=1d count 
| streamstats sum(count) as start 
| fields - count 
| append [ search source="*sample.log" sourcetype=test 
| eval _time=strptime(end,"%Y/%m/%d-%H:%M:%S") 
| timechart span=1d count 
| streamstats sum(count) as end 
| fields - count
] | timechart first(start) as start first(end) as end 
| filldown start

alt text

もっと簡単で効率的な方法があるかもしれませんが、まずは一例として参考までにどうぞ。

View solution in original post

0 Karma

melonman
Motivator

サンプルログとして以下を利用してやってみました。

start=2015/12/09-15:31:11 end=2015/12/13-15:31:11 status=0
start=2015/12/10-15:31:11 end=2015/12/17-15:31:11 status=0
start=2015/12/11-15:31:11 end=2015/12/15-15:31:11 status=0
start=2015/12/12-15:31:11 end=2015/12/14-15:31:11 status=0
start=2015/12/13-15:31:11 end=2015/12/15-15:31:11 status=0
start=2015/12/14-15:31:11 end=2015/12/18-15:31:11 status=0
start=2015/12/15-15:31:11 end=2015/12/16-15:31:11 status=1
start=2015/12/16-15:31:11 end=2015/12/21-15:31:11 status=0
start=2015/12/17-15:31:11 end=2015/12/25-15:31:11 status=0
start=2015/12/18-15:31:11 end=2015/12/24-15:31:11 status=1

start=の部分の日付は、イベント(ログの各行)のタイムスタンプとして、認識されているので、そのままtimechart span=1d countをすれば1日ごとの集計は可能です。次に、endをタイムスタンプとして設定して、timechart span=1d count とすれば、endを元にした日付ごとの集計が可能です。それぞれの積算が必要なので、streamstats sum(count)で積算を出します。最後に、もう一回timechartで2つの結果を日付でひも付けますが、first()コマンドでその日の値を取得し、start/endとしてそれぞれ名前を振り直します。最後にstartの値がendの終了日まで存在しないので、startの最後の値をつかって、nullの部分を埋めます。

と書きましたが、以下がそのサーチと図です。サーチを分解して、append前と[]内をそれぞれ実行してみて、動きを確認いただければとおもいます。

source="*sample.log" sourcetype=test 
| timechart span=1d count 
| streamstats sum(count) as start 
| fields - count 
| append [ search source="*sample.log" sourcetype=test 
| eval _time=strptime(end,"%Y/%m/%d-%H:%M:%S") 
| timechart span=1d count 
| streamstats sum(count) as end 
| fields - count
] | timechart first(start) as start first(end) as end 
| filldown start

alt text

もっと簡単で効率的な方法があるかもしれませんが、まずは一例として参考までにどうぞ。

0 Karma

yanagihara
New Member

早速の回答ありがとうございます。
ご教授いただいた、コマンドで試してみたところ上手くいきませんでした。
以下のコマンドを実施した際に_timeのフィールドに値が何も入っていない状態を確認しました。
これが原因ではないかと思っています。

| eval _time=strptime(end,"%Y/%m/%d-%H:%M:%S")
| table _time

実は、質問時に提示したソースには省略していたのですが、ソースにはすでに_timeのフィールドが存在し取り込んだ時間の値が入っている状態です。
既にあるソースのフィールドにevalコマンドで値を入力することはできるのでしょうか。
最初とは別の質問となってしまい申し訳ありません。
以上、よろしくお願いします。

0 Karma

melonman
Motivator

ちなみにtimechartでは_timeの情報(タイムスタンプとして認識されている情報)を元に集計を行いますので、集計に必要な時刻データを_timeとして指定するなどして集計される必要があります。

実際のデータのサンプルをいただければ時間のフォーマットにあわせたstrptimeの指定を試せるので、サンプルのデータをいただけますか?

0 Karma

yanagihara
New Member

ファイル添付の仕方がわからなかったので、CSVファイルの内容を記入します。
開始日と終了日を利用たいと考えております。
””は、文字拡大を防ぐためにここに記入するときだけつけました。

"#,トラッカー,ステータス,優先度,題名,担当者,進捗率,更新日,開始日,期日,作業時間の記録,作成日,終了日
24,,終了,通常,,,100,2015/8/17 14:03,2014/2/19,2015/8/29,0,2014/2/19 22:49,2015/8/17 14:03
388,,終了,通常,,,100,2015/8/17 14:03,2014/5/2,2015/8/29,0,2014/5/2 8:48,2015/8/17 14:03
516,,終了,高め,,,100,2015/8/17 14:02,2014/7/30,2015/8/29,0,2014/7/30 17:02,2015/8/17 14:02
588,,終了,通常,,,100,2015/4/10 13:58,2014/9/9,2015/2/27,0,2014/9/9 16:43,2015/2/27 22:02
599,,終了,通常,,,100,2015/8/17 14:03,2014/9/12,2014/10/24,0,2014/9/12 17:41,2015/8/17 14:03
630,,終了,通常,,,100,2014/11/8 10:13,2014/10/7,2014/10/17,0,2014/10/7 10:46,2014/10/8 16:01
631,,終了,低め,,,100,2015/1/24 11:27,2014/10/22,2014/10/31,0,2014/10/7 10:51,2014/10/9 15:44
632,,終了,急いで,,,100,2014/11/8 10:12,2014/10/7,2014/10/10,0,2014/10/7 10:57,2014/10/17 16:55
633,,終了,高め,,,100,2015/8/17 14:02,2014/10/7,2015/8/15,0,2014/10/7 11:01,2015/8/17 14:02

以上、よろしくお願いします。

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...