Splunk Search

count over time with open/close events

sudo_su
Engager

Hello Splunkers,

I would like to create a timechart for status. The data only comes when there's an update, so generally, one event when the ticket opens, and one when it closes. How should I approach visualising this?  

Data ~

Problem IDStart TimeEnd Time
ManagementZone
1009:00nullCAT
1109:00nullDOG
1009:0009:30CAT
1210:00nullCAT
1310:00nullDOG
1109:0011:30DOG
1210:0011:30CAT
1310:0012:00DOG
1415:00nullCAT
1515:30nullDOG

 

Desired Outcome

 08:0009:0010:0011:0012:0013:0014:0015:0016:0017:00
CAT0111000111
DOG0122000011

 

Thank you all in advance. 

Labels (5)
0 Karma
1 Solution

manjunathmeti
Champion

hi @sudo_su,

Try this:

| makeresults 
| eval _raw="ProblemID	StartTime	EndTime	ManagementZone
10	09:00	null	CAT
11	09:00	null	DOG
10	09:00	09:30	CAT
12	10:00	null	CAT
13	10:00	null	DOG
11	09:00	11:30	DOG
12	10:00	11:30	CAT
13	10:00	12:00	DOG
14	15:00	null	CAT
15	15:30	null	DOG" 
| multikv forceheader=1 
| search EndTime!=null 
| table ProblemID StartTime EndTime ManagementZone 
| eval st="04/19/2021 ".StartTime, et="04/19/2021 ".EndTime 
| eval st=strptime(st, "%m/%d/%Y %H:%M"), et=strptime(et, "%m/%d/%Y %H:%M"), mv=mvrange(st, et, "1h"), mv=strftime(mv, "%H:%M") 
| mvexpand mv 
| chart count over ManagementZone by mv

 

If this reply helps you, a like would be appreciated.

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Looking at the desired outcome, it looks like you are bucketing your times to the top of the next hour (hence the relative_time calculations)

| makeresults 
| eval _raw="Problem ID,Start,End,ManagementZone
10,09:00,,CAT
11,09:00,,DOG
10,09:00,09:30,CAT
12,10:00,,CAT
13,10:00,,DOG
11,09:00,11:30,DOG
12,10:00,11:30,CAT
13,10:00,12:00,DOG
14,15:00,,CAT
15,15:30,,DOG"
| multikv forceheader=1 
| eval Start="2021-04-10T".Start
| eval End="2021-04-10T".End
| eval Start=strptime(Start,"%Y-%m-%dT%H:%M")
| eval End=strptime(End,"%Y-%m-%dT%H:%M")
| fieldformat Start=strftime(Start,"%H:%M")
| fieldformat End=strftime(End,"%H:%M")
| fields - _* linecount 
| eval change=if(isnull(End),1,-1)
| eval _time=coalesce(relative_time(End,"+1h-1s@h"),relative_time(Start,"+1h-1s@h"))
| chart sum(change) as change by _time ManagementZone
| makecontinuous _time span=1h
| fillnull value=0
| untable _time ManagementZone change
| streamstats sum(change) as count by ManagementZone
| stats sum(count) as count by _time ManagementZone
| eval time=strftime(_time,"%H:%M")
| xyseries ManagementZone time count

manjunathmeti
Champion

hi @sudo_su,

Try this:

| makeresults 
| eval _raw="ProblemID	StartTime	EndTime	ManagementZone
10	09:00	null	CAT
11	09:00	null	DOG
10	09:00	09:30	CAT
12	10:00	null	CAT
13	10:00	null	DOG
11	09:00	11:30	DOG
12	10:00	11:30	CAT
13	10:00	12:00	DOG
14	15:00	null	CAT
15	15:30	null	DOG" 
| multikv forceheader=1 
| search EndTime!=null 
| table ProblemID StartTime EndTime ManagementZone 
| eval st="04/19/2021 ".StartTime, et="04/19/2021 ".EndTime 
| eval st=strptime(st, "%m/%d/%Y %H:%M"), et=strptime(et, "%m/%d/%Y %H:%M"), mv=mvrange(st, et, "1h"), mv=strftime(mv, "%H:%M") 
| mvexpand mv 
| chart count over ManagementZone by mv

 

If this reply helps you, a like would be appreciated.

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!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...