Splunk Search

search results sum count by date?

abovebeyond
Communicator

Hi,
Im trying to sum results by date:

CreatedDate ------ count
2015-12-2 ------ 1
2015-12-1 ------ 4
2015-11-30 ------ 5
2015-11-29 ------ 2

i want to count how much in each month, how can i do it?

Thanks!

Tags (2)
0 Karma

fdi01
Motivator

if count and CreateDate fields exit after you run your_DB_search try simplily:

<your_DB_search>| timechart span=1months sum(count) by CreatedDate usenull=f useother=f
0 Karma

yannK
Splunk Employee
Splunk Employee

If the field CreatedDate is not detected as a valid date, you can convert it.
see http://docs.splunk.com/Documentation/Splunk/6.3.1511/SearchReference/Convert

<mysearch>
| convert timeformat="%Y-%m-%d" ctime(CreatedDate) AS NewCreatedDate
| bucket span=1month NewCreatedDate
 | stats sum(count) AS total_count by NewCreatedDate
0 Karma

abovebeyond
Communicator

Hi yannK , tried it without a success

NewCreatedDate shows nothing...

Any other suggestions ?

Thanks !

0 Karma

dcarmack_splunk
Splunk Employee
Splunk Employee

try this

| bucket span=1mon CreatedDate
| stats sum(count) AS total_count by CreatedDate
0 Karma

abovebeyond
Communicator

hmm i forgot to mention , this is a db connect query

the results from the DB , its not parsed so date_month isn't working

any other options ?

0 Karma

jmallorquin
Builder
|rex "\d{4}\-(?<month>[^\-]+)"
|rex "\-\-\-\-\-\-\s+(?<count>\d+)"
|stats sum(count) by month
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...