<?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: MySQL slow query log parsing in All Apps and Add-ons</title>
    <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/MySQL-slow-query-log-parsing/m-p/67874#M4196</link>
    <description>&lt;P&gt;Very helpful, works great.&lt;/P&gt;</description>
    <pubDate>Sun, 22 Jan 2012 01:41:48 GMT</pubDate>
    <dc:creator>redventures</dc:creator>
    <dc:date>2012-01-22T01:41:48Z</dc:date>
    <item>
      <title>MySQL slow query log parsing</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/MySQL-slow-query-log-parsing/m-p/67870#M4192</link>
      <description>&lt;P&gt;I have a mysql slow.log being piped into splunk and works great.  Splunk also seems to do a good job of separating the queries out.  The only issue I have is I want to have splunk parse out the fields within the comments containing query time and similar.  I can't seem to readily get this to work.  See sample below:&lt;/P&gt;

&lt;P&gt;/* /usr/share/www/redventures.com/data/reddash/dashboard.html &lt;EM&gt;/
/&lt;/EM&gt; DBHost: rv-atl-db06 via TCP/IP &lt;EM&gt;/
/&lt;/EM&gt; Server: rv-atl-web209 */;&lt;/P&gt;

&lt;H1&gt;Time: 110325  2:58:25&lt;/H1&gt;

&lt;H1&gt;User@Host: intranet[intranet] @ rv-atl-web209-db [10.24.24.209]&lt;/H1&gt;

&lt;H1&gt;Query_time: 4  Lock_time: 0  Rows_sent: 101  Rows_examined: 712668&lt;/H1&gt;

