<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to graph a unique count of users logged on by hour from login and log out information in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182473#M52584</link>
    <description>&lt;P&gt;The &lt;CODE&gt;concurrency&lt;/CODE&gt; command can be helpful here.  If given a start time and duration field (defaults:  _time, duration) it calculates overlaps.  Assuming users can't have more than one session active at a time, this would give you concurrent users over time:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats count earliest(_time) as _time latest(_time) as logoff first(user) as user by  number 
    | eval duration=logoff-_time 
    | eval duration=if(count==1, now()-_time, duration)
    | concurrency output=concurrent_users 
    | timechart avg(concurrent_users)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above does the following:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;in this case, we can use &lt;CODE&gt;stats&lt;/CODE&gt; like a cheap transaction, assuming session number is unique for each login session.&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;We calculate the session duration based on earliest/latest times&lt;/LI&gt;
&lt;LI&gt;To accommodate users currently logged in, we can further define duration to be &lt;CODE&gt;now()-_time&lt;/CODE&gt; if there is only one event.  (A login but no logoff)&lt;/LI&gt;
&lt;LI&gt;Now we use &lt;CODE&gt;concurrency&lt;/CODE&gt; to generate a concurrent sessions metric.&lt;/LI&gt;
&lt;LI&gt;Finally, timechart the &lt;CODE&gt;concurrent_users&lt;/CODE&gt; field we created in the previous step.&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Fri, 24 Oct 2014 15:32:41 GMT</pubDate>
    <dc:creator>emiller42</dc:creator>
    <dc:date>2014-10-24T15:32:41Z</dc:date>
    <item>
      <title>How to graph a unique count of users logged on by hour from login and log out information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182471#M52582</link>
      <description>&lt;P&gt;I have a set of log entries that looks like the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2014/10/20 12:23:30 [28761-9098]: Session 9098 (username@ipaddress) started
2014/10/20 14:33:33 [28761-9098]: Session 9098 ended
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to be able to create a graph that shows how many people are logged in for a particular hour. Currently, I'm able to create a graph that shows the hour in which people have logged on. In the above time example, my current graph would show that the user logged on during the 12:00 hour, but would not show anything for the 13:00 or 14:00 hour. &lt;/P&gt;

&lt;P&gt;Here's what my code looks like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... "Login succeeded for user" | rex field=_raw ".*Login succeeded for user: (?&amp;lt;user&amp;gt;.*)"    | stats dc(user) as "unique logins" by date_hour
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm familiar with the transaction command and am able to get the duration for which people have logged on with the below code, but I don't know how to apply that to a graph to show a unique count of people over each hour&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... "Session" | rex field=_raw "Session  (?&amp;lt;number&amp;gt;&amp;gt;&amp;gt;doublebackslash&amp;gt;w+) (&amp;lt;doublebackslash&amp;gt;((?&amp;lt;user&amp;gt;&amp;lt;doublebackslash&amp;gt;w+)@|)" | transaction number startswith "started" endswith "ended" | where duration &amp;gt; 1 |
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Does anyone have any advice? Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Oct 2014 12:51:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182471#M52582</guid>
      <dc:creator>Splunkster45</dc:creator>
      <dc:date>2014-10-24T12:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to graph a unique count of users logged on by hour from login and log out information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182472#M52583</link>
      <description>&lt;P&gt;Actually you don't need to pair transactions or sessions if you just want the total number in a given time period:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "Session (?&amp;lt;s_sid&amp;gt;\d+) \(\@\) started" | rex "Session (?&amp;lt;e_sid&amp;gt;\d+) ended"
    | timechart span=1h count(s_sid) AS logins count(e_sid) AS logouts
    | eval net_logins=logins-logouts
    | streamstats global=t current=t sum(net_logins) as cumulative_net_users
    | timechart span=1h sum(cumulative_net_users)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Oct 2014 15:20:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182472#M52583</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2014-10-24T15:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to graph a unique count of users logged on by hour from login and log out information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182473#M52584</link>
      <description>&lt;P&gt;The &lt;CODE&gt;concurrency&lt;/CODE&gt; command can be helpful here.  If given a start time and duration field (defaults:  _time, duration) it calculates overlaps.  Assuming users can't have more than one session active at a time, this would give you concurrent users over time:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats count earliest(_time) as _time latest(_time) as logoff first(user) as user by  number 
    | eval duration=logoff-_time 
    | eval duration=if(count==1, now()-_time, duration)
    | concurrency output=concurrent_users 
    | timechart avg(concurrent_users)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above does the following:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;in this case, we can use &lt;CODE&gt;stats&lt;/CODE&gt; like a cheap transaction, assuming session number is unique for each login session.&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;We calculate the session duration based on earliest/latest times&lt;/LI&gt;
