Class: Ralf

Inherits:
Object
  • Object
show all
Defined in:
lib/ralf/version.rb,
lib/ralf.rb,
lib/ralf/log.rb,
lib/ralf/bucket.rb,
lib/ralf/interpolation.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Bucket, ClfTranslator, Config, Interpolation, Log, OptionParser

Constant Summary collapse

ROOT_DEFAULT_CONFIG_FILE =
'/etc/ralf.conf'
USER_DEFAULT_CONFIG_FILE =
'~/.ralf.conf'
VERSION =
"1.1.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Ralf

Create new Ralf instance



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ralf.rb', line 43

def initialize(options = {})
  initial_options = options.dup

  @config = load_config(initial_options.delete(:config_file))
  
  config.merge!(initial_options)
  config.validate!
  
  RightAws::RightAwsBaseInterface.caching = true # enable caching to speed up
  Bucket.s3 = RightAws::S3.new(config.aws_access_key_id, config.aws_secret_access_key,
    :protocol => 'http', :port => 80,
    :logger => Logger.new('aws' == config.debug? ? $stdout : StringIO.new)
  )
end

Instance Attribute Details

#configObject (readonly)

The current configuration.



25
26
27
# File 'lib/ralf.rb', line 25

def config
  @config
end

#s3Object (readonly)

Instance of RightAws::S3 used by Ralf to talk to Amazon S3.



28
29
30
# File 'lib/ralf.rb', line 28

def s3
  @s3
end

Class Method Details

.run(options) ⇒ Object

Create instance and run with the specified parameters



31
32
33
34
35
36
37
38
39
40
# File 'lib/ralf.rb', line 31

def self.run(options)
  list = options.delete(:list)

  ralf = Ralf.new(options)
  if list
    ralf.list
  else
    ralf.run
  end
end

Instance Method Details

#list(with_logging = false) ⇒ Object

List all buckets with the logging info.



100
101
102
103
104
105
106
107
108
109
# File 'lib/ralf.rb', line 100

def list(with_logging = false)
  puts "Listing buckets..." if config.debug?
  
  Bucket.each(config.buckets, with_logging) do |bucket|
    print "#{bucket.name}"
    puts bucket.logging_enabled? ? " [#{bucket.targetbucket}/#{bucket.targetprefix}]" : " [-]"
  end

  nil
end

#run(output_file = nil) ⇒ Object

For all buckets for all dates in the configured range download the available log files. After downloading, merge the log files and convert the format from Amazon Log Format to Apache Common Log Format.

Raises:

  • (ArgumentError)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ralf.rb', line 61

def run(output_file = nil)
  config.output_file = output_file unless output_file.nil?
  
  raise ArgumentError.new("--output-file required") if config.output_file_missing?
  raise ArgumentError.new("--output-file requires ':bucket' variable") if (config.buckets.nil? || config.buckets.size > 1) and !(config.output_file_format =~ /:bucket/)
  
  puts "Processing range #{config.range}" if config.debug?

  # iterate over all buckets
  Bucket.each(config.buckets) do |bucket|
    
    print "#{bucket.name}: " if config.debug?

    # iterate over the full range
    log_files = []
    config.range.each do |date|
      dir = config.cache_dir(:bucket => bucket.name, :date => date)
      log_files << Ralf.download_logs(bucket, date, dir)
    end
    log_files.flatten!

    # determine output file names
    output_log = config.output_file(:date => config.range.end, :bucket => bucket.name)
    merged_log =  output_log + ".alf"

    # create directory for output file
    FileUtils.mkdir_p(File.dirname(merged_log))

    # merge the log files
    Ralf.merge(merged_log, log_files)
    
    # convert to common log format
    Ralf.convert_to_common_log_format(merged_log, output_log, config.translate_options)

    puts "#{log_files.size} files" if config.debug?
  end
end