{"action":"created","comment":{"url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/pulls/comments/79233828","id":79233828,"diff_hunk":"@@ -0,0 +1,230 @@\n+#!/usr/bin/env ruby\n+\n+require 'gelf'\n+require 'digest/crc64'\n+require 'optparse'\n+\n+class QueryParser\n+  def initialize\n+    @buffer = \"\"\n+    @parsed = []\n+    @query = SlowQuery.new\n+  end\n+\n+  def parse_line(line)\n+    @query.parse_line(line)\n+    if @query.done?\n+      @parsed << @query\n+      @query = SlowQuery.new\n+    end\n+  end\n+\n+  def pop_finished_query\n+    @parsed.pop\n+  end\n+end\n+\n+class SlowQuery\n+  SPECIAL_PREFIXES = {\n+    query_string: \"_\",\n+    request_time: \"_\",\n+    host: \"_\",\n+    timestamp: \"\",\n+  }\n+  PATTERNS = {\n+    header:   /(^Tcp port:|^Time\\s+Id|started with:$)/,\n+    skip:     /^(# Time: \\d+|use \\w+;)/,\n+    userhost: /^# User@Host: (\\S+)\\[\\S+\\] @\\s+\\[(\\S+)\\]/,\n+    thread:   /^# Thread_id: (\\d+)\\s+Schema: (\\w+)\\s+Last_errno: (\\d+)\\s+Killed: (\\d+)/,\n+    qtime:    /^# Query_time: (\\S+)\\s+Lock_time: (\\S+)\\s+Rows_sent: (\\d+)\\s+Rows_examined: (\\d+)\\s+Rows_affected: (\\d+)\\s+Rows_read: (\\d+)/,\n+    bytes:    /^# Bytes_sent: (\\d+)\\s+Tmp_tables: (\\d+)\\s+Tmp_disk_tables: (\\d+)\\s+Tmp_table_sizes: (\\d+)/,\n+    trxid:    /^# InnoDB_trx_id: (\\S+)/,\n+    qchit:    /^# QC_Hit: (\\w+)\\s+Full_scan: (\\w+)\\s+Full_join: (\\w+)/,\n+    filesort: /^# Filesort: (\\w+)\\s+Filesort_on_disk: (\\w+)\\s+Merge_passes: (\\d+)/,\n+    innoio:   /^#\\s+InnoDB_IO_r_ops: (\\d+)\\s+InnoDB_IO_r_bytes: (\\d+)\\s+InnoDB_IO_r_wait: (\\S+)/,\n+    innowait: /^#\\s+InnoDB_rec_lock_wait: (\\S+)\\s+InnoDB_queue_wait: (\\S+)/,\n+    innopage: /^#\\s+InnoDB_pages_distinct: (\\d+)/,\n+    time:     /^SET timestamp=(\\d+)/,\n+    query:    /^(SELECT|INSERT|UPDATE|DELETE)\\b/,\n+  }\n+\n+  attr_accessor :attributes\n+\n+  def initialize\n+    @attributes = {query_string: \"\"}\n+    @done = false\n+  end\n+\n+  def parse_line(line)\n+    return if line =~ PATTERNS[:header] || line =~ PATTERNS[:skip]\n+\n+    case line\n+    when PATTERNS[:userhost]\n+      attributes[:user] = $1\n+      attributes[:host] = $2\n+    when PATTERNS[:thread]\n+      attributes[:thread_id] = $1.to_i\n+      attributes[:schema] = $2\n+      attributes[:errno] = $3.to_i\n+      attributes[:killed] = $4.to_i > 0\n+    when PATTERNS[:qtime]\n+      attributes[:request_time] = $1.to_f\n+      attributes[:lock_time] = $2.to_f\n+      attributes[:rows_sent] = $3.to_i\n+      attributes[:rows_examined] = $4.to_i\n+      attributes[:rows_affected] = $5.to_i\n+      attributes[:rows_read] = $6.to_i\n+    when PATTERNS[:bytes]\n+      attributes[:bytes_sent] = $1.to_i\n+      attributes[:tmp_tables] = $2.to_i\n+      attributes[:tmp_disk_tables] = $3.to_i\n+      attributes[:tmp_table_sizes] = $4.to_i\n+    when PATTERNS[:trxid]\n+      attributes[:transaction_id] = $1\n+    when PATTERNS[:qchit]\n+      attributes[:used_query_cache] = $1 == \"Yes\"\n+      attributes[:full_scan] = $2 == \"Yes\"\n+      attributes[:full_join] = $3 == \"Yes\"\n+    when PATTERNS[:filesort]\n+      attributes[:filesort] = $1 == \"Yes\"\n+      attributes[:filesort_on_disk] = $2 == \"Yes\"\n+      attributes[:merge_passes] = $3.to_i\n+    when PATTERNS[:innoio]\n+      attributes[:io_read_ops] = $1.to_i\n+      attributes[:io_read_bytes] = $2.to_i\n+      attributes[:io_read_wait] = $3.to_f\n+    when PATTERNS[:innowait]\n+      attributes[:io_lock_wait] = $1.to_f\n+      attributes[:io_queue_wait] = $2.to_f\n+    when PATTERNS[:innopage]\n+      attributes[:io_distinct_pages] = $1.to_i\n+    when PATTERNS[:time]\n+      attributes[:timestamp] = $1.to_i\n+    when PATTERNS[:query]\n+      append_line(line)\n+    else\n+      if attributes[:query_string]\n+        append_line(line)\n+      else\n+        raise \"Weird-looking log line:\\n#{line}\\n\"","path":"slow_query_exporter.rb","position":109,"original_position":109,"commit_id":"6095f778b51cdb114bd40a0addb02f8abf4d96ae","original_commit_id":"6095f778b51cdb114bd40a0addb02f8abf4d96ae","user":{"login":"brainoreally","id":9439226,"avatar_url":"https://avatars.githubusercontent.com/u/9439226?v=3","gravatar_id":"","url":"https://api.github.com/users/brainoreally","html_url":"https://github.com/brainoreally","followers_url":"https://api.github.com/users/brainoreally/followers","following_url":"https://api.github.com/users/brainoreally/following{/other_user}","gists_url":"https://api.github.com/users/brainoreally/gists{/gist_id}","starred_url":"https://api.github.com/users/brainoreally/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brainoreally/subscriptions","organizations_url":"https://api.github.com/users/brainoreally/orgs","repos_url":"https://api.github.com/users/brainoreally/repos","events_url":"https://api.github.com/users/brainoreally/events{/privacy}","received_events_url":"https://api.github.com/users/brainoreally/received_events","type":"User","site_admin":false},"body":"I'm not sure who will be reviewing this output - but is it possible this message might be unclear to them?\r\n\r\nMaybe \r\n```\r\nDo not know how to parse log line:\r\n```\r\nOr something? (unless you think it's clear enough for anyone viewing Greylog)","created_at":"2016-09-16T19:15:38Z","updated_at":"2016-09-16T19:30:25Z","html_url":"https://github.com/fimmtiu/slow_query_exporter/pull/1#discussion_r79233828","pull_request_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/fimmtiu/slow_query_exporter/pulls/comments/79233828"},"html":{"href":"https://github.com/fimmtiu/slow_query_exporter/pull/1#discussion_r79233828"},"pull_request":{"href":"https://api.github.com/repos/fimmtiu/slow_query_exporter/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/pulls/1","id":85618536,"html_url":"https://github.com/fimmtiu/slow_query_exporter/pull/1","diff_url":"https://github.com/fimmtiu/slow_query_exporter/pull/1.diff","patch_url":"https://github.com/fimmtiu/slow_query_exporter/pull/1.patch","issue_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/issues/1","number":1,"state":"open","locked":false,"title":"Add everything","user":{"login":"fimmtiu","id":1072142,"avatar_url":"https://avatars.githubusercontent.com/u/1072142?v=3","gravatar_id":"","url":"https://api.github.com/users/fimmtiu","html_url":"https://github.com/fimmtiu","followers_url":"https://api.github.com/users/fimmtiu/followers","following_url":"https://api.github.com/users/fimmtiu/following{/other_user}","gists_url":"https://api.github.com/users/fimmtiu/gists{/gist_id}","starred_url":"https://api.github.com/users/fimmtiu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fimmtiu/subscriptions","organizations_url":"https://api.github.com/users/fimmtiu/orgs","repos_url":"https://api.github.com/users/fimmtiu/repos","events_url":"https://api.github.com/users/fimmtiu/events{/privacy}","received_events_url":"https://api.github.com/users/fimmtiu/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-09-16T18:28:14Z","updated_at":"2016-09-16T19:30:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"18730871102b76fbee5115c709684e6e7f21e25d","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/pulls/1/commits","review_comments_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/pulls/1/comments","review_comment_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/issues/1/comments","statuses_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/statuses/6095f778b51cdb114bd40a0addb02f8abf4d96ae","head":{"label":"fimmtiu:add-everything","ref":"add-everything","sha":"6095f778b51cdb114bd40a0addb02f8abf4d96ae","user":{"login":"fimmtiu","id":1072142,"avatar_url":"https://avatars.githubusercontent.com/u/1072142?v=3","gravatar_id":"","url":"https://api.github.com/users/fimmtiu","html_url":"https://github.com/fimmtiu","followers_url":"https://api.github.com/users/fimmtiu/followers","following_url":"https://api.github.com/users/fimmtiu/following{/other_user}","gists_url":"https://api.github.com/users/fimmtiu/gists{/gist_id}","starred_url":"https://api.github.com/users/fimmtiu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fimmtiu/subscriptions","organizations_url":"https://api.github.com/users/fimmtiu/orgs","repos_url":"https://api.github.com/users/fimmtiu/repos","events_url":"https://api.github.com/users/fimmtiu/events{/privacy}","received_events_url":"https://api.github.com/users/fimmtiu/received_events","type":"User","site_admin":false},"repo":{"id":68400712,"name":"slow_query_exporter","full_name":"fimmtiu/slow_query_exporter","owner":{"login":"fimmtiu","id":1072142,"avatar_url":"https://avatars.githubusercontent.com/u/1072142?v=3","gravatar_id":"","url":"https://api.github.com/users/fimmtiu","html_url":"https://github.com/fimmtiu","followers_url":"https://api.github.com/users/fimmtiu/followers","following_url":"https://api.github.com/users/fimmtiu/following{/other_user}","gists_url":"https://api.github.com/users/fimmtiu/gists{/gist_id}","starred_url":"https://api.github.com/users/fimmtiu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fimmtiu/subscriptions","organizations_url":"https://api.github.com/users/fimmtiu/orgs","repos_url":"https://api.github.com/users/fimmtiu/repos","events_url":"https://api.github.com/users/fimmtiu/events{/privacy}","received_events_url":"https://api.github.com/users/fimmtiu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fimmtiu/slow_query_exporter","description":"A daemon which exports a MySQL slow query log to a Graylog server","fork":false,"url":"https://api.github.com/repos/fimmtiu/slow_query_exporter","forks_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/forks","keys_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/teams","hooks_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/hooks","issue_events_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/issues/events{/number}","events_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/events","assignees_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/assignees{/user}","branches_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/branches{/branch}","tags_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/tags","blobs_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/git/refs{/sha}","trees_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/statuses/{sha}","languages_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/languages","stargazers_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/stargazers","contributors_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/contributors","subscribers_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/subscribers","subscription_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/subscription","commits_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/commits{/sha}","git_commits_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/git/commits{/sha}","comments_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/comments{/number}","issue_comment_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/issues/comments{/number}","contents_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/contents/{+path}","compare_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/merges","archive_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/downloads","issues_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/issues{/number}","pulls_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/pulls{/number}","milestones_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/milestones{/number}","notifications_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/labels{/name}","releases_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/releases{/id}","deployments_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/deployments","created_at":"2016-09-16T17:32:10Z","updated_at":"2016-09-16T18:27:11Z","pushed_at":"2016-09-16T18:28:14Z","git_url":"git://github.com/fimmtiu/slow_query_exporter.git","ssh_url":"git@github.com:fimmtiu/slow_query_exporter.git","clone_url":"https://github.com/fimmtiu/slow_query_exporter.git","svn_url":"https://github.com/fimmtiu/slow_query_exporter","homepage":null,"size":4,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"fimmtiu:master","ref":"master","sha":"9179ffd99c664122a85b1e9f197b85b01c7540e2","user":{"login":"fimmtiu","id":1072142,"avatar_url":"https://avatars.githubusercontent.com/u/1072142?v=3","gravatar_id":"","url":"https://api.github.com/users/fimmtiu","html_url":"https://github.com/fimmtiu","followers_url":"https://api.github.com/users/fimmtiu/followers","following_url":"https://api.github.com/users/fimmtiu/following{/other_user}","gists_url":"https://api.github.com/users/fimmtiu/gists{/gist_id}","starred_url":"https://api.github.com/users/fimmtiu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fimmtiu/subscriptions","organizations_url":"https://api.github.com/users/fimmtiu/orgs","repos_url":"https://api.github.com/users/fimmtiu/repos","events_url":"https://api.github.com/users/fimmtiu/events{/privacy}","received_events_url":"https://api.github.com/users/fimmtiu/received_events","type":"User","site_admin":false},"repo":{"id":68400712,"name":"slow_query_exporter","full_name":"fimmtiu/slow_query_exporter","owner":{"login":"fimmtiu","id":1072142,"avatar_url":"https://avatars.githubusercontent.com/u/1072142?v=3","gravatar_id":"","url":"https://api.github.com/users/fimmtiu","html_url":"https://github.com/fimmtiu","followers_url":"https://api.github.com/users/fimmtiu/followers","following_url":"https://api.github.com/users/fimmtiu/following{/other_user}","gists_url":"https://api.github.com/users/fimmtiu/gists{/gist_id}","starred_url":"https://api.github.com/users/fimmtiu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fimmtiu/subscriptions","organizations_url":"https://api.github.com/users/fimmtiu/orgs","repos_url":"https://api.github.com/users/fimmtiu/repos","events_url":"https://api.github.com/users/fimmtiu/events{/privacy}","received_events_url":"https://api.github.com/users/fimmtiu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fimmtiu/slow_query_exporter","description":"A daemon which exports a MySQL slow query log to a Graylog server","fork":false,"url":"https://api.github.com/repos/fimmtiu/slow_query_exporter","forks_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/forks","keys_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/teams","hooks_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/hooks","issue_events_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/issues/events{/number}","events_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/events","assignees_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/assignees{/user}","branches_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/branches{/branch}","tags_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/tags","blobs_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/git/refs{/sha}","trees_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/statuses/{sha}","languages_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/languages","stargazers_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/stargazers","contributors_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/contributors","subscribers_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/subscribers","subscription_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/subscription","commits_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/commits{/sha}","git_commits_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/git/commits{/sha}","comments_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/comments{/number}","issue_comment_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/issues/comments{/number}","contents_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/contents/{+path}","compare_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/merges","archive_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/downloads","issues_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/issues{/number}","pulls_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/pulls{/number}","milestones_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/milestones{/number}","notifications_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/labels{/name}","releases_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/releases{/id}","deployments_url":"https://api.github.com/repos/fimmtiu/slow_query_exporter/deployments","created_at":"2016-09-16T17:32:10Z","updated_at":"2016-09-16T18:27:11Z","pushed_at":"2016-09-16T18:28:14Z","git_url":"git://github.com/fimmtiu/slow_query_exporter.git","ssh_url":"git@github.com:fimmtiu/slow_query_exporter.git","clone_url":"https://github.com/fimmtiu/slow_query_exporter.git","svn_url":"https://github.com/fimmtiu/slow_query_exporter","homepage":null,"size":4,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fimmtiu/slow_query_exporter/pulls/1"},"html":{"href":"https://github.com/fimmtiu/slow_query_exporter/pull/1"},"issue":{"href":"https://api.github.com/repos/fimmtiu/slow_query_exporter/issues/1"},"comments":{"href":"https://api.github.com/repos/fimmtiu/slow_query_exporter/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/fimmtiu/slow_query_exporter/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/fimmtiu/slow_query_exporter/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fimmtiu/slow_query_exporter/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/fimmtiu/slow_query_exporter/statuses/6095f778b51cdb114bd40a0addb02f8abf4d96ae"}}}}
{"actor":{"display_login":"brainoreally"}}