&lt;LI&gt;To accommodate users currently logged in, we can further define duration to be &lt;CODE&gt;now()-_time&lt;/CODE&gt; if there is only one event.  (A login but no logoff)&lt;/LI&gt;
&lt;LI&gt;Now we use &lt;CODE&gt;concurrency&lt;/CODE&gt; to generate a concurrent sessions metric.&lt;/LI&gt;
&lt;LI&gt;Finally, timechart the &lt;CODE&gt;concurrent_users&lt;/CODE&gt; field we created in the previous step.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Fri, 24 Oct 2014 15:32:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182473#M52584</guid>
      <dc:creator>emiller42</dc:creator>
      <dc:date>2014-10-24T15:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to graph a unique count of users logged on by hour from login and log out information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182474#M52585</link>
      <description>&lt;P&gt;The session number is unique for each login session.&lt;BR /&gt;
I implemented this (after inserting duration=duration) into the concurrency segment and got a cool graph.&lt;/P&gt;

&lt;P&gt;I thought that this was really nifty, however, like you said, this is a graph of the total number of users that have logged in. When I displayed the graph for the past week, I got back a (strictly) increasing function. It doesn't appear that the graph took into account when people logged off.  I'm looking for the number of concurrent users per hour. If there was someway to subtract when people logged off, then I think that this would be close. Also, people can and will have multiple open sessions at once and so if one person is logged in twice in at 10, I'll need to only record the value once. However, I've learning to use concurrency and so this I've been able to take away some things &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Oct 2014 18:27:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182474#M52585</guid>
      <dc:creator>Splunkster45</dc:creator>
      <dc:date>2014-10-27T18:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to graph a unique count of users logged on by hour from login and log out information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182475#M52586</link>
      <description>&lt;P&gt;This was helpful! But there are a few things that I need to iron out.&lt;/P&gt;

&lt;P&gt;I modified my opening post to show what the logs exactly look like. Before, I think I put a wildcard (or something similar) in place of the username and ipaddress as it wasn't important, but that messed things up.  One issue I'm having with this is that if I go back 48 hours, then I get logs that ended, but never started (as their start date was over 48 hours ago). If there are three logs that fit this scenario, then my graph down by 3. &lt;/P&gt;

&lt;P&gt;I also have to figure out how to make the logins unique.  If one person is logged in twice in an hour, then I don't want to count him twice. I can kind of map this out in my head (with a bash script) and it doesn't look like this will be simple.  I wouldn't mind being wrong though.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Oct 2014 18:56:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182475#M52586</guid>
      <dc:creator>Splunkster45</dc:creator>
      <dc:date>2014-10-27T18:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to graph a unique count of users logged on by hour from login and log out information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182476#M52587</link>
      <description>&lt;P&gt;I've got a work around for the first issue that I just listed - logs that have ended, but have not started (during the specified time frame). If I make a clever use of the time frame to go back to a point in time where no one is on, then I won't have this issue. E.g. snap to midnight of a particular day. However, I've run our program over night and so this won't take care of all instances, but its a start.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Oct 2014 19:03:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182476#M52587</guid>
      <dc:creator>Splunkster45</dc:creator>
      <dc:date>2014-10-27T19:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to graph a unique count of users logged on by hour from login and log out information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182477#M52588</link>
      <description>&lt;P&gt;Concurrency should take care of this.  It takes the start time and the duration for each event, and then calculates overlaps.  This means that as sessions end, they get dropped out of the concurrency total.  The only thing I can think of is the duration is getting calculated at a different scale than the concurrency command expects.  (IE Duration is in milliseconds but concurrency assumes seconds)  This would make the sessions seem to go on longer than expected and appear to just keep growing over time.  &lt;/P&gt;</description>
      <pubDate>Mon, 27 Oct 2014 19:07:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182477#M52588</guid>
      <dc:creator>emiller42</dc:creator>
      <dc:date>2014-10-27T19:07:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to graph a unique count of users logged on by hour from login and log out information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182478#M52589</link>
      <description>&lt;P&gt;I think that one reason this may be the case is that _time is in mm/dd/yyyy format while logoff is in epoch time. This messes with the duration command that tries to subtract the two.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Oct 2014 18:02:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182478#M52589</guid>
      <dc:creator>Splunkster45</dc:creator>
      <dc:date>2014-10-29T18:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to graph a unique count of users logged on by hour from login and log out information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182479#M52590</link>
      <description>&lt;P&gt;That shouldn't be the case  _time is actually stored in epoch time.  You can test this with the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* | head 1 | eval test=1414675868 | eval now=now() | eval diff=now-test| table now test diff | fieldformat now_frmt=strftime(now, "%c") | fieldformat test_frmt=strftime(test, "%c")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you subtract two epoch times in splunk, the difference is in seconds, which is the scale that concurrency expects.&lt;/P&gt;

