-
Notifications
You must be signed in to change notification settings - Fork 5
/
import_syslog.rb
executable file
·53 lines (48 loc) · 1.35 KB
/
import_syslog.rb
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
#!/usr/bin/env ruby
require './config/environment.rb'
def process_logs
Event.resetStats # reset event timing counters
pending_logs = Dir['*'].sort
processed = 0
lines = 0
begin
pending_logs.each do |log|
processed += 1
puts "Processing #{log}: Log #{processed} out of #{pending_logs.count}" if processed % 50 == 0
File.foreach(log) do |line|
begin
lines += 1
Event.storeEvent(line)
rescue Exception => e
puts "Error processing #{log}!"
puts e
puts "Offending line: #{line}"
Event.performPendingInserts
exit
end
end
File.rename(log, "../ProcessedLogs/#{log}")
end
rescue Interrupt
puts "\nHalting operations... Emptying memory queues..."
Event.performPendingInserts
end
Event.performPendingInserts
Statistic.logLinesProcessed(lines)
end
def purge_logs
# Purge logs older than 1 day ago from now.
#system("cd ../ProcessedLogs;find . -mtime +1 | xargs rm -Rf")
# -mtime +1 means modified more than 1 day ago.
end
Dir.chdir("Logs/LogsToProcess")
referenceTime = Time.now - 13.hours #force a purge when importer first runs
while true do
process_logs
if Time.now-12.hours > referenceTime then
puts "Purged logs older than: #{Time.now}"
referenceTime = Time.now
purge_logs
end
sleep(1.minute)
end