fluent-plugin-haproxy_stats 0.1.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: 4827b6cac73434a4866d6c39a9bed74a28ad737b
4
+ data.tar.gz: 0eed58fb66f88ed97458570bbfc3cea3b3e96094
5
+ SHA512:
6
+ metadata.gz: 68465758383ed521a25382890399ea23c7905f5f47f01f1a0d6148b972c266149e0b5b1b7b3df02ae97e1c8e71a4daed1db61d9026e9ba08ba93ef6364593c80
7
+ data.tar.gz: af0151374494a20240943b8dc97c8ee2617660282d339dd4384c9a1fcae55538a9bccf3c081df75969da39d765c3f2b502bf9b970f0fb440f5edd0d127e8fe90
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
11
+ .bundle
12
+ Gemfile.lock
13
+ pkg/*
14
+ *.tmproj
15
+ tmtags
16
+ *~
17
+ \#*
18
+ .\#*
19
+ *.swp
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-haproxy_stats.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # Fluent::Plugin::HaproxyStats
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fluent/plugin/haproxy_stats`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'fluent-plugin-haproxy_stats'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install fluent-plugin-haproxy_stats
22
+
23
+ ## Usage
24
+
25
+ ### Configuration
26
+
27
+ #### HAProxy
28
+
29
+ - Require `stats` option
30
+
31
+ ```
32
+ global
33
+ stats socket /path/to/stats
34
+
35
+ defaults
36
+ mode http
37
+ option httplog
38
+ option httpclose
39
+ retries 3
40
+ option redispatch
41
+ maxconn 2000
42
+
43
+ frontend app1
44
+ bind 0.0.0.0:10011
45
+ default_backend app1
46
+
47
+ backend app1
48
+ balance roundrobin
49
+ server web1 127.0.0.1:10006
50
+ server web2 127.0.0.1:10007
51
+ ```
52
+
53
+ #### fluentd
54
+
55
+ ```
56
+ <source>
57
+ type haproxy_stats
58
+ stats_file "/path/to/stats"
59
+ px_name app1
60
+ sv_name FRONTEND
61
+ tag haproxy.input
62
+ </source>
63
+
64
+ <match haproxy.input.**>
65
+ type stdout
66
+ </match>
67
+ ```
68
+
69
+ ## ToDo
70
+
71
+ - Multiple pxname and svname.
72
+
73
+ ## Development
74
+
75
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
76
+
77
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
78
+
79
+ ## Contributing
80
+
81
+ 1. Fork it ( https://github.com/[my-github-username]/fluent-plugin-haproxy_stats/fork )
82
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
83
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
84
+ 4. Push to the branch (`git push origin my-new-feature`)
85
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fluent/plugin/haproxy_stats/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fluent-plugin-haproxy_stats"
8
+ spec.version = Fluent::Plugin::HaproxyStats::VERSION
9
+ spec.authors = ["Yohei Kawahara"]
10
+ spec.email = [""]
11
+
12
+ spec.summary = %q{Fluentd plugin fo HAProxy info and stats}
13
+ spec.description = %q{Fluentd plugin fo HAProxy info and stats}
14
+ spec.homepage = ""
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.9"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "haproxy"
24
+ spec.add_runtime_dependency "fluentd"
25
+ end
@@ -0,0 +1,7 @@
1
+ module Fluent
2
+ module Plugin
3
+ module HaproxyStats
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,69 @@
1
+ module Fluent
2
+ class InHaproxyStats < Fluent::Input
3
+ Fluent::Plugin.register_input('haproxy_stats', self)
4
+
5
+ unless method_defined?(:log)
6
+ define_method("log") { $log }
7
+ end
8
+
9
+ unless method_defined?(:router)
10
+ define_method("router") { Fluent::Engine }
11
+ end
12
+
13
+ config_param :interval, :integer, :default => 60
14
+ config_param :stats_file, :string
15
+ config_param :px_name, :string, :default => 'all'
16
+ config_param :sv_name, :string, :default => 'all'
17
+ config_param :tag, :string
18
+
19
+ def initialize
20
+ super
21
+ #
22
+ require "haproxy"
23
+ end
24
+
25
+ def start
26
+ @finished = false
27
+ @thread = Thread.new(&method(:run))
28
+ end
29
+
30
+ def shutdown
31
+ @finished = true
32
+ @thread.join
33
+ end
34
+
35
+ def configure(conf)
36
+ super
37
+ #
38
+ unless File.exist?(@stats_file) or File.readable?(@stats_file)
39
+ raise Fluent::ConfigError, 'HAProxy stats file does not exists or does not readable.'
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def run
46
+ loop do
47
+ sleep @interval
48
+ haproxy = HAProxy.read_stats @stats_file
49
+ haproxy.stats.each do |s|
50
+ time = Time.now
51
+ if @px_name == 'all' and @sv_name == 'all'
52
+ tag = [@tag, 'all'].join(".")
53
+ router.emit(tag, time, s)
54
+ elsif s[:pxname] == @px_name and s[:svname] == @sv_name
55
+ tag = [@tag, @px_name, @sv_name].join(".")
56
+ router.emit(tag, time, s)
57
+ elsif s[:pxname] == @px_name and @sv_name == 'all'
58
+ tag = [@tag, @px_name].join(".")
59
+ router.emit(tag, time, s)
60
+ elsif s[:svname] == @sv_name and @px_name == 'all'
61
+ tag = [@tag, @sv_name].join(".")
62
+ router.emit(tag, time, s)
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-haproxy_stats
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yohei Kawahara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-12 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
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: haproxy
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '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: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Fluentd plugin fo HAProxy info and stats
70
+ email:
71
+ - ''
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .travis.yml
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - fluent-plugin-haproxy_stats.gemspec
82
+ - lib/fluent/plugin/haproxy_stats/version.rb
83
+ - lib/fluent/plugin/in_haporxy_stats.rb
84
+ homepage: ''
85
+ licenses: []
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.0.3
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Fluentd plugin fo HAProxy info and stats
107
+ test_files: []
108
+ has_rdoc: