Splunk Search

How to edit my search to transpose data field (in column) to header field?

rflouquet
Explorer

Hello,

I'm trying to get this table :

Device ----- Interface ----- March ----- April ----- .....

device1 ----- interface1 ----- LoaddurationM1 ----- LoaddurationA1 ----- .....

device2 ----- interface2 ----- LoaddurationM2 ----- LoaddurationA2 ----- .....

But after running my search I'm getting the table :

Month ----- Device----- Interface----- Load Duration
March----- device1 ----- interface1----- LoaddurationM1
April----- device1 ----- interface1----- LoaddurationA1
April----- device2 ----- interface2----- LoaddurationA2
March----- device2 ----- interface2 ----- LoaddurationM2

I tried the "transpose" command but nothing works.

My search is the next one :

sourcetype=csv Device=*
| eval LD=if(Bits_out_sec>Bandwidth*0.8, Duration, 0)
|stats sum(Duration) AS TotalDuration sum(LD) AS TotalLD BY date_month, Device, Interface
|eval "Load Duration"=round(TotalLD/TotalDuration*100,2)
|table date_month, Device, Interface, "Load Duration"

If you have any idea it would be great.

Thanks a lot,

Romain

0 Karma
1 Solution

woodcock
Esteemed Legend

Try this:

sourcetype=csv Device=*
| eval LD=if(Bits_out_sec>Bandwidth*0.8, Duration, 0)
| stats sum(Duration) AS TotalDuration sum(LD) AS TotalLD BY date_month, Device, Interface
| eval "Load Duration"=round(TotalLD/TotalDuration*100,2)
| eval Device_Interface = Device . ":::" . Interface
| fields - Device Interface
| xyseries Device_Interface date_month "Load Duration"
| rex field=Device_Interface "^(?<Device>.*?):::(?<Interface>.*)$"
| fields - Device_Interface
| table Device Interface *

You will now probably care about the ordering of the months along the top, for that, see my (should-be-accepted-but-unfortunately-hasn't-been) answer on this Q&A:

https://answers.splunk.com/answers/522959/cannot-sort-dynamic-column-in-date-format.html

View solution in original post

0 Karma

woodcock
Esteemed Legend

Try this:

sourcetype=csv Device=*
| eval LD=if(Bits_out_sec>Bandwidth*0.8, Duration, 0)
| stats sum(Duration) AS TotalDuration sum(LD) AS TotalLD BY date_month, Device, Interface
| eval "Load Duration"=round(TotalLD/TotalDuration*100,2)
| eval Device_Interface = Device . ":::" . Interface
| fields - Device Interface
| xyseries Device_Interface date_month "Load Duration"
| rex field=Device_Interface "^(?<Device>.*?):::(?<Interface>.*)$"
| fields - Device_Interface
| table Device Interface *

You will now probably care about the ordering of the months along the top, for that, see my (should-be-accepted-but-unfortunately-hasn't-been) answer on this Q&A:

https://answers.splunk.com/answers/522959/cannot-sort-dynamic-column-in-date-format.html

0 Karma

rflouquet
Explorer

Thanks a lot @woodcock, It work !

I'm looking att your "should-be-accepted...........answer" too !

Thanks

0 Karma

woodcock
Esteemed Legend

If any answer over there helps, be sure to up-vote.

0 Karma

cmerriman
Super Champion

try this:

sourcetype=csv Device=*
 | eval LD=if(Bits_out_sec>Bandwidth*0.8, Duration, 0)
 |stats sum(Duration) AS TotalDuration sum(LD) AS TotalLD BY date_month, Device, Interface
|eval deviceInterface=Device+" - "+Interface
|eval "LoadDuration"=round(TotalLD/TotalDuration*100,2)
|chart values(LoadDuration) as LoadDuration by deviceInterface
|makemv deviceInterface delim=" - "
|eval Interface=mvindex(deviceInterface ,1)
|eval Device=mvindex(deviceInterface ,0)
|fields - deviceInterface 
0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...