fluent-plugin-nginx-status 1.0.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.
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ Robert Pitt <rpitt _at_ centiq.co.uk>
@@ -0,0 +1,25 @@
1
+ # Fluent::Plugin::NginxStatus, a plugin for [Fluentd](http://fluentd.org)
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+ gem 'fluent-plugin-nginx-status'
7
+
8
+ Or install it yourself as:
9
+ $ gem install fluent-plugin-nginx-status
10
+
11
+ Or use td-agent : (on Ubuntu12.04)
12
+ $ sudo /usr/lib/fluent/ruby/bin/fluent-gem install fluent-plugin-nginx-status
13
+
14
+ ## Configuration
15
+
16
+ Adding the following source block will enable the nginx status plugin for FluentD
17
+
18
+ <source>
19
+ type nginx_status
20
+ </source>
21
+
22
+ You also need to enable the nginx_status page in your nginx configuration, see the following link for more details:
23
+
24
+ http://wiki.nginx.org/HttpStubStatusModule
25
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "fluent-plugin-nginx-status"
6
+ gem.description = "Nginx status page monitor for FleuntD"
7
+ gem.homepage = "https://github.com/robertpitt/fluent-plugin-nginx-status"
8
+ gem.summary = gem.description
9
+ gem.version = File.read("VERSION").strip
10
+ gem.authors = ["Robert Pitt"]
11
+ gem.email = "rpitt@centiq.co.uk"
12
+ gem.has_rdoc = false
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ gem.require_paths = ['lib']
17
+
18
+ gem.add_dependency "fluentd", "~> 0.10.9"
19
+ end
@@ -0,0 +1,140 @@
1
+ #
2
+ # Fluent
3
+ #
4
+ #
5
+ #
6
+ #
7
+ #
8
+ #
9
+ class NginxTimer < Fluent::Input
10
+ # First, register the plugin. NAME is the name of this plugin
11
+ # and identifies the plugin in the configuration file.
12
+ Fluent::Plugin.register_input('nginx_status', self)
13
+
14
+ # Load Modules
15
+ require 'net/http'
16
+ require 'uri'
17
+
18
+ class TimerWatcher < Coolio::TimerWatcher
19
+ def initialize(interval, repeat, log, &callback)
20
+ @callback = callback
21
+ @log = log
22
+ super(interval, repeat)
23
+ end
24
+
25
+ def on_timer
26
+ @callback.call
27
+
28
+ rescue
29
+ # TODO log?
30
+ @log.error $!.to_s
31
+ @log.error_backtrace
32
+ end
33
+ end
34
+
35
+ # This method is called before starting.
36
+ # 'conf' is a Hash that includes configuration parameters.
37
+ # If the configuration is invalid, raise Fluent::ConfigError.
38
+ def configure(conf)
39
+ super
40
+ # Send a info event to the output
41
+ $log.info "Nginx status monitor initializing"
42
+
43
+ # Default port is http
44
+ @tag = conf['tag'] || 'nginx.status'
45
+
46
+ # Nginx host
47
+ @host = conf['host'] || 'localhost'
48
+
49
+ # Default port is http
50
+ @port = conf['port'] || "80"
51
+
52
+ # Nginx host
53
+ @scheme = if @port == 443 then "https" else "http" end
54
+
55
+ # Nginz status page path
56
+ @path = conf['path'] || '/nginx_status'
57
+
58
+ #Interval for the timer object, defaults 1s
59
+ @interval = conf['interval'] || 1
60
+ end
61
+
62
+ # This method is called when starting.
63
+ # Open sockets or files and create a thread here.
64
+ def start
65
+ super
66
+
67
+ # Create a new timer loop
68
+ @loop = Coolio::Loop.new
69
+
70
+ # Create a new timer entity
71
+ @timer = TimerWatcher.new(@interval, true, log, &method(:on_timer))
72
+
73
+ # Attach the timer to the looper
74
+ @loop.attach(@timer)
75
+
76
+ # Run the timer object within a new thread
77
+ @thread = Thread.new(&method(:run))
78
+ end
79
+
80
+ # Sub-thread run method
81
+ def run
82
+ @loop.run
83
+ rescue => e
84
+ $log.error "unexpected error", :error=> e.to_s
85
+ $log.error_backtrace
86
+ end
87
+
88
+ # On timer method
89
+ def on_timer
90
+ # Generate a URI Object, helps validate domain etc
91
+ uri = URI.parse(@scheme + "://" + @host + ":" + @port)
92
+
93
+ # Create a new connection object to the endpoint
94
+ connection = Net::HTTP.new(uri.host, uri.port)
95
+
96
+ # # Are we going over ssl
97
+ if @port == 443
98
+ # # Go over https, but we have not implemented cert validation
99
+ # # so skip verification.
100
+ connection.use_ssl = true
101
+ connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
102
+ end
103
+
104
+ # Fetch the response
105
+ response = connection.get(@path)
106
+
107
+ # Validate a response
108
+ if response.code != "200"
109
+ $log.error "invalid_nginx_status_response", :code => response.code
110
+ return
111
+ end
112
+
113
+ if m = response.body.to_s.match(/^[a-zA-Z\s]+\:\s([0-9]+?)\s\n[a-z\s]+([0-9]+)\s([0-9]+)\s([0-9]+)\s\n[a-zA-Z\:?]+\s([0-9]+)\s[a-zA-Z\:?]+\s([0-9]+)\s[a-zA-Z\:?]+\s([0-9]+)/)
114
+ record = {
115
+ "active" => m.captures[0],
116
+ "accepted" => m.captures[1],
117
+ "handled" => m.captures[2],
118
+ "total" => m.captures[3],
119
+ "reading" => m.captures[4],
120
+ "writing" => m.captures[5],
121
+ "waiting" => m.captures[6],
122
+ }
123
+
124
+ # Push to the FluentD Output handlers
125
+ Fluent::Engine.emit(@tag, Time.now.to_i, record)
126
+ end
127
+
128
+ # $log.info response.body
129
+ rescue => e
130
+ $log.error "Unable to fetch status page", :error=> e.to_s
131
+ end
132
+
133
+ # This method is called when shutting down.
134
+ # Shutdown the thread and close sockets or files here.
135
+ def shutdown
136
+ @loop.watchers.each {|w| w.detach }
137
+ @loop.stop
138
+ @thread.join
139
+ end
140
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-nginx-status
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Robert Pitt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-04-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.10.9
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.10.9
30
+ description: Nginx status page monitor for FleuntD
31
+ email: rpitt@centiq.co.uk
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - AUTHORS
37
+ - README.md
38
+ - VERSION
39
+ - fluent-plugin-nginx-status.gemspec
40
+ - lib/fluent/plugin/in_nginx.rb
41
+ homepage: https://github.com/robertpitt/fluent-plugin-nginx-status
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 1.8.23
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Nginx status page monitor for FleuntD
65
+ test_files: []