{"id":3362,"date":"2013-11-30T12:26:38","date_gmt":"2013-11-30T17:26:38","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=3362"},"modified":"2013-11-30T12:27:38","modified_gmt":"2013-11-30T17:27:38","slug":"getting-count-of-sessions-created-by-minute","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2013\/11\/30\/getting-count-of-sessions-created-by-minute\/","title":{"rendered":"Getting count of sessions created by minute"},"content":{"rendered":"<p>In the wake of a flood of 24,000 application server sessions created per minute at the start of Black Friday week, we wanted to share how we calculated how many sessions were created per minute.  This can be obtained from a jmx-console jboss.web call to &#8220;host=localhost,path=\/,type=Manager&#8221; and the sessionCounter attribute, but it is a live call, so we didn&#8217;t have the information historically.<\/p>\n<p>Thankfully, in the access log we log the JSESSIONID created by JBOSS to uniquely identify a session.  The python script below simply counts the number of unique JSESSIONID&#8217;s by minute.  In other words, if JSESSIONID 123ABC first occurs at 08:44, it will be added to the counter for sessions created at 08:44.  No future occurrences in the log will be considered for JSESSIONID 123ABC.<\/p>\n<p>The weakness to this approach is that it does not account for sessions created the previous day, such as 11:57PM, that then show up at 12:00AM in the newly rolled over log.  As such, it isn&#8217;t 100% accurate, but it is very close.<\/p>\n<p>Depending on your access log format, you may have to change some of the index numbers below.  For example, we log the JSESSIONID in the tenth column of the access log.<\/p>\n<p>Hopefully its useful.<\/p>\n<pre lang=\"python\">\r\n\"\"\"\r\n-----------------------------------------------------------------------------------\r\nAuthor:         Steve Howard\r\nDate:           November 14, 2013\r\nPurpose:        Provide count of sessions created in the access log.  It only\r\n                  logs the first occurrence for a given JSESSIONID.\r\n-----------------------------------------------------------------------------------\r\n\"\"\"\r\n\r\nimport sys\r\nif len(sys.argv) == 2:\r\n  f = open(sys.argv[1])\r\nelse:\r\n  f = sys.stdin\r\nd = dict() #fast to search by key, or JSESSIONID in our case\r\ntim = dict()\r\n\r\n#read each line in the provided file...\r\nfor l in f:\r\n  #...then split it into an array...\r\n  l2 = l.split()\r\n  #...and if it isn't an akamai performance request or a load balancer request, and it is\r\n  #   in the new log format with JSESSIONID...\r\n  if l.find(\"sure_route\") == -1 and l2[0] != \"-\" and len(l2) == 13:\r\n    #...if we don't already have this JSESSIONID in our dict, i.e., the first time we have seen it...\r\n    if l2[9] not in d:\r\n      #...then add JSESSIONID without any real value for the value we only need the key\r\n      d[l2[9]] = 0\r\n      t=l2[2].split(\":\")\r\n      #...and finally print the time of the first request for this JSESSIONID, as that is when the session\r\n      #...was created.\r\n      if t[1] + \":\" + t[2] in tim:\r\n        tim[t[1] + \":\" + t[2]] = tim[t[1] + \":\" + t[2]] + 1\r\n      else:\r\n        tim[t[1] + \":\" + t[2]] = 1\r\nfor j in sorted(tim.items()):\r\n  print j[0],j[1]\r\n<\/pre>\n<p>This will generate output similar to what is below&#8230;<\/p>\n<pre lang=\"text\">\r\n23:40 354\r\n23:41 329\r\n23:42 356\r\n23:43 369\r\n23:44 338\r\n23:45 384\r\n23:46 358\r\n23:47 320\r\n23:48 334\r\n23:49 365\r\n23:50 344\r\n23:51 254\r\n23:52 313\r\n23:53 346\r\n23:54 321\r\n23:55 329\r\n23:56 349\r\n23:57 369\r\n23:58 326\r\n23:59 381\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In the wake of a flood of 24,000 application server sessions created per minute at the start of Black Friday week, we wanted to share how we calculated how many sessions were created per minute. This can be obtained from&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2013\/11\/30\/getting-count-of-sessions-created-by-minute\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[48,24,49,26],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/3362"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=3362"}],"version-history":[{"count":9,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/3362\/revisions"}],"predecessor-version":[{"id":3371,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/3362\/revisions\/3371"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=3362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=3362"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=3362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}