bind_log_analyzer 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -118,7 +118,7 @@
118
118
  </div>
119
119
 
120
120
  <div id="footer">
121
- Generated on Thu Apr 5 16:40:26 2012 by
121
+ Generated on Tue Apr 10 16:12:42 2012 by
122
122
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
123
123
  0.7.5 (ruby-1.9.3).
124
124
  </div>
@@ -73,7 +73,7 @@
73
73
 
74
74
  <dt class="r1 last">Defined in:</dt>
75
75
  <dd class="r1 last">lib/bind_log_analyzer.rb<span class="defines">,<br />
76
- lib/bind_log_analyzer/base.rb,<br /> lib/bind_log_analyzer/version.rb,<br /> lib/bind_log_analyzer/connector.rb,<br /> lib/bind_log_analyzer/web_server.rb,<br /> lib/bind_log_analyzer/exceptions.rb</span>
76
+ lib/bind_log_analyzer/base.rb,<br /> lib/bind_log_analyzer/version.rb,<br /> lib/bind_log_analyzer/connector.rb,<br /> lib/bind_log_analyzer/log_utils.rb,<br /> lib/bind_log_analyzer/web_server.rb,<br /> lib/bind_log_analyzer/exceptions.rb</span>
77
77
  </dd>
78
78
 
79
79
  </dl>
@@ -96,7 +96,7 @@ supported by ActiveRecord.</p>
96
96
  <p class="children">
97
97
 
98
98
 
99
- <strong class="modules">Modules:</strong> <span class='object_link'><a href="BindLogAnalyzer/Connector.html" title="BindLogAnalyzer::Connector (module)">Connector</a></span>
99
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="BindLogAnalyzer/Connector.html" title="BindLogAnalyzer::Connector (module)">Connector</a></span>, <span class='object_link'><a href="BindLogAnalyzer/LogUtils.html" title="BindLogAnalyzer::LogUtils (module)">LogUtils</a></span>
100
100
 
101
101
 
102
102
 
@@ -141,7 +141,7 @@ supported by ActiveRecord.</p>
141
141
 
142
142
  </div>
143
143
  </dt>
144
- <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0.2.1</span><span class='tstring_end'>&quot;</span></span></pre></dd>
144
+ <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0.2.2</span><span class='tstring_end'>&quot;</span></span></pre></dd>
145
145
 
146
146
  </dl>
147
147
 
@@ -157,7 +157,7 @@ supported by ActiveRecord.</p>
157
157
  </div>
158
158
 
159
159
  <div id="footer">
160
- Generated on Thu Apr 5 16:40:26 2012 by
160
+ Generated on Tue Apr 10 16:12:42 2012 by
161
161
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
162
162
  0.7.5 (ruby-1.9.3).
163
163
  </div>
data/doc/Log.html CHANGED
@@ -259,7 +259,7 @@
259
259
  </div>
260
260
 
261
261
  <div id="footer">
262
- Generated on Thu Apr 5 16:40:26 2012 by
262
+ Generated on Tue Apr 10 16:12:42 2012 by
263
263
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
264
264
  0.7.5 (ruby-1.9.3).
265
265
  </div>
data/doc/_index.html CHANGED
@@ -135,6 +135,13 @@
135
135
 
136
136
  </li>
137
137
 
138
+ <li>
139
+ <span class='object_link'><a href="BindLogAnalyzer/LogUtils.html" title="BindLogAnalyzer::LogUtils (module)">LogUtils</a></span>
140
+
141
+ <small>(BindLogAnalyzer)</small>
142
+
143
+ </li>
144
+
138
145
  </ul>
139
146
  </ul>
140
147
 
@@ -162,7 +169,7 @@
162
169
  </div>
163
170
 
164
171
  <div id="footer">
165
- Generated on Thu Apr 5 16:40:26 2012 by
172
+ Generated on Tue Apr 10 16:12:42 2012 by
166
173
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
167
174
  0.7.5 (ruby-1.9.3).
168
175
  </div>
data/doc/class_list.html CHANGED
@@ -39,7 +39,7 @@
39
39
 
40
40
  <ul id="full_list" class="class">
41
41
  <li><span class='object_link'><a href="top-level-namespace.html" title=" (root)">Top Level Namespace</a></span></li>
