Splunk Search

Count days with events

NaorPenso
Explorer

Hi everyone,
I have looked all over for a solution but without luck, so i'm approaching you hoping to find a solution.
I would like to count the amount of days (not the amount of events) that has events based on a ctime value in the log.

Sample log:

1398963749 1398963749 1432 1404320549
0 0 10446976 15988 2 4 0
DD_Servers_2003-2008_1398963749_FULL.f
NULL NULL 0 1 0 2 1399050149 NULL 1 0 0 0 0 0 0 NULL 0 0 0 NULL 777220 1 0 1999619 0 0 NULL 3 1398963602 3 0 NULL NULL 0 1 0 0

The first field states the EPOCH time of the event start (i should mention right away that Splunk time is not relevant as it is the time of insertion to the index, not this field)
what I do is:

index="foo" | convert ctime(bar)

From here on im stuck as to how to count the amount of days with the event (i.e. 33 days with events)

Thanks in advance

Tags (3)
0 Karma
1 Solution

lguinn2
Legend

I would do it like this

index="foo"
| bucket ctime span=1d
| stats dc(ctime) as numberofuniquedays

If you want to check that this makes sense, try

index="foo"
| bucket ctime span=1d
| stats count by ctime
| fieldformat ctime=strftime(ctime,"%x %X")

BTW, you can get Splunk to use the ctime of the event - and you probably should. It will make a lot of the reports easier and more sensible. Here is how do that:

props.conf

[sourcetypeOfData]
MAX_TIMESTAMP_LOOKAHEAD = 11
TIME_FORMAT = %s

This props.conf goes on the indexer(s), or wherever the data is being parsed.

View solution in original post

0 Karma

lguinn2
Legend

I would do it like this

index="foo"
| bucket ctime span=1d
| stats dc(ctime) as numberofuniquedays

If you want to check that this makes sense, try

index="foo"
| bucket ctime span=1d
| stats count by ctime
| fieldformat ctime=strftime(ctime,"%x %X")

BTW, you can get Splunk to use the ctime of the event - and you probably should. It will make a lot of the reports easier and more sensible. Here is how do that:

props.conf

[sourcetypeOfData]
MAX_TIMESTAMP_LOOKAHEAD = 11
TIME_FORMAT = %s

This props.conf goes on the indexer(s), or wherever the data is being parsed.

0 Karma

NaorPenso
Explorer

Hi,
Thanks a lot, you steered me to the correct path.
it didn't work exactly as i wanted so what i did is:

index="foo" |
convert ctime(bar) as Time timeformat=%m/%d/%y |
bucket Time span=1d |
stats dc(Time) as numberofuniquedays

Thanks again!!

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!

Build the Future of Agentic AI: Join the Splunk Agentic Ops Hackathon

AI is changing how teams investigate incidents, detect threats, automate workflows, and build intelligent ...

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...