Class: PQA

Inherits:
Object
  • Object
show all
Defined in:
lib/pqa.rb

Class Method Summary collapse

Class Method Details

.pqa_usageObject



7
8
9
10
11
12
13
14
# File 'lib/pqa.rb', line 7

def PQA.pqa_usage
  puts "=============================="
  puts "Usage: " + $0 + " [-logtype syslog|pglog|mysql] [-top n] [-normalize] [-format text|html] [-reports rep1,rep2,...,repn] -file log_file_name"
  puts "Report types : overall, bytype, mosttime, slowest, mostfrequent, errors"
  puts "For example:"
  puts "ruby pqa.rb -logtype pglog -top 10 -normalize -format text -reports overall,slowest ../sample/pglog_sample.log"
  puts "=============================="
end

.runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pqa.rb', line 15

def PQA.run
  (PQA.pqa_usage ; exit) if ARGV == nil 
  if !ARGV.include?("-file")
  puts "=============================="
    puts "## No log file specified; use the '-file' parameter"
    pqa_usage ; exit
  end
  log = nil
  if ARGV.include?("-logtype") && ARGV[ARGV.index("-logtype")+1] == "syslog"
    log = GenericLogReader.new(ARGV[ARGV.index("-file")+1], "SyslogPGParser", "PostgreSQLAccumulator")
  elsif ARGV.include?("-logtype") && ARGV[ARGV.index("-logtype")+1] == "mysql"
    log = GenericLogReader.new(ARGV[ARGV.index("-file")+1], "MySQLLogLine", "MySQLAccumulator")
  else
    log = GenericLogReader.new(ARGV[ARGV.index("-file")+1], "PostgresLogParser", "PostgreSQLAccumulator")
  end
  log.parse
  log.normalize if ARGV.include?("-normalize")  
  top = (ARGV.include?("-top") ? ARGV[ARGV.index("-top")+1] : DEFAULT_TOP).to_i
  format = (ARGV.include?("-format") ? ARGV[ARGV.index("-format")+1] : "text")

  rpts = []
  if ARGV.include?("-reports")
    reports_array = ARGV[ARGV.index("-reports")+1].split(',')
    rpts.push(OverallStatsReport.new(log)) if reports_array.include?("overall")
    rpts.push(QueriesByTypeReport.new(log)) if reports_array.include?("bytype")
    rpts.push(QueriesThatTookUpTheMostTimeReport.new(log,top)) if reports_array.include?("mosttime")
    rpts.push(SlowestQueriesReport.new(log, top)) if reports_array.include?("slowest")
    rpts.push(MostFrequentQueriesReport.new(log, top)) if reports_array.include?("mostfrequent")
    rpts.push(ErrorReport.new(log)) if reports_array.include?("errors")
    #rpts.push() if reports_array.include?("")
    rpts.push(ParseErrorReport.new(log))
  else
    rpts = [OverallStatsReport.new(log), QueriesByTypeReport.new(log), QueriesThatTookUpTheMostTimeReport.new(log, top), SlowestQueriesReport.new(log, top), MostFrequentQueriesReport.new(log, top), ParseErrorReport.new(log)] 
  end
  report_aggregator = (format == "text") ? TextReportAggregator.new : HTMLReportAggregator.new
  puts report_aggregator.create(rpts)
end