42
- <li><a class='toggle'></a> <span class='object_link'><a href="BindLogAnalyzer.html" title="BindLogAnalyzer (module)">BindLogAnalyzer</a></span><small class='search_info'>Top Level Namespace</small></li><ul><li><span class='object_link'><a href="BindLogAnalyzer/Base.html" title="BindLogAnalyzer::Base (class)">Base</a></span> &lt; Object<small class='search_info'>BindLogAnalyzer</small></li><li><span class='object_link'><a href="BindLogAnalyzer/Connector.html" title="BindLogAnalyzer::Connector (module)">Connector</a></span><small class='search_info'>BindLogAnalyzer</small></li><li><span class='object_link'><a href="BindLogAnalyzer/DatabaseConfsNotValid.html" title="BindLogAnalyzer::DatabaseConfsNotValid (class)">DatabaseConfsNotValid</a></span> &lt; Exception<small class='search_info'>BindLogAnalyzer</small></li><li><span class='object_link'><a href="BindLogAnalyzer/WebServer.html" title="BindLogAnalyzer::WebServer (class)">WebServer</a></span> &lt; Application<small class='search_info'>BindLogAnalyzer</small></li></ul><li><span class='object_link'><a href="Log.html" title="Log (class)">Log</a></span> &lt; Base<small class='search_info'>Top Level Namespace</small></li>
42
+ <li><a class='toggle'></a> <span class='object_link'><a href="BindLogAnalyzer.html" title="BindLogAnalyzer (module)">BindLogAnalyzer</a></span><small class='search_info'>Top Level Namespace</small></li><ul><li><span class='object_link'><a href="BindLogAnalyzer/Base.html" title="BindLogAnalyzer::Base (class)">Base</a></span> &lt; Object<small class='search_info'>BindLogAnalyzer</small></li><li><span class='object_link'><a href="BindLogAnalyzer/Connector.html" title="BindLogAnalyzer::Connector (module)">Connector</a></span><small class='search_info'>BindLogAnalyzer</small></li><li><span class='object_link'><a href="BindLogAnalyzer/DatabaseConfsNotValid.html" title="BindLogAnalyzer::DatabaseConfsNotValid (class)">DatabaseConfsNotValid</a></span> &lt; Exception<small class='search_info'>BindLogAnalyzer</small></li><li><span class='object_link'><a href="BindLogAnalyzer/LogUtils.html" title="BindLogAnalyzer::LogUtils (module)">LogUtils</a></span><small class='search_info'>BindLogAnalyzer</small></li><li><span class='object_link'><a href="BindLogAnalyzer/WebServer.html" title="BindLogAnalyzer::WebServer (class)">WebServer</a></span> &lt; Application<small class='search_info'>BindLogAnalyzer</small></li></ul><li><span class='object_link'><a href="Log.html" title="Log (class)">Log</a></span> &lt; Base<small class='search_info'>Top Level Namespace</small></li>
43
43
 
44
44
  </ul>
45
45
  </div>
data/doc/file.README.html CHANGED
@@ -223,7 +223,7 @@ bind_log_analyzer -f query.log -c database.yml 322,44s user 22,90s system 76% c
223
223
  </div></div>
224
224
 
225
225
  <div id="footer">
226
- Generated on Thu Apr 5 16:40:26 2012 by
226
+ Generated on Tue Apr 10 16:12:42 2012 by
227
227
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
228
228
  0.7.5 (ruby-1.9.3).
229
229
  </div>
data/doc/index.html CHANGED
@@ -223,7 +223,7 @@ bind_log_analyzer -f query.log -c database.yml 322,44s user 22,90s system 76% c
223
223
  </div></div>
224
224
 
225
225
  <div id="footer">
226
- Generated on Thu Apr 5 16:40:26 2012 by
226
+ Generated on Tue Apr 10 16:12:42 2012 by
227
227
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
228
228
  0.7.5 (ruby-1.9.3).
229
229
  </div>
data/doc/method_list.html CHANGED
@@ -129,9 +129,9 @@
129
129
 
130
130
 
131
131
  <li class="r2 ">
