<?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: java verbosegc log files (long pause before log line flushes) in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/java-verbosegc-log-files-long-pause-before-log-line-flushes/m-p/98687#M20639</link>
    <description>&lt;P&gt;The &lt;CODE&gt;time_before_close&lt;/CODE&gt; setting in &lt;CODE&gt;inputs.conf&lt;/CODE&gt; is (short of reformatting the file entirely like tpederson suggests) is really you best/only option.  This has worked for many people before - but you will need to set &lt;CODE&gt;time_before_close&lt;/CODE&gt; to a value greater than your longest GC.  (Which I know could be minutes worst-case, this really sucks)&lt;/P&gt;</description>
    <pubDate>Tue, 08 Oct 2013 21:43:55 GMT</pubDate>
    <dc:creator>dwaddle</dc:creator>
    <dc:date>2013-10-08T21:43:55Z</dc:date>
    <item>
      <title>java verbosegc log files (long pause before log line flushes)</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/java-verbosegc-log-files-long-pause-before-log-line-flushes/m-p/98682#M20634</link>
      <description>&lt;P&gt;We are trying to forward verbose Java garbage collection log files (java version "1.6.0_34") using Java's "&lt;CODE&gt;-XX:+PrintGCDetails&lt;/CODE&gt;" option to get detailed information.&lt;/P&gt;

&lt;P&gt;There is a bug in Java where the last line of the log does not get flushed until the next garbage collection occurs.  So a log line that should be one event in Splunk gets split into two:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://dl.dropbox.com/u/58110344/one_line_two_events.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;The top event is the rest of the line from the bottom event and comes in an hour later because that's when the next GC happened (there are newer events not in the screenshot).&lt;/P&gt;

&lt;P&gt;The gc log file problem is described really well &lt;A href="http://stackoverflow.com/questions/12935329/jvm-verbosegc-log-file-issue"&gt;here&lt;/A&gt;.&lt;/P&gt;

&lt;P&gt;Has anyone else encountered this or similar issues and found a good solution or work around?&lt;/P&gt;

&lt;P&gt;I have tried to craft custom &lt;CODE&gt;LINE_BREAKER&lt;/CODE&gt; property logic to no avail.  I have tried playing around with the &lt;CODE&gt;time_before_close&lt;/CODE&gt; property with no luck.  I'm not sure &lt;CODE&gt;time_before_close&lt;/CODE&gt; is even a fesible solution since some of our Java apps have long periods of time between garbage collections.&lt;/P&gt;

&lt;P&gt;Using Splunk 5.0.1.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2013 15:27:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/java-verbosegc-log-files-long-pause-before-log-line-flushes/m-p/98682#M20634</guid>
      <dc:creator>pmacdougall</dc:creator>
      <dc:date>2013-01-24T15:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: java verbosegc log files (long pause before log line flushes)</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/java-verbosegc-log-files-long-pause-before-log-line-flushes/m-p/98683#M20635</link>
      <description>&lt;P&gt;Rather than monitoring JVM GC logs , you might want to consider using &lt;A href="http://splunk-base.splunk.com/apps/25505/splunk-for-jmx"&gt;Splunk for JMX&lt;/A&gt; to poll for Garbage Collection metrics.The Splunk for JMX app comes with configuration examples for GC MBean attributes and also some example dashboards for visualizing GC metrics. &lt;/P&gt;</description>
      <pubDate>Sun, 27 Jan 2013 11:02:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/java-verbosegc-log-files-long-pause-before-log-line-flushes/m-p/98683#M20635</guid>
      <dc:creator>Damien_Dallimor</dc:creator>
      <dc:date>2013-01-27T11:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: java verbosegc log files (long pause before log line flushes)</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/java-verbosegc-log-files-long-pause-before-log-line-flushes/m-p/98684#M20636</link>
      <description>&lt;P&gt;I'm running in to the same problem but didn't know why it was happening until reading your post. Have you found a workaround?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2013 19:02:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/java-verbosegc-log-files-long-pause-before-log-line-flushes/m-p/98684#M20636</guid>
      <dc:creator>cramasta</dc:creator>
      <dc:date>2013-06-21T19:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: java verbosegc log files (long pause before log line flushes)</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/java-verbosegc-log-files-long-pause-before-log-line-flushes/m-p/98685#M20637</link>
      <description>&lt;P&gt;No we never did find a work around for this.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2013 20:28:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/java-verbosegc-log-files-long-pause-before-log-line-flushes/m-p/98685#M20637</guid>
      <dc:creator>pmacdougall</dc:creator>
      <dc:date>2013-06-21T20:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: java verbosegc log files (long pause before log line flushes)</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/java-verbosegc-log-files-long-pause-before-log-line-flushes/m-p/98686#M20638</link>
      <description>&lt;P&gt;I have a solution to this that may not be pretty, but it seems to be working for us.  It looks like your JVM outputs the timestamps, so our solution is a little different, but can work for both with some modification.&lt;/P&gt;

&lt;P&gt;Our JVM wouldn't output timestamps for love nor money and Splunk didn't like the fact that Java would output half a line at the start of GC then output the rest later when it felt like it.&lt;/P&gt;

&lt;P&gt;So, I found a python script that takes the modified date and calculates the timestamp from the seconds in the log file.  I paired that with a bash script that goes through our JVMs and lumps all the files together, ignoring any unfinished lines that don't have a linebreak.&lt;/P&gt;

&lt;P&gt;Original python script is at the bottom of this &lt;A href="http://176.34.122.30/blog/2010/05/26/human-readable-jvm-gc-timestamps/"&gt;page&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Here's my modified version. We write the date to the file name every time the JVM starts to prevent the modified date being changed.  So, my version uses the string from the end of the file name.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/usr/bin/env python

