Splunk Search

How to compare values based on other fields

ckdoan
New Member

Hi all,

So I'm working with log files, and here's a sample entry,


8:09:03 IN: "field1" "user1"

8:09:04 IN: "field2" "user2"
8:09:20 OUT: "field1" "user2"

8:09:25 OUT: "field1" "user1"

8:12:03 IN: "field1" "user1"
8:13:03 OUT: "field1" "user1"
etc...


(the time is inside the event as well)

What I want to do is compare the amount of time that the user is online when and only if field1 is the same. Ie. for the above example, user1 is online for 1 minute and 22 seconds (in total) .

As you can see, sometimes the events do not occur consecutively to each other. (see bold) So based upon the time stamp, I want to see the next time it ends.

Lastly, I want to chart this so that the chart will display when the user is online throughout a day and when they're not online.

Thanks.

Ps, I'm quite new at splunk, please provide a lot of detail.

Tags (2)
0 Karma

sk314
Builder

Have you tried using the transaction command on "field" and "user"? Ref: http://docs.splunk.com/Documentation/Splunk/6.4.1/SearchReference/Transaction

  • The transaction command adds a duration field that you could use.
0 Karma

ckdoan
New Member

Hi, yeah I've already grouped all my data using the transaction command, not quite sure how to proceed from there.

0 Karma

Richfez
SplunkTrust
SplunkTrust

To expand on sk314's answer:

If you use

... my base search ... | transaction maxpause=30m maxspan=1h field, user

As your search, when run it should create a field called duration that is the length of each transaction. It's just there. If you'd like, you could take the above and add to the end of it | table field, user, duration to get a shorter, easier to read table.

Alternatively, if you want to see the duration in other formats check out the fieldformat function. You could do something like

... my base search ... | transaction ... | fieldformat duration=fieldformat(duration, "duration")

Other possibilities exist. What is it you are trying to do that we haven't answered?

0 Karma

ckdoan
New Member

Well it's more like, I'm not able to properly group the data into a transaction. For example, each transaction should ideally contain only one instance of the time that the user logins and logouts to get that duration (2 events) and then repeat for the rest with the same field1. Right now, my transaction groups all the INs together and then separated by field1 which is not what I want.

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!

Event Series: Telemetry Pipeline Management

Balancing Scale and Spend: Gaining Control Over High-Volume Metrics in Splunk Observability Cloud As ...

Kick the Tires Before You Commit: A Hands-On Tour of the Splunk Observability Cloud ...

Evaluating an enterprise observability platform usually goes like this: fill out a form, get a free trial with ...

Deep insights, no barriers: Splunk Observability Cloud Free Edition

As software delivery cycles continue to accelerate, observability shouldn’t be a luxury — it should be a ...