Splunk Search

How to combine the results ?

skavuri11
Observer

I am new to Splunk. I have the logs in the following format for our servers. 

  • Host, CPU, %USAGE
  • Host, Memory, %Usage
  • Host, Load Average, % USAGE
  • Host, Swapping, %Usage

I need to create a query to display the results in the following format. 

  • HOST, CPU Avg Usage, Memory Avg Usage, Load Avg Usage, Swapping Avg Usage

My query below is printing the same value for each of fields. Ex: it prints the same cpu value for all the rows. Any suggestions on the query?

    index = index1 sourcetype=.... source=...
      | eval cpu_usage = [search index = ... sourcetype=... source=*  | search metric_name=CPU_Utilization | stats avg(Usage) as "CPU_Usage" by host_name | return $CPU_Usage ]
      | eval memory_usage = [search index = ... sourcetype=... source=*  | search metric_name=Memory_Utilization | stats avg(Usage) as "Memory_Usage" by host_name | return $Memory_Usage ]
      | eval load_usage = [search index = ... sourcetype=... source=*  | search metric_name=Load_Utilization | stats avg(Usage) as "Load_Usage" by host_name | return $Load_Usage ]
      | eval swapping_usage = [search index = ... sourcetype=... source=*  | search metric_name=Swapping_Utilization | stats avg(Usage) as "Swapping_Usage" by host_name | return $Swapping_Usage ]
      | stats values(cpu_usage) as "CPU Utilization", values(memory_usage) as "Memory  Utilization", values(load_usage) as "Load  Utilization", values(swapping_usage) as "Swapping  Utilization"  by host_name
Labels (1)
0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

please try the next:

 

index=_internal 
| head 1
| eval _raw = "Host, metric_name, usage
f1, CPU, 10
f1, mem, 11
f1, mem, 12
f1, swap, 0
f1, load, 10
f1, load, 5
f1, CPU, 1"
| multikv forceheader=1
| makemv metric_name
| rename COMMENTS as "Previous prepare sample data"
| eval {metric_name} = usage
| stats avg(CPU) as aCPU avg(load) as aLoad avg(mem) as aMem avg(swap) as aSwap by Host

 

 

Here I suppose that you have field names: Host, metric_name, usage in your events. 

Last two rows do the logic:

  • create new field name value of metric_name (CPU, men, swap or load) and assign usage% to it
  • stats just count averages by Host 

r. Ismo

0 Karma

skavuri11
Observer

Thank you @isoutamo . My query with your suggestions works now. 

0 Karma
Get Updates on the Splunk Community!

Data Management Digest – December 2025

Welcome to the December edition of Data Management Digest! As we continue our journey of data innovation, the ...

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...