Splunk Search

Transaction with count of successive events

chrispappo
Explorer

Hi,

If I have several events like this:

ID1 name1
ID2 name2
ID3 name1
ID3 name1
ID3 name1
ID4 name3
ID3 name1

I would like to have the number of successive events by ID and by Name. So it will give me something like this:

ID1 name1 1
ID2 name2 1
ID3 name1 3
ID4 name3 1
ID3 name1 1

My problem is with the transaction. It will regroup every identical ID instead of regrouping events that are successive, with the same ID and name.

Can someone help me?
Thanks

Tags (2)
0 Karma
1 Solution

Richfez
SplunkTrust
SplunkTrust

If those have field names of "ID" and "Name", then the simple way would be

... | stats count by ID, Name

Transaction could be useful in other circumstances (perhaps even on this same data), but isn't probably what you need here.

View solution in original post

0 Karma

sundareshr
Legend

I believe you are looking for the eventstats command http://docs.splunk.com/Documentation/Splunk/6.1/SearchReference/eventstats

In your example, something like this may work..`.. | sort idcolname | eventstats count by idcolname | dedup idcolname

If this doesn't give you what you are looking for, try the streamstats command` http://docs.splunk.com/Documentation/Splunk/6.1/SearchReference/streamstats

0 Karma

Richfez
SplunkTrust
SplunkTrust

If those have field names of "ID" and "Name", then the simple way would be

... | stats count by ID, Name

Transaction could be useful in other circumstances (perhaps even on this same data), but isn't probably what you need here.

0 Karma

chrispappo
Explorer

thanks for answering. The problem is with your order the result will be

ID1 name1 1 
ID2 name2 1
ID3 name1 4
ID4 name3 1 

And I want something like

ID1 name1 1 
ID2 name2 1
ID3 name1 3
ID4 name3 1 
ID3 name1 1

as you can see it's different from what I want, i want to count ONLY the following events who own the same ID/NAME!

could you help ?

0 Karma

Richfez
SplunkTrust
SplunkTrust

So you need them bounded by intervening, non-matching events? What I mean by that is that you want to not have a transaction cross another item - so an ID4 splits that ID3/name1 into two chunks, the before one and after one. Right?

If so, I'd recommend using streamstats to split your events by counting number of distinct IDs in a two-item streamstats group. The short version:

... | streamstats window=2 distinct_count(ID) AS splitter| transaction startswith=splitter>1 ID name

The longer version: I answered another question a while back with a similar solution that has explanations, so please refer to this answer here for more information.

Let me know how it goes or if you need help with some tweaking!

chrispappo
Explorer

anyone can help 🙂 ?

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!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...