Splunk Search

How would I divide this table into hours?

wagnerj02
Engager
source=****** "Result from operation"
| rex field=message ".*?returnCode=(?<code>\d+).*"
| eval status=if(code=0000,"success","failure")
| stats count(eval(status="success")) as complete, count(eval(status="failure")) as incomplete
| eval success = complete, failures = incomplete, total=(success +failures), percent = (success/total)
| table total, complete, failures, percent

No matter what I try, when I try to add time to this table it does not display a seperate search with

|eval hour=strftime(_time, "%H")
|table hour

works. Why can't I add hour to the table above? What would I do instead?

Tags (2)
0 Karma
1 Solution

macadminrohit
Contributor

You can either do this bucket _time span=1h add the bucket command after your first pipe and then add _time to your stats . Or i would use eventstats . Let us know how it works for you.

View solution in original post

macadminrohit
Contributor

You can either do this bucket _time span=1h add the bucket command after your first pipe and then add _time to your stats . Or i would use eventstats . Let us know how it works for you.

wagnerj02
Engager

like this? it is saying:

Error in 'stats' command: The argument '_time' is invalid.

| bucket _time span=1h
| rex field=message ".?returnCode=(?\d+)."
| eval status=if(code=0000,"success","failure")
| stats count(eval(status="success")) as complete, count(eval(status="failure")) as incomplete, _time
| eval success = complete, failures = incomplete, total=(success +failures), percent = (success/total)
| table total, complete, failures, percent, _time

0 Karma

macadminrohit
Contributor

you missed the by clause in your stats command.

0 Karma

wagnerj02
Engager

| bin _time span=1h as hour
| rex field=message ".?returnCode=(?\d+)."
| eval status=if(code=0000,"success","failure")
| stats count(eval(status="success")) as complete, count(eval(status="failure")) as incomplete by _time
| eval success = complete, failures = incomplete, total=(success +failures), percent = (success/total)
| table total, complete, failures, percent, _time

no luck, it is still breaking up in to every transaction

0 Karma

wagnerj02
Engager

oh woops i left it as hour on accident, I think it is working now

0 Karma

macadminrohit
Contributor

Can you accept the answer if it worked for you ?

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The problem lies with the stats command. Any field not explicitly mentioned in the command is not available to subsequent commands. In your example, 'complete' and 'incomplete' are the only fields passed on by stats so _time is not available to the eval. The solution is to include _time in stats or use streamstats. The streamstats command does not remove fields.

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

wagnerj02
Engager

I see, thank you for that pointer! But I am running into issues still.

Adding _time to stats doesn't seem to be working. If I stream stats, it gets divided up into individual transactions which I also can't seem to work around?

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Get Agentic with Splunk Lantern: Connect to Cisco Cloud Control, Transform ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

July Community Events: Master ITSI 5.0 & Automate Splunk

Struggling with alert fatigue or feeling like you're spending more time on infrastructure maintenance than ...

New Release of Federated Search: Bringing Splunk Analytics to More of Your Data

Organizations today are generating more data than ever and storing it across cloud object stores, data lakes, ...