rforward 0.1.0 → 0.1.1
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/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/exe/rforward +1 -1
- data/lib/rforward/config.rb +5 -5
- data/lib/rforward/directory_processor.rb +3 -1
- data/lib/rforward/exceptions.rb +2 -2
- data/lib/rforward/ffluentd_line.rb +3 -0
- data/lib/rforward/file_processor.rb +4 -0
- data/lib/rforward/rlogger.rb +4 -0
- data/lib/rforward/stat.rb +17 -0
- data/lib/rforward/version.rb +1 -1
- data/lib/rforward.rb +4 -2
- metadata +2 -3
- data/exe/rforward.yml +0 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b604a36bc1961d87954e6cd92266934969ace196
|
|
4
|
+
data.tar.gz: da76ae995aaf1f648da48ec8c03b1db8a26f5274
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 20a8dd075a2b6fb29e9ed00dd8a648b05debe226c641096a7c1f8221357571d1ea42872aef2866bc947a80f1efe9f693bc8a68b2ef871a3a5cbee5707670051a
|
|
7
|
+
data.tar.gz: 93b501de72c5e6cc2df5e63fd9dc7999cfa34b5f429ce469da7abfec3fae5d192f3d2616abb6c4ac57c9963899e95832c181f16c1364d2dd05d07882eceb0cdd
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/exe/rforward
CHANGED
data/lib/rforward/config.rb
CHANGED
|
@@ -7,11 +7,11 @@ class Config
|
|
|
7
7
|
FLUENTD = :flunetd.freeze
|
|
8
8
|
|
|
9
9
|
def load_config config_path
|
|
10
|
-
config = YAML.load_file config_path
|
|
10
|
+
@config = YAML.load_file config_path
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def [](key)
|
|
14
|
-
config = config || sample
|
|
14
|
+
config = @config || sample
|
|
15
15
|
config[key.to_s]
|
|
16
16
|
end
|
|
17
17
|
|
|
@@ -27,9 +27,9 @@ class Config
|
|
|
27
27
|
|
|
28
28
|
def sample
|
|
29
29
|
hash = {
|
|
30
|
-
fluentd_host
|
|
31
|
-
fluentd_port
|
|
32
|
-
tag
|
|
30
|
+
'fluentd_host' => 'localhost',
|
|
31
|
+
'fluentd_port' => '24224',
|
|
32
|
+
'tag' => 'event'
|
|
33
33
|
}
|
|
34
34
|
end
|
|
35
35
|
end
|
data/lib/rforward/exceptions.rb
CHANGED
|
@@ -3,13 +3,13 @@ end
|
|
|
3
3
|
|
|
4
4
|
class WrongPathEx < BaseRforwardEx
|
|
5
5
|
def initialize path
|
|
6
|
-
super("
|
|
6
|
+
super("(#{path}) path must be exist and must be a directory ")
|
|
7
7
|
end
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
class ConfigNotFoundEx < BaseRforwardEx
|
|
11
11
|
def initialize config
|
|
12
|
-
super("
|
|
12
|
+
super("(#{config}) config yml not found create config first 'rforward create config'")
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
@@ -8,10 +8,13 @@ class FFluentdLine
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def call line
|
|
11
|
+
Stat.instance.total += 1
|
|
11
12
|
json = JSON.parse line
|
|
12
13
|
@client.post Config.instance[:tag], json
|
|
14
|
+
Stat.instance.success += 1
|
|
13
15
|
true
|
|
14
16
|
rescue Exception => e
|
|
17
|
+
Stat.instance.failed += 1
|
|
15
18
|
RLogger.instance.error "(#{e.message}) (line: #{line})"
|
|
16
19
|
false
|
|
17
20
|
end
|
|
@@ -6,9 +6,13 @@ class FileProcessor
|
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def call
|
|
9
|
+
RLogger.instance.info "start working on #{filepath}"
|
|
9
10
|
File.readlines(filepath).each do |line|
|
|
10
11
|
line_processor.call line
|
|
11
12
|
end
|
|
13
|
+
Stat.instance.files_current += 1
|
|
14
|
+
RLogger.instance.info "finish working on #{filepath}"
|
|
15
|
+
RLogger.instance.stat
|
|
12
16
|
end
|
|
13
17
|
|
|
14
18
|
def self.call filepath
|
data/lib/rforward/rlogger.rb
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class Stat
|
|
2
|
+
include Singleton
|
|
3
|
+
attr_accessor :success, :failed, :total, :files_total, :files_current
|
|
4
|
+
|
|
5
|
+
def initialize
|
|
6
|
+
@success, @failed, @total, @files_total, @files_current = 0, 0, 0, 0, 0
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def to_s
|
|
10
|
+
text = []
|
|
11
|
+
text << "[STAT]"
|
|
12
|
+
text << "[total: #{total}] [success: #{success}] [failed #{failed}]"
|
|
13
|
+
text << "[file current #{files_current}] [files total #{files_total}]"
|
|
14
|
+
text << "[STAT]"
|
|
15
|
+
text.join "\n"
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/rforward/version.rb
CHANGED
data/lib/rforward.rb
CHANGED
|
@@ -4,6 +4,7 @@ require 'yaml'
|
|
|
4
4
|
require 'json'
|
|
5
5
|
require 'dry-container'
|
|
6
6
|
require "rforward/exceptions"
|
|
7
|
+
require "rforward/stat"
|
|
7
8
|
require "rforward/rlogger"
|
|
8
9
|
require "rforward/directory_processor"
|
|
9
10
|
require "rforward/file_processor"
|
|
@@ -17,6 +18,7 @@ module Rforward
|
|
|
17
18
|
def process_logs path, ext=".log"
|
|
18
19
|
check_config
|
|
19
20
|
dependencies
|
|
21
|
+
DirectoryProcessor.call path, ext
|
|
20
22
|
RLogger.instance.info "#{path} logs extensions #{ext}"
|
|
21
23
|
rescue ConfigNotFoundEx => e
|
|
22
24
|
RLogger.instance.error e.message
|
|
@@ -31,7 +33,7 @@ module Rforward
|
|
|
31
33
|
|
|
32
34
|
private
|
|
33
35
|
def check_config
|
|
34
|
-
raise ConfigNotFoundEx,
|
|
36
|
+
raise ConfigNotFoundEx, config_path.to_path unless config_path.file? && config_path.exist?
|
|
35
37
|
Config.instance.load_config config_path
|
|
36
38
|
end
|
|
37
39
|
|
|
@@ -41,7 +43,7 @@ module Rforward
|
|
|
41
43
|
|
|
42
44
|
def dependencies
|
|
43
45
|
Config.register Config::FLUENTD do
|
|
44
|
-
host, port, tag = Config.instance[:
|
|
46
|
+
host, port, tag = Config.instance[:fluentd_host], Config.instance[:fluentd_port], Config.instance[:tag]
|
|
45
47
|
Fluent::Logger::FluentLogger.new(nil, host: host, port: port.to_i)
|
|
46
48
|
end
|
|
47
49
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rforward
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- gingray
|
|
@@ -113,7 +113,6 @@ email:
|
|
|
113
113
|
- gingray.dev@gmail.com
|
|
114
114
|
executables:
|
|
115
115
|
- rforward
|
|
116
|
-
- rforward.yml
|
|
117
116
|
extensions: []
|
|
118
117
|
extra_rdoc_files: []
|
|
119
118
|
files:
|
|
@@ -129,7 +128,6 @@ files:
|
|
|
129
128
|
- bin/console
|
|
130
129
|
- bin/setup
|
|
131
130
|
- exe/rforward
|
|
132
|
-
- exe/rforward.yml
|
|
133
131
|
- lib/rforward.rb
|
|
134
132
|
- lib/rforward/config.rb
|
|
135
133
|
- lib/rforward/directory_processor.rb
|
|
@@ -137,6 +135,7 @@ files:
|
|
|
137
135
|
- lib/rforward/ffluentd_line.rb
|
|
138
136
|
- lib/rforward/file_processor.rb
|
|
139
137
|
- lib/rforward/rlogger.rb
|
|
138
|
+
- lib/rforward/stat.rb
|
|
140
139
|
- lib/rforward/version.rb
|
|
141
140
|
- rforward.gemspec
|
|
142
141
|
homepage: https://github.com/gingray/rforward
|
data/exe/rforward.yml
DELETED