&lt;P&gt;SELECT
                    CC.AgentID,
                    COUNT(DISTINCT O.OrderID) AS OrdersStarted,
                    COUNT(DISTINCT IF(O.CreditApproved = 'notchecked', 
.....&lt;/P&gt;

&lt;P&gt;I want the Query_time, Lock_time and so forth to be added to the search as a name/value pair so I can run additional queries.&lt;/P&gt;

&lt;P&gt;Ideas?&lt;/P&gt;</description>
      <pubDate>Sat, 26 Mar 2011 01:18:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/MySQL-slow-query-log-parsing/m-p/67870#M4192</guid>
      <dc:creator>redventures</dc:creator>
      <dc:date>2011-03-26T01:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: MySQL slow query log parsing</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/MySQL-slow-query-log-parsing/m-p/67871#M4193</link>
      <description>&lt;P&gt;I had to figure out MySQL slow query logs today. These configs should help you out. They tell Splunk to only break on a line starting with &lt;CODE&gt;# Time: 110408 12:34:56&lt;/CODE&gt;, get the time format right, and extract some other fields.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;--inputs.conf--
[monitor:///path/to/file]
# input settings, send to the splunk that is collecting
sourcetype = mysql:slow

--props.conf--
[mysql:slow]
# index-time settings, send to the indexer
SHOULD_LINEMERGE = true
TIME_FORMAT = Time: %y%m%d %k:%M:%S
BREAK_ONLY_BEFORE = #\sTime:\s\d{6}\s[\s\d]\d:\d\d:\d\d
MAX_EVENTS = 512
# search-time settings, sent to search head
REPORT-query_for_mysql_slow = query_for_mysql_slow
REPORT-user_src_for_mysql_slow = user_src_for_mysql_slow
REPORT-times_rows_for_mysql_slow = times_rows_for_mysql_slow

--transforms.conf--
# search-time settings, sent to search head
[query_for_mysql_slow]
REGEX = Rows_examined:\s\d+[\r\n\s]+([\s\S]+)
FORMAT = query::$1

[user_src_for_mysql_slow]
REGEX = User@Host:\s([^[]+)\[([^]]+)\]\s?@\s+?\[([^]]+)\]
FORMAT = user::$1 src_user::$2 src::$3 src_bestmatch::$3

[times_rows_for_mysql_slow]
REGEX = Query_time:\s([\d.]+)\s++Lock_time:\s([\d.]+)\s++Rows_sent:\s(\d+)\s++Rows_examined:\s(\d+)
FORMAT = query_time::$1 lock_time::$2 rows_sent::$3 rows_examined::$4
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Apr 2011 10:23:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/MySQL-slow-query-log-parsing/m-p/67871#M4193</guid>
      <dc:creator>Jason</dc:creator>
      <dc:date>2011-04-09T10:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: MySQL slow query log parsing</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/MySQL-slow-query-log-parsing/m-p/67872#M4194</link>
      <description>&lt;P&gt;Jason, this was really helpful, thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2011 22:32:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/MySQL-slow-query-log-parsing/m-p/67872#M4194</guid>
      <dc:creator>tpsplunk</dc:creator>
      <dc:date>2011-10-25T22:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: MySQL slow query log parsing</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/MySQL-slow-query-log-parsing/m-p/67873#M4195</link>
      <description>&lt;P&gt;Jason- i suggest the following update to remove the "SET Timestamp" portion out of the query field extraction (with it in it makes nearly every query unique because the timestamp is always changing):&lt;/P&gt;

&lt;P&gt;[query_for_mysql_slow]&lt;BR /&gt;
REGEX = Rows_examined:\s\d+[\r\n\s]+SET\s+timestamp=\d+;([\s\S]+)&lt;BR /&gt;
FORMAT = query::$1&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 10:01:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/MySQL-slow-query-log-parsing/m-p/67873#M4195</guid>
      <dc:creator>tpsplunk</dc:creator>
      <dc:date>2020-09-28T10:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: MySQL slow query log parsing</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/MySQL-slow-query-log-parsing/m-p/67874#M4196</link>
      <description>&lt;P&gt;Very helpful, works great.&lt;/P&gt;</description>
      <pubDate>Sun, 22 Jan 2012 01:41:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/MySQL-slow-query-log-parsing/m-p/67874#M4196</guid>
      <dc:creator>redventures</dc:creator>
      <dc:date>2012-01-22T01:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: MySQL slow query log parsing</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/MySQL-slow-query-log-parsing/m-p/67875#M4197</link>
      <description>&lt;P&gt;Jason's answer doesn't handle the fact that not every mysqlslow.log event has the "Time: " line -- it appears that mysql only logs that line when the time has actually changed since the last event(..?)&lt;/P&gt;

&lt;P&gt;This set of configs seems to be working robustly for me:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;inputs.conf

[monitor:///path/to/file]
sourcetype = mysqlslow


splunk/etc/system/local/props.conf

[mysqlslow]
# Use LINE_BREAKER to segment events.  An event may start with either "Time:"" or "User@Host:".
# Look for a semicolon (termination of previous event) followed by one of those items.
# However, the very first entry won't have a ";" before it. Instead it is preceeded by "Argument".
LINE_BREAKER = (?:;|Argument)(\n)(?:\# Time: |\# User@Host: )
SHOULD_LINEMERGE = false
TRUNCATE = 0


splunk/etc/apps/search/local/props.conf

[mysqlslow]
EXTRACT-mysqlslow-user-line = User@Host: (?&amp;lt;user&amp;gt;[^\s@]+) @ (?&amp;lt;query_host&amp;gt;\S+) \[(?&amp;lt;query_ip&amp;gt;[\d.]+)\]
EXTRACT-mysqlslow-query-time-line = Query_time: (?&amp;lt;query_time&amp;gt;\d+)  Lock_time: (?&amp;lt;lock_time&amp;gt;\d+)  Rows_sent: (?&amp;lt;rows_sent&amp;gt;\d+)  Rows_examined: (?&amp;lt;rows_examined&amp;gt;\d+)
EXTRACT-mysqlslow-query-line = \n(?&amp;lt;query&amp;gt;[^#].*)$
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Jun 2012 20:19:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/MySQL-slow-query-log-parsing/m-p/67875#M4197</guid>
      <dc:creator>Jordan_Brough</dc:creator>
      <dc:date>2012-06-06T20:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: MySQL slow query log parsing</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/MySQL-slow-query-log-parsing/m-p/67876#M4198</link>
      <description>&lt;P&gt;Jordan's answer is not exhaustive either.&lt;/P&gt;

&lt;PRE&gt;
SET timestamp=1376020745;
# administrator command: Init DB;
# User@Host: xxxx[xxxx] @ web-xxxx.private [10.x.x.x]
# Thread_id: 8343655  Schema: xxxx  QC_hit: No
# Query_time: 3.179482  Lock_time: 0.000000  Rows_sent: 1  Rows_examined: 1
&lt;/PRE&gt;

&lt;P&gt;I thought it might be doable by looking for a line that starts with '#' which follows a line which does not start with '#', but there can be comments inside a query.&lt;/P&gt;

&lt;P&gt;It's very much an edge case, but a query that is followed by a comment is likely to also fail, as the semi-colon is not last.&lt;/P&gt;

&lt;P&gt;I wonder if mysql has any special  handling for comments like '# Time: foo' that are passed within queries.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Aug 2013 03:19:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/MySQL-slow-query-log-parsing/m-p/67876#M4198</guid>
      <dc:creator>mc0e</dc:creator>
      <dc:date>2013-08-30T03:19:22Z</dc:date>
    </item>
  </channel>
</rss>