132
- <span class='object_link'><a href="BindLogAnalyzer/Connector.html#set_log_level-class_method" title="BindLogAnalyzer::Connector.set_log_level (method)">set_log_level</a></span>
132
+ <span class='object_link'><a href="BindLogAnalyzer/LogUtils.html#set_log_level-class_method" title="BindLogAnalyzer::LogUtils.set_log_level (method)">set_log_level</a></span>
133
133
 
134
- <small>BindLogAnalyzer::Connector</small>
134
+ <small>BindLogAnalyzer::LogUtils</small>
135
135
 
136
136
  </li>
137
137
 
@@ -98,7 +98,7 @@
98
98
  </div>
99
99
 
100
100
  <div id="footer">
101
- Generated on Thu Apr 5 16:40:26 2012 by
101
+ Generated on Tue Apr 10 16:12:43 2012 by
102
102
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
103
103
  0.7.5 (ruby-1.9.3).
104
104
  </div>
@@ -1,10 +1,12 @@
1
1
  require 'bind_log_analyzer/exceptions'
2
+ require 'bind_log_analyzer/log_utils'
2
3
  require 'bind_log_analyzer/connector'
3
4
  require 'models/log'
4
5
 
5
6
  module BindLogAnalyzer
6
7
  # The main class of the BindLogAnalyzer module
7
8
  class Base
9
+ include BindLogAnalyzer::LogUtils
8
10
  include BindLogAnalyzer::Connector
9
11
 
10
12
  # @attribute [r]
@@ -16,16 +18,25 @@ module BindLogAnalyzer
16
18
  # @param [String] logfile The path to the file containing the Bind's logs to analyze
17
19
  # @param [true, false] setup_database A flag which indicates whether to launch the database migration
18
20
  # @param [Integer] log_level The level of the log requested by the user
19
- def initialize(database_params = nil, logfile = nil, setup_database = false, log_level = 0)
21
+ # @param [true, false] check_uniq Checks if a record exists before creating it
22
+ def initialize(database_params = nil, logfile = nil, setup_database = false, log_level = 0, check_uniq = false)
20
23
  @stored_queries = 0
24
+ @check_uniq = check_uniq
25
+
26
+ @log = BindLogAnalyzer::LogUtils.set_log_level(log_level)
27
+
21
28
  self.logfile = logfile if logfile
22
- setup_db(database_params, setup_database, log_level)
29
+ setup_db(database_params, setup_database)
23
30
  end
24
31
 
25
32
  # Sets the path to the log file checking if exists
26
33
  # @param [String] logfile The path to the file containing the Bind's logs to analyze
27
34
  def logfile=(logfile)
28
- @log_filename = logfile if FileTest.exists?(logfile)
35
+ if FileTest.exists?(logfile)
36
+ @log_filename = logfile
37
+ else
38
+ @log.error = "The provided log file doesn't exist"
39
+ end
29
40
  end
30
41
 
31
42
  # Returns the path to the Bind's log file
@@ -55,15 +66,30 @@ module BindLogAnalyzer
55
66
 
56
67
  query
57
68
  else
69
+ @log.error "Can't parse the line: \"#{line}\""
58
70
  false
59
71
  end
60
72
  end
61
73
 
62
- # Stores the parsed log line into the database. Increments @stored_queries if successful
74
+ # Stores the parsed log line into the database and increments @stored_queries if successful.
75
+ # It checks the uniqueness of a record if the @check_uniq flag is set
63
76
  # @param [Hash] query The log line parsed by #parse_line
64
77
  def store_query(query)
65
- log = Log.new(query)
66
- @stored_queries += 1 if log.save
78
+ if @check_uniq
79
+ unless Log.where(query)
80
+ log = Log.new(:date => query[:date])
81
+ @stored_queries += 1 if log.save
82
+ else
83
+ @log.warn "Skipping duplicate entry: #{query}"
84
+ end
85
+ else
86
+ log = Log.new(query)
87
+ if log.save
88
+ @stored_queries += 1
89
+ else
90
+ @log.error "Error saving the log #{query}"
91
+ end
92
+ end
67
93
  end
68
94
 
69
95
  # The main method used to manage the analysis operations.
@@ -74,8 +100,10 @@ module BindLogAnalyzer
74
100
 
75
101
  lines = 0