&lt;P&gt;For me the output of that is:&lt;BR /&gt;
now:  1414676209&lt;BR /&gt;
test:   1414675868&lt;BR /&gt;
diff:  341&lt;BR /&gt;
now_frmt:  Thu Oct 30 08:36:49 2014&lt;BR /&gt;
test_frmt:   Thu Oct 30 08:31:08 2014&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:03:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182479#M52590</guid>
      <dc:creator>emiller42</dc:creator>
      <dc:date>2020-09-28T18:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to graph a unique count of users logged on by hour from login and log out information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182480#M52591</link>
      <description>&lt;P&gt;I've done some further looking into this and found a thread that accomplishes exactly what I'm trying to accomplish! &lt;A href="http://answers.splunk.com/answers/69213/calculate-concurrency-of-transactions.html" target="_blank"&gt;link&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I've have two questions over this. First of all, I can't seem to get past the regex part. Here's my version of the code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  "Session" | rex field=_raw "Session (?&amp;lt;id&amp;gt;\\w+) (\\((?&amp;lt;user&amp;gt;\\w+)@|)" | eval mytime=_time | transaction id startswith "started" endswith "ended" | where duration &amp;gt; 1
| eval transactionid=id._time 
| stats min(mytime) AS start max(mytime) AS stop values(id) AS id values(duration) AS duration by transactionid
| eval mytimeconcat="1_".start." -1_".stop
| eval mytimemv=split(mytimeconcat," ") 
| mvexpand mytimemv  
| rex field=mytimemv "(?(1|-1))_(?&amp;lt;_time&amp;gt;d+)" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The error message that I get when I run this is as follows:  "Error in 'rex' command: Encountered the following error while compiling the regex '(?(1|-1))_(?&amp;lt;_time&amp;gt;d+)': Regex: malformed number or name after (?("&lt;/P&gt;

&lt;P&gt;I think that I'm getting this error message because I already have a rex command in the system, but I'm not sure. Secondly, in the command &lt;CODE&gt;| table _time id counter&lt;/CODE&gt; where does counter come from? It seems that it just appears out of nowhere&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:03:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182480#M52591</guid>
      <dc:creator>Splunkster45</dc:creator>
      <dc:date>2020-09-28T18:03:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to graph a unique count of users logged on by hour from login and log out information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182481#M52592</link>
      <description>&lt;P&gt;your second rex looks off.  Can you explain what it's trying to do?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"(?(1|-1))_(?&amp;lt;_time&amp;gt;d+)" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That first ? makes me think you're trying to extract either 1 or -1 as a field, but you're not giving it a name.   Then the &lt;CODE&gt;(1|-1)&lt;/CODE&gt; doesn't do what you think,  (It's saying "a 1 or a -, followed by a 1")&lt;/P&gt;

&lt;P&gt;If that's your intent, the regex should be:  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"(?&amp;lt;field_name&amp;gt;1|(-1))_(?&amp;lt;_time&amp;gt;d+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 Oct 2014 21:29:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-graph-a-unique-count-of-users-logged-on-by-hour-from/m-p/182481#M52592</guid>
      <dc:creator>emiller42</dc:creator>
      <dc:date>2014-10-31T21:29:49Z</dc:date>
    </item>
  </channel>
</rss>

