rforward 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rforward/config.rb +6 -1
- data/lib/rforward/ffluentd_line.rb +11 -0
- data/lib/rforward/file_processor.rb +10 -0
- data/lib/rforward/stat.rb +2 -2
- data/lib/rforward/version.rb +1 -1
- data/lib/rforward.rb +5 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9f7548dcc4d9f4012d9098335e6c06c5e105b812
|
|
4
|
+
data.tar.gz: 467cce2e9839510f5691b44a9d729843551aadd5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1c78ce72a5d8dc00eead64a2f29c18dea7f74b498a656e8fc1ea72d93586a91bf7151f02a2c449d73749d03fdf665fbdc918cf68f59e45782008924a8f46b057
|
|
7
|
+
data.tar.gz: da5cea88320a45468c48ef986cf462fdfb7e3c946f72e8804633aaf718a33b670c13b6486ae60d464d0b5a30b7043841d8303cf4132b7d9fcda3655d4387ca5d
|
data/Gemfile.lock
CHANGED
data/lib/rforward/config.rb
CHANGED
|
@@ -29,7 +29,12 @@ class Config
|
|
|
29
29
|
hash = {
|
|
30
30
|
'fluentd_host' => 'localhost',
|
|
31
31
|
'fluentd_port' => '24224',
|
|
32
|
-
'tag' => 'event'
|
|
32
|
+
'tag' => 'event',
|
|
33
|
+
'flush_delay' => '20',
|
|
34
|
+
'flush_threshold' => '100000',
|
|
35
|
+
'time_key' => 'time',
|
|
36
|
+
'time_format' => '%Y-%m-%dT%H:%M:%S%z',
|
|
37
|
+
'index_key' => 'index_key'
|
|
33
38
|
}
|
|
34
39
|
end
|
|
35
40
|
end
|
|
@@ -10,12 +10,23 @@ class FFluentdLine
|
|
|
10
10
|
def call line
|
|
11
11
|
Stat.instance.total += 1
|
|
12
12
|
json = JSON.parse line
|
|
13
|
+
json = mutate json
|
|
14
|
+
puts json
|
|
13
15
|
@client.post Config.instance[:tag], json
|
|
14
16
|
Stat.instance.success += 1
|
|
17
|
+
Stat.instance.flush_counter += 1
|
|
15
18
|
true
|
|
16
19
|
rescue Exception => e
|
|
17
20
|
Stat.instance.failed += 1
|
|
18
21
|
RLogger.instance.error "(#{e.message}) (line: #{line})"
|
|
19
22
|
false
|
|
20
23
|
end
|
|
24
|
+
|
|
25
|
+
def mutate record
|
|
26
|
+
return record unless record[Config.instance['time_key']]
|
|
27
|
+
time = Time.strptime record[Config.instance['time_key']], Config.instance['time_format']
|
|
28
|
+
record[Config.instance['index_key']] = "fluentd-#{time.strftime('%Y-%m')}"
|
|
29
|
+
record
|
|
30
|
+
end
|
|
31
|
+
|
|
21
32
|
end
|
|
@@ -13,6 +13,16 @@ class FileProcessor
|
|
|
13
13
|
Stat.instance.files_current += 1
|
|
14
14
|
RLogger.instance.info "finish working on #{filepath}"
|
|
15
15
|
RLogger.instance.stat
|
|
16
|
+
delay
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def delay
|
|
21
|
+
if Config.instance['flush_threshold'].to_i < Stat.instance.flush_counter
|
|
22
|
+
RLogger.instance.info "Sleep for #{Config.instance['flush_delay']} seconds"
|
|
23
|
+
sleep(Config.instance['flush_delay'].to_i)
|
|
24
|
+
Stat.instance.flush_counter = 0
|
|
25
|
+
end
|
|
16
26
|
end
|
|
17
27
|
|
|
18
28
|
def self.call filepath
|
data/lib/rforward/stat.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
class Stat
|
|
2
2
|
include Singleton
|
|
3
|
-
attr_accessor :success, :failed, :total, :files_total, :files_current
|
|
3
|
+
attr_accessor :success, :failed, :total, :files_total, :files_current, :flush_counter
|
|
4
4
|
|
|
5
5
|
def initialize
|
|
6
|
-
@success, @failed, @total, @files_total, @files_current = 0, 0, 0, 0, 0
|
|
6
|
+
@success, @failed, @total, @files_total, @files_current, @flush_counter = 0, 0, 0, 0, 0, 0
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def to_s
|
data/lib/rforward/version.rb
CHANGED
data/lib/rforward.rb
CHANGED
|
@@ -3,6 +3,7 @@ require 'singleton'
|
|
|
3
3
|
require 'yaml'
|
|
4
4
|
require 'json'
|
|
5
5
|
require 'dry-container'
|
|
6
|
+
require 'time'
|
|
6
7
|
require "rforward/exceptions"
|
|
7
8
|
require "rforward/stat"
|
|
8
9
|
require "rforward/rlogger"
|
|
@@ -14,17 +15,19 @@ require 'thor'
|
|
|
14
15
|
|
|
15
16
|
module Rforward
|
|
16
17
|
class CLI < Thor
|
|
17
|
-
desc "Process JSON logs into Fluentd Forward"
|
|
18
|
+
desc "process_logs", "Process JSON logs into Fluentd Forward"
|
|
18
19
|
def process_logs path, ext=".log"
|
|
19
20
|
check_config
|
|
20
21
|
dependencies
|
|
21
22
|
DirectoryProcessor.call path, ext
|
|
22
23
|
RLogger.instance.info "#{path} logs extensions #{ext}"
|
|
24
|
+
puts "Work finidhed press any key"
|
|
25
|
+
STDIN.gets
|
|
23
26
|
rescue ConfigNotFoundEx => e
|
|
24
27
|
RLogger.instance.error e.message
|
|
25
28
|
end
|
|
26
29
|
|
|
27
|
-
desc "Create config file
|
|
30
|
+
desc "create_config", "Create config file in current working directory"
|
|
28
31
|
def create_config
|
|
29
32
|
Config.instance.create_sample_config config_path
|
|
30
33
|
rescue ConfigNotFoundEx => e
|