fluent_logger_statistics 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1ab36c857fb64b4e55fb17480bc71863c3df96e5
4
+ data.tar.gz: 58b8b77224325b350cc7c920f9674b8e269441ec
5
+ SHA512:
6
+ metadata.gz: 2d82123ef13982ec3309e80acb511dbbf3b7531be6d5644c400545a1060b19cffa73132f200afd77b76b443d3971b0baa70b84c19a129d7e52d3ddb0f6d81d5b
7
+ data.tar.gz: fdc51c1544c704a517b08046528b9126c1b95f6cef6725a6efd6866f3021eb8c249fe4439ceff4195d6578f5555a5cfd757156b7f6b6d42b96963f0b104fb83a
data/.gitignore ADDED
@@ -0,0 +1,63 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ ### https://raw.github.com/github/gitignore/160d27e2bebf784c4f4a1e070df057f3868b62bc/Ruby.gitignore
11
+
12
+ *.gem
13
+ *.rbc
14
+ /.config
15
+ /coverage/
16
+ /InstalledFiles
17
+ /pkg/
18
+ /spec/reports/
19
+ /spec/examples.txt
20
+ /test/tmp/
21
+ /test/version_tmp/
22
+ /tmp/
23
+
24
+ # Used by dotenv library to load environment variables.
25
+ # .env
26
+
27
+ ## Specific to RubyMotion:
28
+ .dat*
29
+ .repl_history
30
+ build/
31
+ *.bridgesupport
32
+ build-iPhoneOS/
33
+ build-iPhoneSimulator/
34
+
35
+ ## Specific to RubyMotion (use of CocoaPods):
36
+ #
37
+ # We recommend against adding the Pods directory to your .gitignore. However
38
+ # you should judge for yourself, the pros and cons are mentioned at:
39
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
40
+ #
41
+ # vendor/Pods/
42
+
43
+ ## Documentation cache and generated files:
44
+ /.yardoc/
45
+ /_yardoc/
46
+ /doc/
47
+ /rdoc/
48
+
49
+ ## Environment normalization:
50
+ /.bundle/
51
+ /vendor/bundle
52
+ /lib/bundler/man/
53
+
54
+ # for a library or gem, you might want to ignore these files since the code is
55
+ # intended to run in multiple environments; otherwise, check them in:
56
+ # Gemfile.lock
57
+ # .ruby-version
58
+ # .ruby-gemset
59
+
60
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
61
+ .rvmrc
62
+
63
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent_logger_statistics.gemspec
4
+ gemspec
5
+
6
+ gem 'test-unit'
7
+ gem 'rack-test'
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # FluentLoggerStatistics
2
+
3
+ [![Build Status](https://travis-ci.org/itkq/fluent_logger_statistics.svg?branch=master)](https://travis-ci.org/itkq/fluent_logger_statistics)
4
+
5
+ ## Usage
6
+ Middleware settings:
7
+ ```ruby
8
+ Rails.configuration.middleware.use FluentLoggerStatistics::Middleware,
9
+ '/endpoint',
10
+ {
11
+ resource_name1: fluent_logger1, # instance of Fluent::Logger::FluentLogger
12
+ resource_name2: fluent_logger2,
13
+ ...
14
+ }
15
+ ```
16
+
17
+ After rails boot, then
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}
24
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |spec|
5
+ spec.pattern = FileList['spec/**/*_spec.rb']
6
+ end
7
+
8
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fluent_logger_counter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fluent_logger_statistics/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fluent_logger_statistics"
8
+ spec.version = FluentLoggerStatistics::VERSION
9
+ spec.authors = ["Takuya Kosugiyama"]
10
+ spec.email = ["takuya-kosugiyama@cookpad.com"]
11
+
12
+ spec.summary = "Rack middleware for monitoring buffer of fluent-logger."
13
+ spec.description = "Rack middleware for monitoring buffer of fluent-logger."
14
+ spec.homepage = "https://github.com/itkq/fluent_logger_statistics"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.13"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "fluentd"
27
+ spec.add_runtime_dependency "fluent-logger", "~> 0.5"
28
+ end
@@ -0,0 +1,4 @@
1
+ require "fluent_logger_statistics/version"
2
+ require "fluent_logger_statistics/app"
3
+ require "fluent_logger_statistics/middleware"
4
+ require "fluent_logger_statistics/fluent_logger"
@@ -0,0 +1,33 @@
1
+ module FluentLoggerStatistics
2
+ class App
3
+ include Rack::Utils
4
+
5
+ def initialize(fluent_logger)
6
+ @fluent_logger = fluent_logger
7
+ end
8
+
9
+ ACCEPT_METHODS = ['GET'].freeze
10
+
11
+ def call(env)
12
+ unless ACCEPT_METHODS.include?(env['REQUEST_METHOD'])
13
+ return [404, {'Content-Type' => 'text/plain'}, []]
14
+ end
15
+
16
+ status = 200
17
+ header = {'Content-Type' => 'application/json'}
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,
26
+ buffer_usage_rate: usage_rate
27
+ }.to_json
28
+ ]
29
+
30
+ [status, header, body]
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ require 'fluent-logger'
2
+
3
+ module FluentLoggerStatistics
4
+ module FluentLoggerExt
5
+ def pending_bytesize
6
+ if @pending
7
+ @pending.bytesize
8
+ else
9
+ 0
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ Fluent::Logger::FluentLogger.include(FluentLoggerStatistics::FluentLoggerExt)
@@ -0,0 +1,24 @@
1
+ require "fluent_logger_statistics/app"
2
+
3
+ module FluentLoggerStatistics
4
+ class Middleware
5
+ def initialize(app, endpoint, loggers)
6
+ @app = app
7
+ @fluent_apps = loggers.map{|resource, logger|
8
+ path = [ endpoint.chomp('/'), resource ].join('/')
9
+ [ path, App.new(logger) ]
10
+ }.to_h
11
+ end
12
+
13
+ ACCEPT_METHODS = ['GET'].freeze
14
+
15
+ 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)
19
+ else
20
+ @app.call(env)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module FluentLoggerStatistics
2
+ VERSION = "0.2.0"
3
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent_logger_statistics
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Takuya Kosugiyama
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fluentd
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: fluent-logger
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.5'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.5'
83
+ description: Rack middleware for monitoring buffer of fluent-logger.
84
+ email:
85
+ - takuya-kosugiyama@cookpad.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - fluent_logger_statistics.gemspec
99
+ - lib/fluent_logger_statistics.rb
100
+ - lib/fluent_logger_statistics/app.rb
101
+ - lib/fluent_logger_statistics/fluent_logger.rb
102
+ - lib/fluent_logger_statistics/middleware.rb
103
+ - lib/fluent_logger_statistics/version.rb
104
+ homepage: https://github.com/itkq/fluent_logger_statistics
105
+ licenses: []
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.5.1
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Rack middleware for monitoring buffer of fluent-logger.
127
+ test_files: []