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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 016780641d038b2fa6a0436892a3e0b2a30cc222
4
- data.tar.gz: 7c5be24819f08f32779865199e4297d84836d0ae
3
+ metadata.gz: b604a36bc1961d87954e6cd92266934969ace196
4
+ data.tar.gz: da76ae995aaf1f648da48ec8c03b1db8a26f5274
5
5
  SHA512:
6
- metadata.gz: 32b5cdacc9972bba536623629393cc2092f945de7678312adc6c6a5ea76f60980d31056ddf374279c00e4dc01f7051f1f965ed4fe6e2a6350e70c5f5196a59a1
7
- data.tar.gz: e55202665463993ec8128255a18901943da34f5a4277916de8b37b2afbe3885127e14e351906dff9cf64e6a70f280a9266035f6a688d6cda0224d2febfcb32df
6
+ metadata.gz: 20a8dd075a2b6fb29e9ed00dd8a648b05debe226c641096a7c1f8221357571d1ea42872aef2866bc947a80f1efe9f693bc8a68b2ef871a3a5cbee5707670051a
7
+ data.tar.gz: 93b501de72c5e6cc2df5e63fd9dc7999cfa34b5f429ce469da7abfec3fae5d192f3d2616abb6c4ac57c9963899e95832c181f16c1364d2dd05d07882eceb0cdd
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ rforward.yml
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rforward (0.1.0)
4
+ rforward (0.1.1)
5
5
  dry-container
6
6
  fluent-logger
7
7
  thor (~> 0.20)
data/exe/rforward CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "rforward"
4
- ENV['ROOT_PATH'] = File.expand_path("../", __FILE__)
4
+ ENV['ROOT_PATH'] = Dir.getwd
5
5
  Rforward::CLI.start(ARGV)
@@ -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: 'localhost',
31
- fluentd_port: '24224',
32
- tag: 'event'
30
+ 'fluentd_host' => 'localhost',
31
+ 'fluentd_port' => '24224',
32
+ 'tag' => 'event'
33
33
  }
34
34
  end
35
35
  end
@@ -8,7 +8,9 @@ class DirectoryProcessor
8
8
  end
9
9
 
10
10
  def call
11
- Dir["#{path}/**#{ext}"].each do |filepath|
11
+ files_arr = Dir["#{path}/**#{ext}"]
12
+ Stat.instance.files_total = files_arr.count
13
+ files_arr.each do |filepath|
12
14
  FileProcessor.call filepath
13
15
  end
14
16
  end
@@ -3,13 +3,13 @@ end
3
3
 
4
4
  class WrongPathEx < BaseRforwardEx
5
5
  def initialize path
6
- super("[ERROR] (#{path}) path must be exist and must be a directory ")
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("[ERROR] (#{config}) config yml not found create config first 'rforward create config")
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
@@ -8,4 +8,8 @@ class RLogger
8
8
  def error msg
9
9
  puts "[ERROR] #{msg}"
10
10
  end
11
+
12
+ def stat
13
+ puts Stat.instance
14
+ end
11
15
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Rforward
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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, path unless config_path.file? && config_path.exist?
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[:host], Config.instance[:port], Config.instance[:tag]
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.0
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
@@ -1,4 +0,0 @@
1
- ---
2
- :fluentd_host: localhost
3
- :fluentd_port: '24224'
4
- :tag: event