Splunk Search

Change field values into a column using chart command

SarahWKarvenz
Path Finder

I have the following search: stats count by jvm category host

This returns a table with the headings count, jvm, host, category

Category has 4 different values in it and I would like to make those each a column header so that my table would have the headings count, jvm, host, category 1, category 2, category 3, category 4.

I have tried using the chart command to do this. However it will not allow me to group on jvm and host. Regardless of whether I use "chart sum(count) by host,category,jvm" or "chart sum(count) over jvm by host,category" it will not recognize a "third field". "chart sum(count) by host,category" or "chart sum(count) over jvm by host" work just fine.

Any suggestions on how to do this? using either the chart command or something else?
(I am using version 4.3.1)

Thanks!
Sarah

Tags (3)
0 Karma

gkanapathy
Splunk Employee
Splunk Employee

You need something like this:

... | eval hj=host+";"+jvm | chart count by hj,category | eval hj=split(hj,";") | eval host=mvindex(hj,0) | eval jvm=mvindex(hj,1) | fields - hj

which will work regardless of what your category values are.

lguinn2
Legend

Thanks - this is a much better answer! I thought of concatenating the fields, but didn't consider how to split them again after the stats.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...