Splunk Search

Pie-chart with count from different search criteria

habisht
Explorer

Hi All,
I'm trying to create a pie chart where i'v 2 search result sets from different condition and different source. But i'm not able to join the result set into one pie chart.

index=A sourcetype=B host=C | rex "pattern1" | chart count(field1) AS result1
index=A sourcetype=B host=C | rex "pattern2" | chart count(field2) AS result2
index=A sourcetype=B host=D | rex "pattern3" | chart count(field3) AS result3

PieChart should represent resullt1, result2, others(resul3 - result1 - result2) out of result3

0 Karma
1 Solution

jitendragupta
Path Finder

try this:

index=A sourcetype=B host=C | rex "pattern1" | chart count(field1) AS result1  | append [search
index=A sourcetype=B host=C | rex "pattern2" | chart count(field2) AS result2] | append [search
index=A sourcetype=B host=D | rex "pattern3" | chart count(field3) AS result3] | fillnull 
| stats sum(result1) as result1 sum(result2) as result2 sum(result3) as result3 | eval result3=result3-result1-result2 | transpose

View solution in original post

jitendragupta
Path Finder

try this:

index=A sourcetype=B host=C | rex "pattern1" | chart count(field1) AS result1  | append [search
index=A sourcetype=B host=C | rex "pattern2" | chart count(field2) AS result2] | append [search
index=A sourcetype=B host=D | rex "pattern3" | chart count(field3) AS result3] | fillnull 
| stats sum(result1) as result1 sum(result2) as result2 sum(result3) as result3 | eval result3=result3-result1-result2 | transpose

habisht
Explorer

This is perfect. Thanks jitendragupta.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi habisht,
you have to use the eval command to discriminate the values, something like this:

index=A sourcetype=B (host=C OR host=D)
| rex "regex<field1>regex"
| rex "regex<field2>regex"
| rex "regex<field3>regex"
| eval result=if(field1="Pattern1","result1","")
| eval result=if(field2="Pattern2","result2",result)
| eval result=if(field1!="Pattern1" OR field2!="Pattern2","result3",result)
| stats count BY result

Bye.
Giuseppe

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 ...