Class: MysqlStatistics

Inherits:
JsonTail::Parser show all
Defined in:
lib/json_tail/parsers/mysql-statistics.rb

Constant Summary collapse

ENTRIES =
["SELECT", "INSERT", "DELETE", "UPDATE"]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from JsonTail::Parser

inherited, registry, report

Constructor Details

#initialize(filename) ⇒ MysqlStatistics

Returns a new instance of MysqlStatistics.



11
12
13
14
15
16
17
# File 'lib/json_tail/parsers/mysql-statistics.rb', line 11

def initialize(filename)
  @filename = filename
  @com_select = 0
  @com_insert = 0
  @com_delete = 0
  @com_update = 0
end

Instance Attribute Details

#com_deleteObject

Returns the value of attribute com_delete.



8
9
10
# File 'lib/json_tail/parsers/mysql-statistics.rb', line 8

def com_delete
  @com_delete
end

#com_insertObject

Returns the value of attribute com_insert.



8
9
10
# File 'lib/json_tail/parsers/mysql-statistics.rb', line 8

def com_insert
  @com_insert
end

#com_selectObject

Returns the value of attribute com_select.



8
9
10
# File 'lib/json_tail/parsers/mysql-statistics.rb', line 8

def com_select
  @com_select
end

#com_updateObject

Returns the value of attribute com_update.



8
9
10
# File 'lib/json_tail/parsers/mysql-statistics.rb', line 8

def com_update
  @com_update
end

Class Method Details

.build_report(options) ⇒ Object



51
52
53
54
55
56
# File 'lib/json_tail/parsers/mysql-statistics.rb', line 51

def build_report(options)
  mm = self.new(options['filename'])
  content = { "com_select" => mm.com_select, "com_insert" => mm.com_insert, "com_delete" => mm.com_delete, "com_update" => mm.com_update }
  report(options['parser'], content)
  mm.start
end

Instance Method Details

#resetObject



42
43
44
45
46
47
# File 'lib/json_tail/parsers/mysql-statistics.rb', line 42

def reset
  @com_select = 0
  @com_insert = 0
  @com_delete = 0
  @com_update = 0
end

#startObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/json_tail/parsers/mysql-statistics.rb', line 19

def start
  File.open(@filename) do |log|
    log.extend(File::Tail)
    log.interval = 10
    log.tail do |line|
      ENTRIES.each do |e|
        if line.include? e
          case e
          when "SELECT"
            @com_select += 1
          when "INSERT"
            @com_insert += 1
          when "DELETE"
            @com_delete += 1
          when "UPDATE"
            @com_update += 1
          end
        end
      end
    end
  end
end