fluent_logger_statistics 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -7
- data/lib/fluent_logger_statistics/app.rb +13 -11
- data/lib/fluent_logger_statistics/middleware.rb +5 -8
- data/lib/fluent_logger_statistics/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed0b43301c6beb92978b77b3eee67f05c8b7c3da
|
4
|
+
data.tar.gz: 74e98587db73f9270ffe91b603c0477bb37b408f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
17
|
+
After rails boots, then
|
18
18
|
```sh
|
19
|
-
$ curl http://rails-host/endpoint
|
20
|
-
{
|
21
|
-
|
22
|
-
|
23
|
-
|
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(
|
6
|
-
@
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
buffer_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
|
-
}
|
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,
|
5
|
+
def initialize(app, path, loggers)
|
6
6
|
@app = app
|
7
|
-
@
|
8
|
-
|
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
|
-
|
17
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2017-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|