Splunk Enterprise

Combine 2 searches with sub search into One Time Chart

prasad984m
Loves-to-Learn

I have 2 queries which is having sub search for input look up in each.

Query 1

This query outputs the timechart for for CPU1. It will count each processes listed in the CPU1 field of the test.csv. 

index=custom | eval SEP=split(_raw,"|"), eval CPU1=trim(mvindex(SEP,1))
| bin _time span=1m
| stats count(CPU1) as CPU1_COUNT by _time CPU1

| search 
[ |  input lookup test.csv  | fields CPU1 | fillnull value = 0 |  format ]


 

Query 2

This query outputs the timechart for for CPU2. It will count each processes listed in the CPU2 field of the test.csv. 

index=custom | eval SEP=split(_raw,"|"), eval CPU2=trim(mvindex(SEP,1))
| bin _time span=1m
| stats count(CPU2) as CPU2_COUNT by _time CPU2

| search 
[ |  input lookup test.csv  | fields CPU2 | fillnull value = 0 |  format ]

 

test.csv (sample)

CPU1CPU2CPU3
process_aprocess_bprocess_c
process_dprocess_eprocess_f
process_gprocess_iprocess_h

 

 

What I want is to display the CPU1 and CPU2 time chart in one chart . 

Any advice on that will be a great help.

Thanks

Labels (1)
0 Karma

P_vandereerden
Splunk Employee
Splunk Employee

The CSV is not structured as a lookup table. The structure should be that, given a value for CPU1 (e.g. "process_a"), what are the (first matching) values for CPU2 ("process_b") and CPU3 ("process_c").

What you seem to be looking for is given a value for some CPU (e.g. "process_a"), to what CPU category does it belong ("CPU1").

Are you able to restructure the test.csv to be more like:

ProcessCPU Class
process_aCPU1
process_bCPU2
process_cCPU3
process_dCPU1
process_eCPU2
process_fCPU3
process_gCPU1
process_hCPU2
process_iCPU3

 

IF you can't restructure that file, something like this would work:

 

| makeresults 
| eval CPU=mvappend("process_a","process_a","process_b","process_a","process_c","process_a","process_b","process_d","process_a","process_e","process_a","process_b","process_c","process_a","process_a","process_b","process_d","process_a","process_c","process_a","process_b","process_e","process_a")
| mvexpand CPU
``` The above is to generate sample data and can be ignored in your SPL ```
``` uncomment the line below and notice the change from CPU1 to CPU ```
```index=custom | eval SEP=split(_raw,"|"), eval CPU=trim(mvindex(SEP,1))```
``` These two lines create aliases to map in the CPU group for each class in turn ```
| eval myCPU1=CPU
| eval myCPU2=CPU
``` These next lines assume that a process will only appear once in the test.csv file. ``` 
``` If that is the case, then CPU2 and CPU3 will be non-null when CPU1 matches, ```
``` otherwise that process does not belong to CPU1 (and ditto for the CPU2 case.) ```
| lookup community CPU1 as myCPU1 | eval myCPU1=if(NOT isnull(CPU2),CPU,NULL) 
| lookup community CPU2 as myCPU2 | eval myCPU2=if(NOT isnull(CPU1),CPU,NULL)
``` Now create your stats on the two CPU classes. ```
| bin _time span=1m
| stats count(myCPU1) as CPU1_COUNT count(myCPU2) as CPU2_COUNT by _time

 

 

Paul van der Eerden,
Breaking software for over 20 years.
0 Karma
Get Updates on the Splunk Community!

New Case Study Shows the Value of Partnering with Splunk Academic Alliance

The University of Nevada, Las Vegas (UNLV) is another premier research institution helping to shape the next ...

How to Monitor Google Kubernetes Engine (GKE)

We’ve looked at how to integrate Kubernetes environments with Splunk Observability Cloud, but what about ...

Index This | How can you make 45 using only 4?

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