Splunk Search

How to show timechart and timewrap of business hours

dyapasrikanth
Path Finder

I am trying to compare count of events with previous days within business hours, here is my query

 

 

index=abc
| search "userId:" 
| where date_hour>=9 AND date_hour<=17
| rex field=message "userId: (?<customerId>.*)" 
| timechart span=1h dc(customerId) as "Unique customer count" 
| timewrap d

 

 

I am trying to see the chart data only between 9AM to 5PM, but it is showing data (bar chart) on 24hr scale with blank before 9AM and after 5PM.

How can I adjust the query or time picker to get the desired output ?

Labels (2)
0 Karma

venkatasri
SplunkTrust
SplunkTrust

Hi @dyapasrikanth 

Can you try this,

index=abc earliest=@d+9h latest=@d+17h "userId:" 
| rex field=message "userId: (?<customerId>.*)" 
| timechart span=1h dc(customerId) as "Unique customer count" 

---

An upvote would be appreciated and accept solution if it helps!

 

dyapasrikanth
Path Finder

This is working fine for one day's data, even my search range is last 7days it is just giving today's data only.

0 Karma

venkatasri
SplunkTrust
SplunkTrust

Hi @dyapasrikanth 

Can you try this

index=abc "userId:" 
| where date_hour>=9 AND date_hour<=18
| rex field=message "userId: (?<customerId>.*)" 
| timechart span=1h dc(customerId) as "Unique customer count"

---

An upvote would be appreciated if it helps!

dyapasrikanth
Path Finder

It is still giving data from 00:00 to 23:00

dyapasrikanth_0-1624844139894.png

 

0 Karma

venkatasri
SplunkTrust
SplunkTrust

Hi @dyapasrikanth 

I wish this can be done better, however date_hour i understood its not being extracted by Splunk from _time but actually its from original event FYI. About default fields (host, source, sourcetype, and more) - Splunk Documentation

Following should work, extracted hour from _time. you would find events upto 17:59 as time_hour = 17,  you need to further change this condition using time_min

 

index=abc "userId:" 
| eval time_hour=strftime(_time, "%H") , time_min=strftime(_time, "%M")
| where time_hour >=9 AND time_hour<=17 
| rex field=message "userId: (?<customerId>.*)" 
| timechart span=1h dc(customerId) as "Unique customer count"

 

---

An upvote would be appreciated if it helps!

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!

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...