Splunk Search

Display specific field in log by count

Bhavika
Loves-to-Learn

I want to write the query which will number of count the event occurred and time taken for that. 

This is the log  -

log2024-07-01 16:57:17.022 INFO 1 --- [nio-8080-exec-6] xyztask : FILE_TRANSFER | Data | LOGS | Fetched count:345243 time:102445ms

time2024-07-01T16:57:17.022583728Z

 

I want result like -

| count           | time |

| 2528945    | 130444 |

Query that I am writing 

base search | stats count by count | stats count by time | table count time

For  stats count by count I am getting error - 

Error in 'stats' command: The output field 'count' cannot have the same name as a group-by field

Query isn't right, correct solution would be helpful. Also tried different queries different ways.

 

 

Labels (6)
0 Karma

PickleRick
SplunkTrust
SplunkTrust

With stats command you can use the same field name in both the aggregation function (in your case you want a count of events which yields a field named just count) and the list of fields by which you split the results (in your case count is also a field name within the event.

You can walk around the problem by renaming the field. Like

| stats count as event_count by count

This way the count of events will not be named count in the results but will be named event_count whereas the field by which you split the results (which comes from your events) will stay named count. Yes, it's a tiny bit confusing.

Anyway, I don't see what's the relation between your data and your desired results. And your final table command is completely unnecessary at this point - your results will just contain table of fields count and time after the last stats command so the table command is not needed.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Is it just a case of extracting count and time from your event? If so, why are you using stats commands?

0 Karma

Bhavika
Loves-to-Learn

@ITWhisperer  Yes, just the extraction of count and time which is there in log. What is the correct way ? I am new to Splunk.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Probably the simplest (assuming the event you posted is an accurate representation of your events) is to use rex to extract the fields.

| rex "count:(?<count>\d+) time:(?<time>\d+)ms"
0 Karma

Bhavika
Loves-to-Learn

This is generating logs and not the expected output.

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

What is your full search?

0 Karma

bowesmana
SplunkTrust
SplunkTrust

rex just extracts the fields, now add

| table count time

if you want each event listed with the count and time.

If you want some other representation of those values, please say what you want

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...