bind_log_analyzer 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ pkg/*
5
5
  .rvmrc
6
6
  query.log
7
7
  coverage/
8
+ .yardoc/
data/README.md CHANGED
@@ -121,6 +121,16 @@ The script **/usr/local/bin/update_bind_log_analyzer.sh** can be wherever you pr
121
121
  rvm use $BLA_RVM_GEMSET
122
122
  bind_log_analyzer --config $BLA_DB_FILE --file $1
123
123
 
124
+ ## Performance
125
+
126
+ On a 1.6 Ghz Intel Core i5 with SSD SATA2 disk, using Ruby-1.9.3-p125 and MySQL 5.5.15, this is the performance:
127
+
128
+ ~$ time bind_log_analyzer -f query.log -c database.yml
129
+ Analyzed 319758 lines and correctly stored 319758 logs
130
+ bind_log_analyzer -f query.log -c database.yml 322,44s user 22,90s system 76% cpu 7:33,17 total
131
+
132
+ which is equivalent to ±706 query/sec.
133
+
124
134
  ## To do
125
135
 
126
136
  - Add a web interface to show the queries (with awesome graphs, obviously :)
@@ -0,0 +1,166 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Module: BindLogAnalyzer
8
+
9
+ &mdash; Documentation by YARD 0.7.5
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ relpath = '';
19
+ if (relpath != '') relpath += '/';
20
+ </script>
21
+
22
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
23
+
24
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
25
+
26
+
27
+ </head>
28
+ <body>
29
+ <script type="text/javascript" charset="utf-8">
30
+ if (window.top.frames.main) document.body.className = 'frames';
31
+ </script>
32
+
33
+ <div id="header">
34
+ <div id="menu">
35
+
36
+ <a href="_index.html">Index (B)</a> &raquo;
37
+
38
+
39
+ <span class="title">BindLogAnalyzer</span>
40
+
41
+
42
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
43
+ </div>
44
+
45
+ <div id="search">
46
+
47
+ <a id="class_list_link" href="#">Class List</a>
48
+
49
+ <a id="method_list_link" href="#">Method List</a>
50
+
51
+ <a id="file_list_link" href="#">File List</a>
52
+
53
+ </div>
54
+ <div class="clear"></div>
55
+ </div>
56
+
57
+ <iframe id="search_frame"></iframe>
58
+
59
+ <div id="content"><h1>Module: BindLogAnalyzer
60
+
61
+
62
+
63
+ </h1>
64
+
65
+ <dl class="box">
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+ <dt class="r1 last">Defined in:</dt>
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/exceptions.rb</span>
77
+ </dd>
78
+
79
+ </dl>
80
+ <div class="clear"></div>
81
+
82
+ <h2>Overview</h2><div class="docstring">
83
+ <div class="discussion">
84
+
85
+ <p>BindLogAnalyzer analyzes a Bind query log file, parses the logs and store
86
+ them in a database. The database choise is "limited" to the databases
87
+ supported by ActiveRecord.</p>
88
+
89
+
90
+ </div>
91
+ </div>
92
+ <div class="tags">
93
+
94
+
95
+ </div><h2>Defined Under Namespace</h2>
96
+ <p class="children">
97
+
98
+
99
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="BindLogAnalyzer/Connector.html" title="BindLogAnalyzer::Connector (module)">Connector</a></span>
100
+
101
+
102
+
103
+ <strong class="classes">Classes:</strong> <span class='object_link'><a href="BindLogAnalyzer/Base.html" title="BindLogAnalyzer::Base (class)">Base</a></span>, <span class='object_link'><a href="BindLogAnalyzer/DatabaseConfsNotValid.html" title="BindLogAnalyzer::DatabaseConfsNotValid (class)">DatabaseConfsNotValid</a></span>
104
+
105
+
106
+ </p>
107
+
108
+ <h2>Constant Summary</h2>
109
+
110
+ <dl class="constants">
111
+
112
+ <dt id="VERSION-constant" class="">VERSION =
113
+ <div class="docstring">
114
+ <div class="discussion">
115
+
116
+ <p>The version of the gem</p>
117
+
118
+
119
+ </div>
120
+ </div>
121
+ <div class="tags">
122
+
123
+ <h3>Returns:</h3>
124
+ <ul class="return">
125
+
126
+ <li>
127
+
128
+
129
+ <span class='type'>(<tt>String</tt>)</span>
130
+
131
+
132
+
133
+ &mdash;
134
+ <div class='inline'>
135
+ <p>The version of the gem</p>
136
+ </div>
137
+
138
+ </li>
139
+
140
+ </ul>
141
+
142
+ </div>
143
+ </dt>
144
+ <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0.1.1</span><span class='tstring_end'>&quot;</span></span></pre></dd>
145
+
146
+ </dl>
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+ </div>
158
+
159
+ <div id="footer">
160
+ Generated on Tue Apr 3 17:01:09 2012 by
161
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
162
+ 0.7.5 (ruby-1.9.3).
163
+ </div>
164
+
165
+ </body>
166
+ </html>
@@ -0,0 +1,1016 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Class: BindLogAnalyzer::Base
8
+
9
+ &mdash; Documentation by YARD 0.7.5
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ relpath = '..';
19
+ if (relpath != '') relpath += '/';
20
+ </script>
21
+
22
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
23
+
24
+ <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
25
+
26
+
27
+ </head>
28
+ <body>
29
+ <script type="text/javascript" charset="utf-8">
30
+ if (window.top.frames.main) document.body.className = 'frames';
31
+ </script>
32
+
33
+ <div id="header">
34
+ <div id="menu">
35
+
36
+ <a href="../_index.html">Index (B)</a> &raquo;
37
+ <span class='title'><span class='object_link'><a href="../BindLogAnalyzer.html" title="BindLogAnalyzer (module)">BindLogAnalyzer</a></span></span>
38
+ &raquo;
39
+ <span class="title">Base</span>
40
+
41
+
42
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
43
+ </div>
44
+
45
+ <div id="search">
46
+
47
+ <a id="class_list_link" href="#">Class List</a>
48
+
49
+ <a id="method_list_link" href="#">Method List</a>
50
+
51
+ <a id="file_list_link" href="#">File List</a>
52
+
53
+ </div>
54
+ <div class="clear"></div>
55
+ </div>
56
+
57
+ <iframe id="search_frame"></iframe>
58
+
59
+ <div id="content"><h1>Class: BindLogAnalyzer::Base
60
+
61
+
62
+
63
+ </h1>
64
+
65
+ <dl class="box">
66
+
67
+ <dt class="r1">Inherits:</dt>
68
+ <dd class="r1">
69
+ <span class="inheritName">Object</span>
70
+
71
+ <ul class="fullTree">
72
+ <li>Object</li>
73
+
74
+ <li class="next">BindLogAnalyzer::Base</li>
75
+
76
+ </ul>
77
+ <a href="#" class="inheritanceTree">show all</a>
78
+
79
+ </dd>
80
+
81
+
82
+
83
+
84
+
85
+
86
+ <dt class="r2">Includes:</dt>
87
+ <dd class="r2"><span class='object_link'><a href="Connector.html" title="BindLogAnalyzer::Connector (module)">Connector</a></span></dd>
88
+
89
+
90
+
91
+
92
+
93
+ <dt class="r1 last">Defined in:</dt>
94
+ <dd class="r1 last">lib/bind_log_analyzer/base.rb</dd>
95
+
96
+ </dl>
97
+ <div class="clear"></div>
98
+
99
+ <h2>Overview</h2><div class="docstring">
100
+ <div class="discussion">
101
+
102
+ <p>The main class of the BindLogAnalyzer module</p>
103
+
104
+
105
+ </div>
106
+ </div>
107
+ <div class="tags">
108
+
109
+
110
+ </div>
111
+
112
+
113
+
114
+ <h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
115
+ <ul class="summary">
116
+
117
+ <li class="public ">
118
+ <span class="summary_signature">
119
+
120
+ <a href="#database_confs-instance_method" title="#database_confs (instance method)">- (Hash) <strong>database_confs</strong> </a>
121
+
122
+
123
+
124
+ </span>
125
+
126
+
127
+ <span class="note title readonly">readonly</span>
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+ <span class="summary_desc"><div class='inline'>
137
+ <p>The hash containing the database params and credentials.</p>
138
+ </div></span>
139
+
140
+ </li>
141
+
142
+
143
+ <li class="public ">
144
+ <span class="summary_signature">
145
+
146
+ <a href="#log_filename-instance_method" title="#log_filename (instance method)">- (String) <strong>log_filename</strong> </a>
147
+
148
+
149
+
150
+ </span>
151
+
152
+
153
+ <span class="note title readonly">readonly</span>
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+ <span class="summary_desc"><div class='inline'>
163
+ <p>The file containing the logs to be analyzed.</p>
164
+ </div></span>
165
+
166
+ </li>
167
+
168
+
169
+ </ul>
170
+
171
+
172
+
173
+
174
+
175
+ <h2>
176
+ Instance Method Summary
177
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
178
+ </h2>
179
+
180
+ <ul class="summary">
181
+
182
+ <li class="public ">
183
+ <span class="summary_signature">
184
+
185
+ <a href="#analyze-instance_method" title="#analyze (instance method)">- (true, false) <strong>analyze</strong> </a>
186
+
187
+
188
+
189
+ </span>
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+ <span class="summary_desc"><div class='inline'>
199
+ <p>The main method used to manage the analysis operations.</p>
200
+ </div></span>
201
+
202
+ </li>
203
+
204
+
205
+ <li class="public ">
206
+ <span class="summary_signature">
207
+
208
+ <a href="#initialize-instance_method" title="#initialize (instance method)">- (Base) <strong>initialize</strong>(database_confs = nil, logfile = nil, setup_database = false, log_level = 0) </a>
209
+
210
+
211
+
212
+ </span>
213
+
214
+ <span class="note title constructor">constructor</span>
215
+
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
+ <span class="summary_desc"><div class='inline'>
224
+ <p>The constructor of BindLogAnalyzer::Base sets some vars and manages the
225
+ setup of the database.</p>
226
+ </div></span>
227
+
228
+ </li>
229
+
230
+
231
+ <li class="public ">
232
+ <span class="summary_signature">
233
+
234
+ <a href="#logfile-instance_method" title="#logfile (instance method)">- (String) <strong>logfile</strong> </a>
235
+
236
+
237
+
238
+ </span>
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+ <span class="summary_desc"><div class='inline'>
248
+ <p>Returns the path to the Bind's log file.</p>
249
+ </div></span>
250
+
251
+ </li>
252
+
253
+
254
+ <li class="public ">
255
+ <span class="summary_signature">
256
+
257
+ <a href="#logfile%3D-instance_method" title="#logfile= (instance method)">- (Object) <strong>logfile=</strong>(logfile) </a>
258
+
259
+
260
+
261
+ </span>
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+
270
+ <span class="summary_desc"><div class='inline'>
271
+ <p>Sets the path to the log file checking if exists.</p>
272
+ </div></span>
273
+
274
+ </li>
275
+
276
+
277
+ <li class="public ">
278
+ <span class="summary_signature">
279
+
280
+ <a href="#parse_line-instance_method" title="#parse_line (instance method)">- (Hash, false) <strong>parse_line</strong>(line) </a>
281
+
282
+
283
+
284
+ </span>
285
+
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+ <span class="summary_desc"><div class='inline'>
294
+ <p>Parses a log line and creates a hash with the informations.</p>
295
+ </div></span>
296
+
297
+ </li>
298
+
299
+
300
+ <li class="public ">
301
+ <span class="summary_signature">
302
+
303
+ <a href="#store_query-instance_method" title="#store_query (instance method)">- (Object) <strong>store_query</strong>(query) </a>
304
+
305
+
306
+
307
+ </span>
308
+
309
+
310
+
311
+
312
+
313
+
314
+
315
+
316
+ <span class="summary_desc"><div class='inline'>
317
+ <p>Stores the parsed log line into the database.</p>
318
+ </div></span>
319
+
320
+ </li>
321
+
322
+
323
+ </ul>
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+ <h3 class="inherited">Methods included from <span class='object_link'><a href="Connector.html" title="BindLogAnalyzer::Connector (module)">Connector</a></span></h3>
335
+ <p class="inherited"><span class='object_link'><a href="Connector.html#connect-instance_method" title="BindLogAnalyzer::Connector#connect (method)">#connect</a></span>, <span class='object_link'><a href="Connector.html#connected%3F-instance_method" title="BindLogAnalyzer::Connector#connected? (method)">#connected?</a></span>, <span class='object_link'><a href="Connector.html#load_environment-instance_method" title="BindLogAnalyzer::Connector#load_environment (method)">#load_environment</a></span>, <span class='object_link'><a href="Connector.html#migrate_tables-instance_method" title="BindLogAnalyzer::Connector#migrate_tables (method)">#migrate_tables</a></span>, <span class='object_link'><a href="Connector.html#setup_db-instance_method" title="BindLogAnalyzer::Connector#setup_db (method)">#setup_db</a></span></p>
336
+ <div id="constructor_details" class="method_details_list">
337
+ <h2>Constructor Details</h2>
338
+
339
+ <div class="method_details first">
340
+ <p class="signature first" id="initialize-instance_method">
341
+
342
+ - (<tt><span class='object_link'><a href="" title="BindLogAnalyzer::Base (class)">Base</a></span></tt>) <strong>initialize</strong>(database_confs = nil, logfile = nil, setup_database = false, log_level = 0)
343
+
344
+
345
+
346
+ </p><div class="docstring">
347
+ <div class="discussion">
348
+
349
+ <p>The constructor of BindLogAnalyzer::Base sets some vars and manages the
350
+ setup of the database</p>
351
+
352
+
353
+ </div>
354
+ </div>
355
+ <div class="tags">
356
+ <h3>Parameters:</h3>
357
+ <ul class="param">
358
+
359
+ <li>
360
+
361
+ <span class='name'>database_confs</span>
362
+
363
+
364
+ <span class='type'>(<tt>Hash</tt>, <tt>String</tt>)</span>
365
+
366
+
367
+ <em class="default">(defaults to: <tt>nil</tt>)</em>
368
+
369
+
370
+ &mdash;
371
+ <div class='inline'>
372
+ <p>The path to the database configurations file or a hash containing such
373
+ informations</p>
374
+ </div>
375
+
376
+ </li>
377
+
378
+ <li>
379
+
380
+ <span class='name'>logfile</span>
381
+
382
+
383
+ <span class='type'>(<tt>String</tt>)</span>
384
+
385
+
386
+ <em class="default">(defaults to: <tt>nil</tt>)</em>
387
+
388
+
389
+ &mdash;
390
+ <div class='inline'>
391
+ <p>The path to the file containing the Bind's logs to analyze</p>
392
+ </div>
393
+
394
+ </li>
395
+
396
+ <li>
397
+
398
+ <span class='name'>setup_database</span>
399
+
400
+
401
+ <span class='type'>(<tt>true</tt>, <tt>false</tt>)</span>
402
+
403
+
404
+ <em class="default">(defaults to: <tt>false</tt>)</em>
405
+
406
+
407
+ &mdash;
408
+ <div class='inline'>
409
+ <p>A flag which indicates whether to launch the database migration</p>
410
+ </div>
411
+
412
+ </li>
413
+
414
+ <li>
415
+
416
+ <span class='name'>log_level</span>
417
+
418
+
419
+ <span class='type'>(<tt>Integer</tt>)</span>
420
+
421
+
422
+ <em class="default">(defaults to: <tt>0</tt>)</em>
423
+
424
+
425
+ &mdash;
426
+ <div class='inline'>
427
+ <p>The level of the log requested by the user</p>
428
+ </div>
429
+
430
+ </li>
431
+
432
+ </ul>
433
+
434
+
435
+ </div><table class="source_code">
436
+ <tr>
437
+ <td>
438
+ <pre class="lines">
439
+
440
+
441
+ 22
442
+ 23
443
+ 24
444
+ 25
445
+ 26
446
+ 27
447
+ 28
448
+ 29
449
+ 30
450
+ 31
451
+ 32
452
+ 33
453
+ 34
454
+ 35
455
+ 36
456
+ 37
457
+ 38
458
+ 39
459
+ 40
460
+ 41
461
+ 42
462
+ 43
463
+ 44
464
+ 45
465
+ 46
466
+ 47</pre>
467
+ </td>
468
+ <td>
469
+ <pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line 22</span>
470
+
471
+ <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_database_confs'>database_confs</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_logfile'>logfile</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_setup_database'>setup_database</span> <span class='op'>=</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='id identifier rubyid_log_level'>log_level</span> <span class='op'>=</span> <span class='int'>0</span><span class='rparen'>)</span>
472
+ <span class='kw'>if</span> <span class='id identifier rubyid_database_confs'>database_confs</span>
473
+ <span class='kw'>if</span> <span class='id identifier rubyid_database_confs'>database_confs</span><span class='period'>.</span><span class='id identifier rubyid_instance_of?'>instance_of?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
474
+ <span class='ivar'>@database_confs</span> <span class='op'>=</span> <span class='id identifier rubyid_database_confs'>database_confs</span>
475
+ <span class='kw'>else</span>
476
+ <span class='comment'># Load the yaml file
477
+ </span> <span class='kw'>if</span> <span class='const'>FileTest</span><span class='period'>.</span><span class='id identifier rubyid_exists?'>exists?</span><span class='lparen'>(</span><span class='id identifier rubyid_database_confs'>database_confs</span><span class='rparen'>)</span>
478
+ <span class='ivar'>@database_confs</span> <span class='op'>=</span> <span class='const'>YAML</span><span class='op'>::</span><span class='id identifier rubyid_load'>load</span><span class='lparen'>(</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='id identifier rubyid_database_confs'>database_confs</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>database</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span>
479
+ <span class='kw'>else</span>
480
+ <span class='id identifier rubyid_raise'>raise</span> <span class='const'>BindLogAnalyzer</span><span class='op'>::</span><span class='const'>DatabaseConfsNotValid</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>The indicated YAML file doesn't exist or is invalid</span><span class='tstring_end'>&quot;</span></span>
481
+ <span class='kw'>end</span>
482
+ <span class='kw'>end</span>
483
+ <span class='kw'>else</span>
484
+ <span class='comment'># Tries to find the yaml file or prints an error
485
+ </span> <span class='id identifier rubyid_filename'>filename</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>database.yml</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
486
+ <span class='kw'>if</span> <span class='const'>FileTest</span><span class='period'>.</span><span class='id identifier rubyid_exists?'>exists?</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span><span class='rparen'>)</span>
487
+ <span class='ivar'>@database_confs</span> <span class='op'>=</span> <span class='const'>YAML</span><span class='op'>::</span><span class='id identifier rubyid_load'>load</span><span class='lparen'>(</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>database</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span>
488
+ <span class='kw'>else</span>
489
+ <span class='id identifier rubyid_raise'>raise</span> <span class='const'>BindLogAnalyzer</span><span class='op'>::</span><span class='const'>DatabaseConfsNotValid</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Can't find valid database configurations</span><span class='tstring_end'>&quot;</span></span>
490
+ <span class='kw'>end</span>
491
+ <span class='kw'>end</span>
492
+
493
+ <span class='ivar'>@stored_queries</span> <span class='op'>=</span> <span class='int'>0</span>
494
+ <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_logfile'>logfile</span> <span class='op'>=</span> <span class='id identifier rubyid_logfile'>logfile</span> <span class='kw'>if</span> <span class='id identifier rubyid_logfile'>logfile</span>
495
+ <span class='id identifier rubyid_setup_db'>setup_db</span><span class='lparen'>(</span><span class='ivar'>@database_confs</span><span class='comma'>,</span> <span class='id identifier rubyid_setup_database'>setup_database</span><span class='comma'>,</span> <span class='id identifier rubyid_log_level'>log_level</span><span class='rparen'>)</span>
496
+ <span class='kw'>end</span></pre>
497
+ </td>
498
+ </tr>
499
+ </table>
500
+ </div>
501
+
502
+ </div>
503
+
504
+ <div id="instance_attr_details" class="attr_details">
505
+ <h2>Instance Attribute Details</h2>
506
+
507
+
508
+ <span id=""></span>
509
+ <span id="database_confs-instance_method"></span>
510
+ <div class="method_details first">
511
+ <p class="signature first" id="database_confs-instance_method">
512
+
513
+ - (<tt>Hash</tt>) <strong>database_confs</strong> <span class="extras">(readonly)</span>
514
+
515
+
516
+
517
+ </p><div class="docstring">
518
+ <div class="discussion">
519
+
520
+ <p>The hash containing the database params and credentials</p>
521
+
522
+
523
+ </div>
524
+ </div>
525
+ <div class="tags">
526
+
527
+ <h3>Returns:</h3>
528
+ <ul class="return">
529
+
530
+ <li>
531
+
532
+
533
+ <span class='type'>(<tt>Hash</tt>)</span>
534
+
535
+
536
+
537
+ &mdash;
538
+ <div class='inline'>
539
+ <p>The hash containing the database params and credentials</p>
540
+ </div>
541
+
542
+ </li>
543
+
544
+ </ul>
545
+
546
+ </div><table class="source_code">
547
+ <tr>
548
+ <td>
549
+ <pre class="lines">
550
+
551
+
552
+ 15
553
+ 16
554
+ 17</pre>
555
+ </td>
556
+ <td>
557
+ <pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line 15</span>
558
+
559
+ <span class='kw'>def</span> <span class='id identifier rubyid_database_confs'>database_confs</span>
560
+ <span class='ivar'>@database_confs</span>
561
+ <span class='kw'>end</span></pre>
562
+ </td>
563
+ </tr>
564
+ </table>
565
+ </div>
566
+
567
+
568
+ <span id=""></span>
569
+ <span id="log_filename-instance_method"></span>
570
+ <div class="method_details ">
571
+ <p class="signature " id="log_filename-instance_method">
572
+
573
+ - (<tt>String</tt>) <strong>log_filename</strong> <span class="extras">(readonly)</span>
574
+
575
+
576
+
577
+ </p><div class="docstring">
578
+ <div class="discussion">
579
+
580
+ <p>The file containing the logs to be analyzed</p>
581
+
582
+
583
+ </div>
584
+ </div>
585
+ <div class="tags">
586
+
587
+ <h3>Returns:</h3>
588
+ <ul class="return">
589
+
590
+ <li>
591
+
592
+
593
+ <span class='type'>(<tt>String</tt>)</span>
594
+
595
+
596
+
597
+ &mdash;
598
+ <div class='inline'>
599
+ <p>The file containing the logs to be analyzed</p>
600
+ </div>
601
+
602
+ </li>
603
+
604
+ </ul>
605
+
606
+ </div><table class="source_code">
607
+ <tr>
608
+ <td>
609
+ <pre class="lines">
610
+
611
+
612
+ 12
613
+ 13
614
+ 14</pre>
615
+ </td>
616
+ <td>
617
+ <pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line 12</span>
618
+
619
+ <span class='kw'>def</span> <span class='id identifier rubyid_log_filename'>log_filename</span>
620
+ <span class='ivar'>@log_filename</span>
621
+ <span class='kw'>end</span></pre>
622
+ </td>
623
+ </tr>
624
+ </table>
625
+ </div>
626
+
627
+ </div>
628
+
629
+
630
+ <div id="instance_method_details" class="method_details_list">
631
+ <h2>Instance Method Details</h2>
632
+
633
+
634
+ <div class="method_details first">
635
+ <p class="signature first" id="analyze-instance_method">
636
+
637
+ - (<tt>true</tt>, <tt>false</tt>) <strong>analyze</strong>
638
+
639
+
640
+
641
+ </p><div class="docstring">
642
+ <div class="discussion">
643
+
644
+ <p>The main method used to manage the analysis operations. Opens the log file
645
+ and passes wvery line to #parse_line and #store_query</p>
646
+
647
+
648
+ </div>
649
+ </div>
650
+ <div class="tags">
651
+
652
+ <h3>Returns:</h3>
653
+ <ul class="return">
654
+
655
+ <li>
656
+
657
+
658
+ <span class='type'>(<tt>true</tt>, <tt>false</tt>)</span>
659
+
660
+
661
+
662
+ &mdash;
663
+ <div class='inline'>
664
+ <p>False if there's a problem with the log file. True elsewhere.</p>
665
+ </div>
666
+
667
+ </li>
668
+
669
+ </ul>
670
+
671
+ </div><table class="source_code">
672
+ <tr>
673
+ <td>
674
+ <pre class="lines">
675
+
676
+
677
+ 96
678
+ 97
679
+ 98
680
+ 99
681
+ 100
682
+ 101
683
+ 102
684
+ 103
685
+ 104
686
+ 105
687
+ 106
688
+ 107
689
+ 108
690
+ 109</pre>
691
+ </td>
692
+ <td>
693
+ <pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line 96</span>
694
+
695
+ <span class='kw'>def</span> <span class='id identifier rubyid_analyze'>analyze</span>
696
+ <span class='kw'>return</span> <span class='kw'>false</span> <span class='kw'>unless</span> <span class='ivar'>@log_filename</span>
697
+
698
+ <span class='id identifier rubyid_lines'>lines</span> <span class='op'>=</span> <span class='int'>0</span>
699
+ <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='ivar'>@log_filename</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_line'>line</span><span class='op'>|</span>
700
+ <span class='id identifier rubyid_query'>query</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_parse_line'>parse_line</span><span class='lparen'>(</span><span class='id identifier rubyid_line'>line</span><span class='rparen'>)</span>
701
+ <span class='kw'>if</span> <span class='id identifier rubyid_query'>query</span>
702
+ <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_store_query'>store_query</span><span class='lparen'>(</span><span class='id identifier rubyid_query'>query</span><span class='rparen'>)</span>
703
+ <span class='id identifier rubyid_lines'>lines</span> <span class='op'>+=</span> <span class='int'>1</span>
704
+ <span class='kw'>end</span>
705
+ <span class='kw'>end</span>
706
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Analyzed </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_lines'>lines</span><span class='rbrace'>}</span><span class='tstring_content'> lines and correctly stored </span><span class='embexpr_beg'>#{</span><span class='ivar'>@stored_queries</span><span class='rbrace'>}</span><span class='tstring_content'> logs</span><span class='tstring_end'>&quot;</span></span>
707
+ <span class='kw'>return</span> <span class='kw'>true</span>
708
+ <span class='kw'>end</span></pre>
709
+ </td>
710
+ </tr>
711
+ </table>
712
+ </div>
713
+
714
+ <div class="method_details ">
715
+ <p class="signature " id="logfile-instance_method">
716
+
717
+ - (<tt>String</tt>) <strong>logfile</strong>
718
+
719
+
720
+
721
+ </p><div class="docstring">
722
+ <div class="discussion">
723
+
724
+ <p>Returns the path to the Bind's log file</p>
725
+
726
+
727
+ </div>
728
+ </div>
729
+ <div class="tags">
730
+
731
+ <h3>Returns:</h3>
732
+ <ul class="return">
733
+
734
+ <li>
735
+
736
+
737
+ <span class='type'>(<tt>String</tt>)</span>
738
+
739
+
740
+
741
+ &mdash;
742
+ <div class='inline'>
743
+ <p>The path to the Bind's log file</p>
744
+ </div>
745
+
746
+ </li>
747
+
748
+ </ul>
749
+
750
+ </div><table class="source_code">
751
+ <tr>
752
+ <td>
753
+ <pre class="lines">
754
+
755
+
756
+ 57
757
+ 58
758
+ 59</pre>
759
+ </td>
760
+ <td>
761
+ <pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line 57</span>
762
+
763
+ <span class='kw'>def</span> <span class='id identifier rubyid_logfile'>logfile</span>
764
+ <span class='ivar'>@log_filename</span>
765
+ <span class='kw'>end</span></pre>
766
+ </td>
767
+ </tr>
768
+ </table>
769
+ </div>
770
+
771
+ <div class="method_details ">
772
+ <p class="signature " id="logfile=-instance_method">
773
+
774
+ - (<tt>Object</tt>) <strong>logfile=</strong>(logfile)
775
+
776
+
777
+
778
+ </p><div class="docstring">
779
+ <div class="discussion">
780
+
781
+ <p>Sets the path to the log file checking if exists</p>
782
+
783
+
784
+ </div>
785
+ </div>
786
+ <div class="tags">
787
+ <h3>Parameters:</h3>
788
+ <ul class="param">
789
+
790
+ <li>
791
+
792
+ <span class='name'>logfile</span>
793
+
794
+
795
+ <span class='type'>(<tt>String</tt>)</span>
796
+
797
+
798
+
799
+ &mdash;
800
+ <div class='inline'>
801
+ <p>The path to the file containing the Bind's logs to analyze</p>
802
+ </div>
803
+
804
+ </li>
805
+
806
+ </ul>
807
+
808
+
809
+ </div><table class="source_code">
810
+ <tr>
811
+ <td>
812
+ <pre class="lines">
813
+
814
+
815
+ 51
816
+ 52
817
+ 53</pre>
818
+ </td>
819
+ <td>
820
+ <pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line 51</span>
821
+
822
+ <span class='kw'>def</span> <span class='id identifier rubyid_logfile='>logfile=</span><span class='lparen'>(</span><span class='id identifier rubyid_logfile'>logfile</span><span class='rparen'>)</span>
823
+ <span class='ivar'>@log_filename</span> <span class='op'>=</span> <span class='id identifier rubyid_logfile'>logfile</span> <span class='kw'>if</span> <span class='const'>FileTest</span><span class='period'>.</span><span class='id identifier rubyid_exists?'>exists?</span><span class='lparen'>(</span><span class='id identifier rubyid_logfile'>logfile</span><span class='rparen'>)</span>
824
+ <span class='kw'>end</span></pre>
825
+ </td>
826
+ </tr>
827
+ </table>
828
+ </div>
829
+
830
+ <div class="method_details ">
831
+ <p class="signature " id="parse_line-instance_method">
832
+
833
+ - (<tt>Hash</tt>, <tt>false</tt>) <strong>parse_line</strong>(line)
834
+
835
+
836
+
837
+ </p><div class="docstring">
838
+ <div class="discussion">
839
+
840
+ <p>Parses a log line and creates a hash with the informations</p>
841
+
842
+
843
+ </div>
844
+ </div>
845
+ <div class="tags">
846
+ <h3>Parameters:</h3>
847
+ <ul class="param">
848
+
849
+ <li>
850
+
851
+ <span class='name'>line</span>
852
+
853
+
854
+ <span class='type'>(<tt>String</tt>)</span>
855
+
856
+
857
+
858
+ &mdash;
859
+ <div class='inline'>
860
+ <p>The query log line to parse</p>
861
+ </div>
862
+
863
+ </li>
864
+
865
+ </ul>
866
+
867
+ <h3>Returns:</h3>
868
+ <ul class="return">
869
+
870
+ <li>
871
+
872
+
873
+ <span class='type'>(<tt>Hash</tt>, <tt>false</tt>)</span>
874
+
875
+
876
+
877
+ &mdash;
878
+ <div class='inline'>
879
+ <p>The hash containing the parsed line or false if the line couldn't be parsed</p>
880
+ </div>
881
+
882
+ </li>
883
+
884
+ </ul>
885
+
886
+ </div><table class="source_code">
887
+ <tr>
888
+ <td>
889
+ <pre class="lines">
890
+
891
+
892
+ 64
893
+ 65
894
+ 66
895
+ 67
896
+ 68
897
+ 69
898
+ 70
899
+ 71
900
+ 72
901
+ 73
902
+ 74
903
+ 75
904
+ 76
905
+ 77
906
+ 78
907
+ 79
908
+ 80
909
+ 81
910
+ 82
911
+ 83
912
+ 84</pre>
913
+ </td>
914
+ <td>
915
+ <pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line 64</span>
916
+
917
+ <span class='kw'>def</span> <span class='id identifier rubyid_parse_line'>parse_line</span><span class='lparen'>(</span><span class='id identifier rubyid_line'>line</span><span class='rparen'>)</span>
918
+ <span class='id identifier rubyid_query'>query</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
919
+ <span class='id identifier rubyid_regexp'>regexp</span> <span class='op'>=</span> <span class='tstring'><span class='regexp_beg'>%r{</span><span class='tstring_content'>^(\d{2}-\w{3}-\d{4}\s+\d{2}:\d{2}:\d{2}\.\d{3})\s+client\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})#\d+:\s+query:\s+(.*)\s+IN\s+(\w+)\s+\+\s+\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\)$</span><span class='regexp_end'>}</span></span>
920
+
921
+ <span class='id identifier rubyid_parsed_line'>parsed_line</span> <span class='op'>=</span> <span class='id identifier rubyid_line'>line</span><span class='period'>.</span><span class='id identifier rubyid_scan'>scan</span><span class='lparen'>(</span><span class='id identifier rubyid_regexp'>regexp</span><span class='rparen'>)</span>
922
+ <span class='kw'>if</span> <span class='id identifier rubyid_parsed_line'>parsed_line</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span> <span class='op'>&gt;</span> <span class='int'>0</span>
923
+ <span class='comment'># Parse timestamp
924
+ </span> <span class='id identifier rubyid_parsed_timestamp'>parsed_timestamp</span> <span class='op'>=</span> <span class='const'>Date</span><span class='period'>.</span><span class='id identifier rubyid__strptime'>_strptime</span><span class='lparen'>(</span><span class='id identifier rubyid_parsed_line'>parsed_line</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>%d-%b-%Y %H:%M:%S.%L</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
925
+ <span class='id identifier rubyid_query_time'>query_time</span> <span class='op'>=</span> <span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_local'>local</span><span class='lparen'>(</span><span class='id identifier rubyid_parsed_timestamp'>parsed_timestamp</span><span class='lbracket'>[</span><span class='symbol'>:year</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_parsed_timestamp'>parsed_timestamp</span><span class='lbracket'>[</span><span class='symbol'>:mon</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_parsed_timestamp'>parsed_timestamp</span><span class='lbracket'>[</span><span class='symbol'>:mday</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_parsed_timestamp'>parsed_timestamp</span><span class='lbracket'>[</span><span class='symbol'>:hour</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_parsed_timestamp'>parsed_timestamp</span><span class='lbracket'>[</span><span class='symbol'>:min</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_parsed_timestamp'>parsed_timestamp</span><span class='lbracket'>[</span><span class='symbol'>:sec</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_parsed_timestamp'>parsed_timestamp</span><span class='lbracket'>[</span><span class='symbol'>:sec_fraction</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_parsed_timestamp'>parsed_timestamp</span><span class='lbracket'>[</span><span class='symbol'>:zone</span><span class='rbracket'>]</span><span class='rparen'>)</span>
926
+
927
+ <span class='id identifier rubyid_query'>query</span><span class='lbracket'>[</span><span class='symbol'>:date</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_query_time'>query_time</span>
928
+ <span class='id identifier rubyid_query'>query</span><span class='lbracket'>[</span><span class='symbol'>:client</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_parsed_line'>parsed_line</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span>
929
+ <span class='id identifier rubyid_query'>query</span><span class='lbracket'>[</span><span class='symbol'>:query</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_parsed_line'>parsed_line</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='int'>2</span><span class='rbracket'>]</span>
930
+ <span class='id identifier rubyid_query'>query</span><span class='lbracket'>[</span><span class='symbol'>:q_type</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_parsed_line'>parsed_line</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='int'>3</span><span class='rbracket'>]</span>
931
+ <span class='id identifier rubyid_query'>query</span><span class='lbracket'>[</span><span class='symbol'>:server</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_parsed_line'>parsed_line</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='int'>4</span><span class='rbracket'>]</span>
932
+
933
+ <span class='id identifier rubyid_query'>query</span>
934
+ <span class='kw'>else</span>
935
+ <span class='kw'>false</span>
936
+ <span class='kw'>end</span>
937
+ <span class='kw'>end</span></pre>
938
+ </td>
939
+ </tr>
940
+ </table>
941
+ </div>
942
+
943
+ <div class="method_details ">
944
+ <p class="signature " id="store_query-instance_method">
945
+
946
+ - (<tt>Object</tt>) <strong>store_query</strong>(query)
947
+
948
+
949
+
950
+ </p><div class="docstring">
951
+ <div class="discussion">
952
+
953
+ <p>Stores the parsed log line into the database. Increments @stored_queries if
954
+ successful</p>
955
+
956
+
957
+ </div>
958
+ </div>
959
+ <div class="tags">
960
+ <h3>Parameters:</h3>
961
+ <ul class="param">
962
+
963
+ <li>
964
+
965
+ <span class='name'>query</span>
966
+
967
+
968
+ <span class='type'>(<tt>Hash</tt>)</span>
969
+
970
+
971
+
972
+ &mdash;
973
+ <div class='inline'>
974
+ <p>The log line parsed by #parse_line</p>
975
+ </div>
976
+
977
+ </li>
978
+
979
+ </ul>
980
+
981
+
982
+ </div><table class="source_code">
983
+ <tr>
984
+ <td>
985
+ <pre class="lines">
986
+
987
+
988
+ 88
989
+ 89
990
+ 90
991
+ 91</pre>
992
+ </td>
993
+ <td>
994
+ <pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line 88</span>
995
+
996
+ <span class='kw'>def</span> <span class='id identifier rubyid_store_query'>store_query</span><span class='lparen'>(</span><span class='id identifier rubyid_query'>query</span><span class='rparen'>)</span>
997
+ <span class='id identifier rubyid_log'>log</span> <span class='op'>=</span> <span class='const'>Log</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_query'>query</span><span class='rparen'>)</span>
998
+ <span class='ivar'>@stored_queries</span> <span class='op'>+=</span> <span class='int'>1</span> <span class='kw'>if</span> <span class='id identifier rubyid_log'>log</span><span class='period'>.</span><span class='id identifier rubyid_save'>save</span>
999
+ <span class='kw'>end</span></pre>
1000
+ </td>
1001
+ </tr>
1002
+ </table>
1003
+ </div>
1004
+
1005
+ </div>
1006
+
1007
+ </div>
1008
+
1009
+ <div id="footer">
1010
+ Generated on Tue Apr 3 17:01:09 2012 by
1011
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1012
+ 0.7.5 (ruby-1.9.3).
1013
+ </div>
1014
+
1015
+ </body>
1016
+ </html>