fluent_logger_statistics 0.2.0 → 0.3.0

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: 1ab36c857fb64b4e55fb17480bc71863c3df96e5
4
- data.tar.gz: 58b8b77224325b350cc7c920f9674b8e269441ec
3
+ metadata.gz: ed0b43301c6beb92978b77b3eee67f05c8b7c3da
4
+ data.tar.gz: 74e98587db73f9270ffe91b603c0477bb37b408f
5
5
  SHA512:
6
- metadata.gz: 2d82123ef13982ec3309e80acb511dbbf3b7531be6d5644c400545a1060b19cffa73132f200afd77b76b443d3971b0baa70b84c19a129d7e52d3ddb0f6d81d5b
7
- data.tar.gz: fdc51c1544c704a517b08046528b9126c1b95f6cef6725a6efd6866f3021eb8c249fe4439ceff4195d6578f5555a5cfd757156b7f6b6d42b96963f0b104fb83a
6
+ metadata.gz: b12299eea163d97ced0722126efe21c0d5772a88d578e03359fa417d72c7d16575ff0de1f5e01949c72747b9a706eeb88f7d44a6ae9cb413baa2c1a6d97942e9
7
+ data.tar.gz: 1c086a9aba069c80b9f3b004c4e04dbcbbcd81cbe5fe553d8e218d043c2be65dd7e3c5622c7e18691e59d41d546c0c819c908900cc2480a4e69c049f4205e6f5
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  Middleware settings:
7
7
  ```ruby
8
8
  Rails.configuration.middleware.use FluentLoggerStatistics::Middleware,
9
- '/endpoint',
9
+ '/endpoint/',
10
10
  {
11
11
  resource_name1: fluent_logger1, # instance of Fluent::Logger::FluentLogger
12
12
  resource_name2: fluent_logger2,
@@ -14,11 +14,19 @@ Rails.configuration.middleware.use FluentLoggerStatistics::Middleware,
14
14
  }
15
15
  ```
16
16
 
17
- After rails boot, then
17
+ After rails boots, then
18
18
  ```sh
19
- $ curl http://rails-host/endpoint/resource_name1 # no buffer used
20
- {"buffer_bytesize":0,"buffer_limit":8388608,"buffer_usage_rate":0.0}
21
-
22
- $ curl http://rails-host/endpoint/resource_name2 # buffered
23
- {"buffer_bytesize":236,"buffer_limit":8388608,"buffer_usage_rate":2.8133392333984375e-05}
19
+ $ curl http://rails-host/endpoint | jq .
20
+ {
21
+ "resource_name1": {
22
+ "buffer_bytesize": 0,
23
+ "buffer_limit": 8388608,
24
+ "buffer_usage_rate": 0
25
+ },
26
+ "resource_name2": {
27
+ "buffer_bytesize": 236,
28
+ "buffer_limit": 8388608,
29
+ "buffer_usage_rate": 2.8133392333984375e-05
30
+ }
31
+ }
24
32
  ```
@@ -2,8 +2,8 @@ module FluentLoggerStatistics
2
2
  class App
3
3
  include Rack::Utils
4
4
 
5
- def initialize(fluent_logger)
6
- @fluent_logger = fluent_logger
5
+ def initialize(fluent_loggers)
6
+ @fluent_loggers = fluent_loggers
7
7
  end
8
8
 
9
9
  ACCEPT_METHODS = ['GET'].freeze
@@ -16,16 +16,18 @@ module FluentLoggerStatistics
16
16
  status = 200
17
17
  header = {'Content-Type' => 'application/json'}
18
18
 
19
- bytesize = @fluent_logger.pending_bytesize
20
- limit = @fluent_logger.limit
21
- usage_rate = bytesize / limit.to_f
22
-
23
- body = [
24
- { buffer_bytesize: bytesize,
25
- buffer_limit: limit,
19
+ stats = @fluent_loggers.map{|k,v|
20
+ bytesize = v.pending_bytesize
21
+ limit_bytesize = v.limit
22
+ usage_rate = bytesize / limit_bytesize.to_f
23
+ [k, {
24
+ buffer_bytesize: bytesize,
25
+ buffer_limit: limit_bytesize,
26
26
  buffer_usage_rate: usage_rate
27
- }.to_json
28
- ]
27
+ }]
28
+ }.to_h
29
+
30
+ body = [ stats.to_json ]
29
31
 
30
32
  [status, header, body]
31
33
  end
@@ -2,20 +2,17 @@ require "fluent_logger_statistics/app"
2
2
 
3
3
  module FluentLoggerStatistics
4
4
  class Middleware
5
- def initialize(app, endpoint, loggers)
5
+ def initialize(app, path, loggers)
6
6
  @app = app
7
- @fluent_apps = loggers.map{|resource, logger|
8
- path = [ endpoint.chomp('/'), resource ].join('/')
9
- [ path, App.new(logger) ]
10
- }.to_h
7
+ @path = path
8
+ @fluent_app = App.new(loggers)
11
9
  end
12
10
 
13
11
  ACCEPT_METHODS = ['GET'].freeze
14
12
 
15
13
  def call(env)
16
- path = env['PATH_INFO'].chomp('/')
17
- if @fluent_apps[path] && ACCEPT_METHODS.include?(env['REQUEST_METHOD'])
18
- @fluent_apps[path].call(env)
14
+ if env['PATH_INFO'] == @path && ACCEPT_METHODS.include?(env['REQUEST_METHOD'])
15
+ @fluent_app.call(env)
19
16
  else
20
17
  @app.call(env)
21
18
  end
@@ -1,3 +1,3 @@
1
1
  module FluentLoggerStatistics
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent_logger_statistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takuya Kosugiyama
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-03 00:00:00.000000000 Z
11
+ date: 2017-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler