Splunk Search

同じSourcetypeで複数のhostからデータを合計する方法について

hirosakurai
Engager

同じSourcetypeで2つのhostから受信しているcsvに含まれる値を合計したいのですが、searchの方法を教えてください。

host-Aから受信しているcsvのA列(field_A)とB列(field_B)、およびhost-Bから受信しているcsvのA列(field_A)を合計したいのです。

これらのhostは通信経路上の通信量(bps)を監視していて、A列、B列にそれぞれの監視ポート上の通信量が記録されています。
現在の環境ではhost-AのA列とB列、host-BのA列を合計すると、Inboundの合計通信量が出ます。

0 Karma
1 Solution

HiroshiSatoh
Champion

全体の合計でよいですか?
例えば以下のようにすればどうでしょうか?

index=your index (host=host-A OR host=host-B)
|stats sum(eval(if(host="host-A",field_A+field_B,field_A))) as total

ソースタイプ毎なら

index=your index (host=host-A OR host=host-B)
|stats sum(eval(if(host="host-A",field_A+field_B,field_A))) as total by sourcetype

View solution in original post

0 Karma

HiroshiSatoh
Champion

全体の合計でよいですか?
例えば以下のようにすればどうでしょうか?

index=your index (host=host-A OR host=host-B)
|stats sum(eval(if(host="host-A",field_A+field_B,field_A))) as total

ソースタイプ毎なら

index=your index (host=host-A OR host=host-B)
|stats sum(eval(if(host="host-A",field_A+field_B,field_A))) as total by sourcetype
0 Karma

hirosakurai
Engager

ありがとうございます。できました!

質問に書いていませんでしたがcsvには1秒ごとに行が記録されていて、3つのフィールドを合計した値をグラフで出したかったのです。
以下のようにしたら希望の通りのグラフを描くことができました。

 index=your index (host=host-A OR host=host-B)
 |timechart span=5m avg(eval(if(host="host-A",field_A+field_B,field_A))) as total

とても助かりました。また何かあればよろしくお願いします。

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...