Splunk Search

How to display the difference between the results from two different searches?

thewho123
Explorer

I display two different graphs by using the following strings.

"Sending" earliest=-7days | eval gigabytes=((bytes/1024)/1024) | timechart span=1day avg(gigabytes) AS "Gigabytes sent"

"Receiving" earliest=-7days | eval gigabytes=((bytes/1024)/1024) | timechart span=1day avg(gigabytes) AS "Gigabytes received"

I can display both in the same graph by:

"Sending" earliest=-7days | eval gigabytes=((bytes/1024)/1024) | timechart span=1day avg(gigabytes) AS "Gigabytes sent" | appendcols [search "Receiving" earliest=-7days | eval gigabytes=((bytes/1024)/1024) | timechart  span=1day avg(gigabytes) AS "Gigabytes received"]

This gives me two lines (each has a value for one day for the past 7 days).

How do I display the difference between gigabytes sent and received? I want to display Gigabytes sent - gigabytes received for each day for the past 7 days.

0 Karma
1 Solution

sundareshr
Legend

Try this

"Sending" OR "Receiving" earliest=-7days | rex  "(?<action>Sending|Receiving)" | eval gigabytes=((bytes/1024)/1024) | timechart span=1day avg(gigabytes) as gb by action | eval diff=Sending-Receiving

View solution in original post

sundareshr
Legend

Try this

"Sending" OR "Receiving" earliest=-7days | rex  "(?<action>Sending|Receiving)" | eval gigabytes=((bytes/1024)/1024) | timechart span=1day avg(gigabytes) as gb by action | eval diff=Sending-Receiving

thewho123
Explorer

Is the syntax correct? I get null for y-axis description.

Also avg bytes from sending and receiving should be separate. Wouldn't this combine all of them together ?

0 Karma

sundareshr
Legend

Do you not see columns for Sending and Receiving? The avg(gb) will be calculated separately for each action. If NULL is the third column, you could add usenull=f to the timechart command. You search would look like this

index=myIndex sourcetype=mySourcetype "Sending" OR "Receiving" earliest=-7d@d | rex  "(?<action>Sending|Receiving)" | eval gigabytes=((bytes/1024)/1024) | timechart usenull=f span=1day avg(gigabytes) as gb by action | eval diff=Sending-Receiving
0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...