import sys, os, datetime, time

# true if string is a positive float
def validSeconds(str_sec):
    try:
        return 0 &amp;lt; float(str_sec)
    except ValueError:
        return False

#make sure you can get a datetime from the filename
def getDateTime(str_datetime):
        try:
                return datetime.datetime(*(time.strptime(str_datetime, "%Y%m%d%H%M%S")[0:6]))
        except ValueError:
                sys.exit(1)

# show usage
if len(sys.argv) &amp;lt; 2:
    print "Usage: %s &amp;lt;gc.log&amp;gt;" % (sys.argv[0])
    sys.exit(1)

file_str = sys.argv[1]

#print file_str[-14:]

lastmod_date = getDateTime(file_str[-14:])

#print lastmod_date

#sys.exit()

file = open(file_str, 'r')
lines = file.readlines()
file.close()

# get last elapsed time
for line in reversed(lines):
    parts = line.split(':')
    if validSeconds(parts[0]):
        break

# calculate start time
start_date = lastmod_date - datetime.timedelta(seconds=float(parts[0]))

# print file prepending human readable time where appropiate
for line in lines:
    if not "\n" in line:
        break
    parts = line.split(':')
    if not validSeconds(parts[0]):
        print line.rstrip()
        continue
    line_date = start_date + datetime.timedelta(seconds=float(parts[0]))
    print "%s: %s" % (line_date.isoformat(), line.rstrip())
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, I paired this with a bash script that goes into each JVM dir, finds all the java.log files and feeds them to the python script.  The output from the python script is conglomerated into a tmp file, which overwrites the last file.  I'm not 100% sure, but I think this is the best way to avoid duplicate entries.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/bin/bash

for instance in `find /usr/JVMs/ -maxdepth 1 -type d -name "jboss.*" 2&amp;gt; /dev/null`; do
        #echo "I: ${instance}"
        for file in `ls ${instance}/server/ourserver/log/java.log.* 2&amp;gt; /dev/null`; do
                LINECOUNT=$(cat ${file} | wc -l)
                #echo "${LINECOUNT}"
                if [[ "${LINECOUNT}" &amp;gt; "0" ]]; then
                        /usr/local/bin/convertTimeStamp.py ${file} &amp;gt;&amp;gt; ${instance}/server/ourserver/log/splunkGcc.tmp
                        mv ${instance}/server/ourserver/log/splunkGcc.tmp ${instance}/server/ourserver/log/splunkGcc.log 2&amp;gt; /dev/null
                fi
                #echo "F: ${file}"
        done
done
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This bash script is in cron, and runs every minute on each of our servers.  Splunk is pointed to the one amalgamated file.  Hope this helps, I know our devs were chomping at the bit to get some charts from this data.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2013 21:31:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/java-verbosegc-log-files-long-pause-before-log-line-flushes/m-p/98686#M20638</guid>
      <dc:creator>tpederson</dc:creator>
      <dc:date>2013-10-08T21:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: java verbosegc log files (long pause before log line flushes)</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/java-verbosegc-log-files-long-pause-before-log-line-flushes/m-p/98687#M20639</link>
      <description>&lt;P&gt;The &lt;CODE&gt;time_before_close&lt;/CODE&gt; setting in &lt;CODE&gt;inputs.conf&lt;/CODE&gt; is (short of reformatting the file entirely like tpederson suggests) is really you best/only option.  This has worked for many people before - but you will need to set &lt;CODE&gt;time_before_close&lt;/CODE&gt; to a value greater than your longest GC.  (Which I know could be minutes worst-case, this really sucks)&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2013 21:43:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/java-verbosegc-log-files-long-pause-before-log-line-flushes/m-p/98687#M20639</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2013-10-08T21:43:55Z</dc:date>
    </item>
    <item>
      <title>Re: java verbosegc log files (long pause before log line flushes)</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/java-verbosegc-log-files-long-pause-before-log-line-flushes/m-p/98688#M20640</link>
      <description>&lt;P&gt;What I did was to reassemble the two halves of the GC event using transactions.&lt;/P&gt;

&lt;P&gt;Here's an example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=PIA_stdout ("GC" OR "secs") 
| transaction endswith=secs keeporphans=true 
| search date_hour&amp;gt;7 date_hour&amp;lt;18 
| rex field=source "/webserv/(?&amp;lt;environment&amp;gt;[^/]+)/servers/" 
| rex field=_raw "(?&amp;lt;starting_occupancy&amp;gt;[0-9]+)K-&amp;gt;(?&amp;lt;ending_occupancy&amp;gt;[0-9]+)K\((?&amp;lt;heap_size&amp;gt;[0-9]+)K\), (?&amp;lt;pause_time&amp;gt;[0-9.]+) secs\]"  
| stats max(pause_time) AS "Max Pause" BY environment
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In this case, I didn't care about "after hours" GCs, but I couldn't filter on date_hour in the first search because the second half of the events (the part with the "secs]" at the end) didn't get date_hour fields. I had to assemble the two halves into a transaction before I could do a date_hour filter.&lt;/P&gt;

&lt;P&gt;Also, when the GC event took less that apx 3 seconds, it didn't get split. So, I need &lt;STRONG&gt;keeporphans=true&lt;/STRONG&gt; to keep the non-jacked-up GC events.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:55:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/java-verbosegc-log-files-long-pause-before-log-line-flushes/m-p/98688#M20640</guid>
      <dc:creator>gpullis</dc:creator>
      <dc:date>2020-09-29T23:55:28Z</dc:date>
    </item>
  </channel>
</rss>

