Splunk Search

How to sum a field grouped by months using a date field

handygecko
Explorer

I'm new to splunk and I'm still struggling to grasp how it works. I uploaded data from a simple csv file. Data is as follows:

Column A       Column B
1/1/2012         9
2/1/2012         5
3/1/2012         17
1/17/2012       11

I would like to sum column B by Month as follows:

Jan                20
Feb               5
Mar              17

Ultimately, I'm looking to create a bar chart displaying this data by year. Any help is greatly appreciated.

Tags (2)
0 Karma
1 Solution

Ayn
Legend

Assuming you have your timestamps working correctly:

... | timechart span=1mon sum(B)

View solution in original post

0 Karma

Ayn
Legend

Assuming you have your timestamps working correctly:

... | timechart span=1mon sum(B)

0 Karma

Ayn
Legend

Splunk shold do this by default. It'll use the first date it encounters in each event.

0 Karma

handygecko
Explorer

You got me going on the right track. Splunk was failing to parse timestamps. I managed to index several files properly, however, a couple files require a more complex regular expression for the preface pattern. The events are structured as follows:

"Justin Lang:2465-1-Lang","164","10/4/2012","10/25/2012",,4345.00,""

Do you happen to know how to write a regular expression that would allow splunk to parse the first date in the event: "10/4/2012"? I do not know regex very well. I tried "",""," Thanks for your help!

0 Karma
Get Updates on the Splunk Community!

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...