76
102
  File.new(@log_filename).each do |line|
103
+ @log.debug "Got line: \"#{line}\""
77
104
  query = self.parse_line(line)
78
105
  if query
106
+ @log.debug "Storing line: \"#{query}\""
79
107
  self.store_query(query)
80
108
  lines += 1
81
109
  end
@@ -1,6 +1,5 @@
1
1
  require 'bind_log_analyzer/exceptions'
2
2
  require 'active_record'
3
- require 'logger'
4
3
 
5
4
  module BindLogAnalyzer
6
5
  # The module which provides connection facility
@@ -10,9 +9,8 @@ module BindLogAnalyzer
10
9
  # loads the Log ActiveRecord model and setups the logger.
11
10
  # @param [Hash] database_params The database params and credentials
12
11
  # @param [true, false] setup_database If true launches the migrations of the database
13
- # @param [Integer] log_level The log level to setup the Logger
14
- def setup_db(database_params, setup_database = false, log_level = 0)
15
- BindLogAnalyzer::Connector.setup_db_confs(database_params)
12
+ def setup_db(database_params, setup_database = false)
13
+ BindLogAnalyzer::Connector.setup_db_confs(database_params, @log)
16
14
 
17
15
  BindLogAnalyzer::Connector.connect
18
16
 
@@ -20,7 +18,7 @@ module BindLogAnalyzer
20
18
 
21
19
  self.load_environment
22
20
 
23
- BindLogAnalyzer::Connector.set_log_level(log_level)
21
+ ActiveRecord::Base.logger = @log
24
22
  end
25
23
 
26
24
  # Launches ActiveRecord migrations
@@ -43,30 +41,36 @@ module BindLogAnalyzer
43
41
 
44
42
  # Loads the ActiveRecord models
45
43
  def load_environment
46
- Dir.glob('./lib/models/*').each { |r| require r }
44
+ Dir.glob('./lib/models/*').each do |r|
45
+ @log.debug "Requiring model #{r}"
46
+ require r
47
+ end
47
48
  end
48
49
 
49
50
  # Setups the database params calling #setup_db_confs and log level calling #set_log_level then connects to the database
50
51
  # @param [Hash, String] database_params The path to the database configurations file or a hash containing such informations
51
52
  # @param [String] logfile The path to the file containing the Bind's logs to analyze
52
- def self.establish_connection(database_params, log_level)
53
- BindLogAnalyzer::Connector.setup_db_confs(database_params)
53
+ def self.establish_connection(database_params, logger)
54
+ BindLogAnalyzer::Connector.setup_db_confs(database_params, logger)
54
55
  BindLogAnalyzer::Connector.connect
55
- BindLogAnalyzer::Connector.set_log_level(log_level)
56
+ ActiveRecord::Base.logger = logger
56
57
  end
57
58
 
58
59
  # Analyzes the database_params param and extracts the database parameters. Raises BindLogAnalyzer::DatabaseConfsNotValid
59
60
  # if it can't find any useful information
60
61
  # @param [Hash, String] database_params The path to the database configurations file or a hash containing such informations
61
- def self.setup_db_confs(database_params)
62
+ def self.setup_db_confs(database_params, logger)
62
63
  if database_params
63
64
  if database_params.instance_of?(Hash)
65
+ logger.debug "Setting up database with confs: #{database_params}"
64
66
  @database_params = database_params
65
67
  else
66
68
  # Load the yaml file
67
69
  if FileTest.exists?(database_params)
70
+ logger.debug "Setting up database using file #{database_params}"
68
71
  @database_params = YAML::load(File.open(database_params))['database']
69
72
  else
73
+ logger.fatal "The indicated YAML file doesn't exist or is invalid"
70
74
  raise BindLogAnalyzer::DatabaseConfsNotValid, "The indicated YAML file doesn't exist or is invalid"
71
75
  end
72
76
  end
@@ -74,28 +78,13 @@ module BindLogAnalyzer
74
78
  # Tries to find the yaml file or prints an error
75
79
  filename = './database.yml'
76
80
  if FileTest.exists?(filename)
81
+ logger.info "No database configurations provided, now trying using #{filename}..."
77
82
  @database_params = YAML::load(File.open(filename))['database']
