Splunk Search

How to Split a field that is the subject of a Top command?

Naji
Explorer

When I ran the following query:

 

 

index="myindex" sourcetype="hamlet" environment=staging
| top limit=10 client
| eval percent = round(percent)
| rename client AS "Users", count AS "Requests", percent AS "Percentage %"

 

 

I get these results:

Users Requests Percentage %
joe.smith@alora.com 118 21
martha.taylor@gmail.com 80 14
paul.gatsby@aol.com 68 12

 

What I want instead are these results

Users Requests Percentage %
joe.smith 118 21
martha.taylor 80 14
paul.gatsby 68 12

 

I hope this helps. Sorry if my original post was confusing. I appreciate your help. Thank you

 

 

Labels (1)
0 Karma
1 Solution

Naji
Explorer

Thank you for your response. That query did not work for me at all. Here is what worked perfectly:

 

index="myindex" sourcetype="hamlet" environment=staging
| rex field=client mode=sed "s/"@aol.com"|"@gmail.com"/""/g"
| eval percent = round(percent)
| rename client AS "Users", count AS "Requests", percent AS "Percentage %"

 

In my case, I have one single domain to worry about.

View solution in original post

0 Karma

yuanliu
SplunkTrust
SplunkTrust

The revised question does show a difference between actual output and desired output.  Your original post also included commands that looks to be able to correctly make the change, something like

 

index="myindex" sourcetype="hamlet" environment=staging
| top limit=10 client
| eval percent = round(percent)
| eval client = mvindex(split(client, "@"), 0)
| rename client AS "Users", count AS "Requests", percent AS "Percentage %"

 

Using the first table to reverse engineer the output from index="myindex" sourcetype="hamlet" environment=staging | top 10 client, I write the following emulation:

 

| makeresults
| eval _raw = "client	count	percent
joe.smith@alora.com	118	21
martha.taylor@gmail.com	80	14
paul.gatsby@aol.com	68	12"
| multikv
| fields - _* linecount
``` the above emulates
index="myindex" sourcetype="hamlet" environment=staging
| top 10 client
```

 

Putting these two together, I get emulated result that is exactly like you wanted:

Percentage %RequestsUsers
21118joe.smith
1480martha.taylor
1268paul.gatsby

In other words, I cannot see why your original code shouldn't work.  Maybe you can play with that emulation and compare with real data from top 10, and let us know the difference?

0 Karma

Naji
Explorer

Thank you for your response. That query did not work for me at all. Here is what worked perfectly:

 

index="myindex" sourcetype="hamlet" environment=staging
| rex field=client mode=sed "s/"@aol.com"|"@gmail.com"/""/g"
| eval percent = round(percent)
| rename client AS "Users", count AS "Requests", percent AS "Percentage %"

 

In my case, I have one single domain to worry about.

0 Karma

yuanliu
SplunkTrust
SplunkTrust

Could you define "not working"?  This is a phrase to be avoided in the best of situations, let alone in a forum where volunteers have no insight into your dataset.  How do your data look like?  What is the result that does not meet your requirement?   Obviously the commands you used are suitable for the problem, so the problem must be caused by data.  But without illustration of either data or actual result, it is impossible to tell what exactly is causing a problem.

The most common problem of this type comes from possible multivalue in clientId.  To handle multivalued calculation, use mvmap, like

index="myindex" sourcetype="hamlet" environment=staging |
eval tmp = mvmap(clientId, split(clientId,"@")) | 
eval sender = mvmap(tmp, mvindex(tmp,0)) |
top limit=10 sender |
eval percent = round(percent) |
rename sender AS "Users", count AS "Plays", percent AS "Percentage %"

 

0 Karma

Naji
Explorer

I edited my post for clarity. Thank you

0 Karma
Get Updates on the Splunk Community!

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

Splunk Education Goes to Washington | Splunk GovSummit 2024

If you’re in the Washington, D.C. area, this is your opportunity to take your career and Splunk skills to the ...