Skip to content
Browse files

Added new parser for Rails with syslog

  • Loading branch information...
1 parent dc20195 commit 209245eb55a7f5ce459d1c682dc3d89997612db0 @zedtux committed
Showing with 67 additions and 0 deletions.
  1. +4 −0 History.txt
  2. +1 −0 Manifest.txt
  3. +6 −0 dist/config.yaml
  4. +56 −0 lib/gl_tail/parsers/rails_syslog.rb
View
4 History.txt
@@ -1,3 +1,7 @@
+== 0.1.8 / 2011-04-18
+
+* Rails with syslog parser (Guillaume Hain <zedtux@zedroot.org>)
+
== 0.1.7 / 2008-07-13
* Handle empty host in URLs logged by Rails (Steve Purcell <steve@sanityinc.com>)
View
1 Manifest.txt
@@ -30,6 +30,7 @@ lib/gl_tail/parsers/postgresql.rb
lib/gl_tail/parsers/pureftpd.rb
lib/gl_tail/parsers/qmail.rb
lib/gl_tail/parsers/rails.rb
+lib/gl_tail/parsers/rails_syslog.rb
lib/gl_tail/parsers/squid.rb
lib/gl_tail/parsers/tshark.rb
lib/gl_tail/resolver.rb
View
6 dist/config.yaml
@@ -95,6 +95,12 @@ config:
mappers:
order: 11
size: 8
+ sqlselect:
+ color: 1.0, 0.8, 0.4, 1.0
+ sqlupdate:
+ color: 1.0, 0.2, 0.2, 1.0
+ sqlinsert:
+ color: 1.0, 0.5, 0.5, 0.0
right_column:
View
56 lib/gl_tail/parsers/rails_syslog.rb
@@ -0,0 +1,56 @@
+# gl_tail.rb - OpenGL visualization of your server traffic
+# Copyright 2011 Guillaume Hain <zedtux@zedroot.org>
+#
+# Licensed under the GNU General Public License v2 (see LICENSE)
+#
+
+# Parser which handles Rails access syslogs
+class RailsSyslogParser < Parser
+ def parse( line )
+ #Apr 18 07:27:02 appname network_name[pid]: Completed in 0.02100 (47 reqs/sec) | Rendering: 0.01374 (65%) | DB: 0.00570 (27%) | 200 OK [http://example.com/whatever/whatever]
+ _, ms, url = /^.*\[[\d.]+\]: Completed in ([\d.]+)ms .* \[([^\]]+)\]/.match(line).to_a
+
+ if url
+ _, host, url = /^http[s]?:\/\/([^\/]*)(.*)/.match(url).to_a
+
+ add_activity(:block => 'sites', :name => host, :size => ms.to_f) # Size of activity based on request time.
+ add_activity(:block => 'urls', :name => HttpHelper.generalize_url(url), :size => ms.to_f)
+ add_activity(:block => 'slow requests', :name => HttpHelper.generalize_url(url), :size => ms.to_f)
+ add_activity(:block => 'content', :name => 'page')
+
+ # Events to pop up
+ add_event(:block => 'info', :name => "Logins", :message => "Login...", :update_stats => true, :color => [0.5, 1.0, 0.5, 1.0]) if url.include?('/login')
+ add_event(:block => 'info', :name => "Sales", :message => "$", :update_stats => true, :color => [1.5, 0.0, 0.0, 1.0]) if url.include?('/checkout')
+ add_event(:block => 'info', :name => "Signups", :message => "New User...", :update_stats => true, :color => [1.0, 1.0, 1.0, 1.0]) if(url.include?('/signup') || url.include?('/users/create'))
+ elsif line.include?('Processing ')
+ #Apr 18 07:27:02 appname network_name[pid]: Processing TasksController#update_sheet_info (for 123.123.123.123 at 2007-10-05 22:34:33) [POST]
+ _, host = /^.*: Processing .* \(for (\d+.\d+.\d+.\d+) at .*\).*$/.match(line).to_a
+ if host
+ add_activity(:block => 'users', :name => host)
+ end
+ elsif line.include?('Error (')
+ _, error, msg = /^([^ ]+Error) \((.*)\):/.match(line).to_a
+ if error
+ add_event(:block => 'info', :name => "Exceptions", :message => error, :update_stats => true, :color => [1.0, 0.0, 0.0, 1.0])
+ add_event(:block => 'info', :name => "Exceptions", :message => msg, :update_stats => false, :color => [1.0, 0.0, 0.0, 1.0])
+ add_activity(:block => 'warnings', :name => msg)
+
+ end
+ elsif line.include?('SELECT ')
+ #Apr 18 07:27:02 appname network_name[pid]: IsinTarget Load (1.1ms) SELECT * FROM "table" WHERE id = 1
+ _, model_name, ms = /^.*\[[\d.]+\]: ([A-Za-z]+) Load \(([\d.]+)ms\)[\s]+SELECT.*$/.match(line).to_a
+
+ add_activity(:block => 'sqlselect', :name => model_name, :size => ms.to_f)
+ elsif line.include?('UPDATE ')
+ #Apr 18 07:27:02 appname network_name[pid]: IsinTarget Load (1.1ms) UPDATE "table" SET "column" = 'value' WHERE id = 1
+ _, model_name, ms = /^.*\[[\d.]+\]: ([A-Za-z]+) Update \(([\d.]+)ms\)[\s]+UPDATE.*$/.match(line).to_a
+
+ add_activity(:block => 'sqlupdate', :name => model_name, :size => ms.to_f)
+ elsif line.include?('INSERT INTO ')
+ #Apr 18 07:27:02 appname network_name[pid]: SQL (3.0ms) INSERT INTO "table" ("field1", "field2") VALUES(value1, value2) RETURNING "id"
+ _, ms, table_name = /^.*\[[\d.]+\]: SQL \(([\d.]+)ms\)[\s]+INSERT INTO \"([A-Za-z_]+)\".*$/.match(line).to_a
+
+ add_activity(:block => 'sqlinsert', :name => table_name, :size => ms.to_f)
+ end
+ end
+end

0 comments on commit 209245e

Please sign in to comment.
Something went wrong with that request. Please try again.