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
Get Updates on the Splunk Community!

Data Management Digest – December 2025

Welcome to the December edition of Data Management Digest! As we continue our journey of data innovation, the ...

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...