78
83
  else
84
+ logger.fatal "Can't find valid database configurations"
79
85
  raise BindLogAnalyzer::DatabaseConfsNotValid, "Can't find valid database configurations"
80
86
  end
81
87
  end
82
88
  end
83
-
84
- # Sets the log level
85
- # @param [String] logfile The path to the file containing the Bind's logs to analyze
86
- def self.set_log_level(log_level)
87
- if log_level > 0
88
-
89
- log_level_class = {
90
- 1 => Logger::WARN,
91
- 2 => Logger::INFO,
92
- 3 => Logger::DEBUG
93
- }
94
-
95
- log = Logger.new STDOUT
96
- log.level = log_level_class[log_level]
97
- ActiveRecord::Base.logger = log
98
- end
99
- end
100
89
  end
101
90
  end
@@ -0,0 +1,28 @@
1
+ require 'bind_log_analyzer/exceptions'
2
+ require 'logger'
3
+
4
+ module BindLogAnalyzer
5
+ # Sets log level
6
+ module LogUtils
7
+ # Sets the log level
8
+ # @param [String] logfile The path to the file containing the Bind's logs to analyze
9
+ def self.set_log_level(log_level)
10
+ log = Logger.new STDOUT
11
+
12
+ if log_level > 0
13
+
14
+ log_level_class = {
15
+ 1 => Logger::ERROR,
16
+ 2 => Logger::WARN,
17
+ 3 => Logger::INFO,
18
+ 4 => Logger::DEBUG
19
+ }
20
+
21
+ log.level = log_level_class[log_level]
22
+ else
23
+ log.level = Logger::FATAL
24
+ end
25
+ return log
26
+ end
27
+ end
28
+ end
@@ -1,4 +1,4 @@
1
1
  module BindLogAnalyzer
2
2
  # @return [String] The version of the gem
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bind_log_analyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-05 00:00:00.000000000 Z
12
+ date: 2012-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &20014180 !ruby/object:Gem::Requirement
16
+ requirement: &9503660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *20014180
24
+ version_requirements: *9503660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &20013680 !ruby/object:Gem::Requirement
27
+ requirement: &9503160 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *20013680
35
+ version_requirements: *9503160
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sinatra
38
- requirement: &20113540 !ruby/object:Gem::Requirement
38
+ requirement: &9603200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *20113540
46
+ version_requirements: *9603200
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: haml
49
- requirement: &20113000 !ruby/object:Gem::Requirement
49
+ requirement: &9602620 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *20113000
57
+ version_requirements: *9602620
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &20112500 !ruby/object:Gem::Requirement
60
+ requirement: &9602120 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *20112500
68
+ version_requirements: *9602120
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
- requirement: &20112000 !ruby/object:Gem::Requirement
71
+ requirement: &9601620 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,9 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *20112000
80
- description: BindLogAnalyzer analyzes a Bind query log file and stores it's data into
81
- a SQL database (ActiveRecord is used for this feature)
79
+ version_requirements: *9601620
80
+ description: BindLogAnalyzer analyzes a Bind query log file and stores its data into
81
+ a SQL database using ActiveRecord. It provides a fancy web interface to show some
82
+ query stats and graphs.
82
83
  email:
83
84
  - tommaso.visconti@gmail.com
84
85
  executables:
@@ -98,6 +99,7 @@ files:
98
99
  - doc/BindLogAnalyzer/Base.html
99
100
  - doc/BindLogAnalyzer/Connector.html
100
101
  - doc/BindLogAnalyzer/DatabaseConfsNotValid.html
102
+ - doc/BindLogAnalyzer/LogUtils.html
101
103
  - doc/BindLogAnalyzer/WebServer.html
102
104
  - doc/Log.html
103
105
  - doc/_index.html
@@ -120,6 +122,7 @@ files:
120
122
  - lib/bind_log_analyzer/base.rb
121
123
  - lib/bind_log_analyzer/connector.rb
122
124
  - lib/bind_log_analyzer/exceptions.rb
125
+ - lib/bind_log_analyzer/log_utils.rb
123
126
  - lib/bind_log_analyzer/version.rb
124
127
  - lib/bind_log_analyzer/web_server.rb
125
128
  - lib/models/log.rb