Splunk Search

get all fields

Shakira1
Explorer

HI

I need to get the count of all fields in some index and then calculate how many times in percentage it occurred out of all events.

 

hope its clear.

thank you!

 

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Use the fieldsummary command to get the field info then calculate the percentage from that info.  It's not clear which percentage is sought so modify the eventstats and eval commands below as necessary.

index=_internal
| fieldsummary
``` Get the total number of fields ```
| eventstats sum(count) as Total,sum(distinct_count) as TotalDistinct
``` Compute the percentages ```
| eval Pct=round(count*100/Total,2), DistPct=round(distinct_count*100/TotalDistinct,2)

 

---
If this reply helps you, Karma would be appreciated.
0 Karma

Shakira1
Explorer

I would like to get the percentage of some count field from the total count

for example: 

after using fieldsummary I got this: [{"value":"/System/Library/LaunchAgents/com.apple.mdworker.shared.plist","count":61372} under value key

and the total count events is1,039,803, so in a new field I want to get the calculate for how much in percentage the count (61372) is from the total (1,039,803), this result I want to get to all my fields. 

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Is this more like what you envision?

index=_internal
| fieldsummary
| eventstats sum(count) as Total
``` Get rid of fields we don't need ```
| fields - max mean min stdev is_exact
``` Convert the values array to a multi-value field ```
| eval mv_values=json_array_to_mv(values)
``` Put each value into a separate event ```
| mvexpand mv_values
``` Extract value and its count ```
| rex field=mv_values "value\\\":\\\"(?<value>[^\"]+)\\\",\\\"count\\\":(?<valueCount>\d+)"
| eval Pct=round(valueCount*100/Total,2)
| table field value valueCount Pct
---
If this reply helps you, Karma would be appreciated.
0 Karma

Shakira1
Explorer

its looking very good! thank you.

I just dont understand the calculate results. 

for example: in valueCount I have 294723 from the total which is 1360007 should be ≈ 21.67% but in Pct field value I have 0.33, Do you know why?

all my results in Pct are not correct. 

0 Karma

richgalloway
SplunkTrust
SplunkTrust

I don't get it, either.  When I plug your numbers into the query I get the expected 21.67.  Can you share a screenshot just so we're sure we're looking at the right numbers?

---
If this reply helps you, Karma would be appreciated.

Shakira1
Explorer

sure.

attached the valueCount and Pct.

also the number of events:  1,380,350 events

Tags (1)
0 Karma
Get Updates on the Splunk Community!

Get ready to show some Splunk Certification swagger at .conf24!

Dive into the deep end of data by earning a Splunk Certification at .conf24. We're enticing you again this ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Now On-Demand Join us to learn more about how you can leverage Service Level Objectives (SLOs) and the new ...

Database Performance Sidebar Panel Now on APM Database Query Performance & Service ...

We’ve streamlined the troubleshooting experience for database-related service issues by adding a database ...