-
Notifications
You must be signed in to change notification settings - Fork 0
/
logpusher
executable file
·111 lines (85 loc) · 2.75 KB
/
logpusher
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
52
53
54
55
56
57
58
59
60
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
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env ruby
require 'optparse'
require "./src/util/util.rb"
require "./src/util/rolling_aggregate.rb"
require "./src/upload_stats.rb"
require "./src/logfile_pusher.rb"
require "./src/eventql_uploader.rb"
require "./src/sqlite_uploader.rb"
require "./src/mongo_uploader.rb"
require "./src/postgresql_uploader.rb"
logfile_pusher = nil
storage_engines = {
"eventql" => EventQLUploader,
"sqlite" => SQLiteUploader,
"mongo" => MongoUploader,
"postgresql" => PostgreSQLUploader
}
# parse arguments
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: $ logpusher [OPTIONS]"
opts.on("-f", "--file <file>", "Set the path of the logfile to import") do |f|
options[:file] = f
end
opts.on("-r", "--regex <REGEX>", "Set the regex") do |r|
options[:regex] = r
end
opts.on("-s", "--storage <engine>", "Set the storage engine") do |s|
options[:storage] = s
end
opts.on("-c", "--connections <num>", "Set the number of concurrent connections") do |c|
options[:connections] = c
end
opts.on(NIL, "--batch_size <num>", "Set the batch size") do |batch_size|
options[:batch_size] = batch_size
end
opts.on("-d", "--database <db>", "Select a database") do |d|
options[:db] = d
end
opts.on("-t", "--table <tbl>", "Select a destination table") do |t|
options[:table] = t
end
opts.on("-h", "--host <hostname>", "Set the hostname of the storage engine") do |h|
options[:host] = h
end
opts.on("-p", "--port <port>", "Set the port of the storage engine") do |p|
options[:port] = p
end
opts.on("-u", "--user <username>", "Set the username of the storage engine") do |u|
options[:user] = u
end
opts.on("-q", "--quiet", "Run quietly") do |q|
options[:quiet] = q
end
opts.on("-?", "--help", "Display this help text and exit") do
$stderr.puts opts
exit
end
end.parse!
mandatory_args = [:file, :regex, :storage]
missing = mandatory_args.select{ |param| options[param].nil? }
unless missing.empty?
$stderr.puts "ERROR: missing arguments: #{missing.join(', ')}. Run logpusher.rb --help for help"
exit
end
begin
unless storage_engines.has_key?(options[:storage])
$stderr.puts "ERROR: unknown storage engine #{options[:storage]}"
exit 1
end
mandatory_args = storage_engines[options[:storage]].mandatory_args()
missing = mandatory_args.select{ |param| options[param].nil? }
unless missing.empty?
raise "missing arguments: #{missing.join(', ')}. Run logpusher.rb --help for help"
end
storage_engine = storage_engines[options[:storage]].new(options)
logfile_pusher = LogfilePusher.new(storage_engine, options)
logfile_pusher.run
rescue SystemExit, Interrupt
rescue
$stderr.puts "ERROR: #{$!} \n"
ensure
logfile_pusher.stop unless logfile_pusher.nil?
Kernel::exit
end