trinidad_jmx_remote_extension 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ Gemfile.lock
5
+ coverage
6
+ doc/
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ # Specify your gem's dependencies in trinidad_jmx_remote_extension.gemspec
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 kares
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # Trinidad JMX Remote Extension
2
+
3
+ This extension allows you to enable remote JMX (Java Management Extensions)
4
+ monitoring capabilities for [Trinidad](https://github.com/trinidad/trinidad/).
5
+
6
+ The extension sets up a Tomcat lifecycle listener which fixes the ports used by
7
+ JMX/RMI to static ones (known ahead of time) thus making things much simpler if
8
+ you need to connect [JConsole](http://bit.ly/jconsole) or any similar tool to a
9
+ remote Trinidad instance running behind a firewall.
10
+
11
+ Please note that only the ports are configured via the listener, the remainder
12
+ of the configuration is via the standard system properties for configuring JMX.
13
+
14
+ ## Install
15
+
16
+ Along with Trinidad in your application's *Gemfile*:
17
+
18
+ ```ruby
19
+ group :server do
20
+ platform :jruby do
21
+ gem 'trinidad', :require => false
22
+ gem 'trinidad_jmx_remote_extension', :require => false
23
+ end
24
+ end
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install trinidad_jmx_remote_extension
34
+
35
+ ## Setup
36
+
37
+ Like all extensions it is setup in the configuration file e.g. *trinidad.yml* :
38
+
39
+ ```yaml
40
+ ---
41
+ # ...
42
+ extensions:
43
+ jmx_remote:
44
+ useLocalPorts: true # bind to localhost than setup a ssh tunnel
45
+ # assuming you'll setup the tunnel you shall remember these ports :
46
+ rmiRegistryPortPlatform: 9993
47
+ rmiServerPortPlatform: 9994
48
+ ```
49
+
50
+ Now your server should be setup, do not forget to restart Trinidad ... You might
51
+ want to disable JMX authentication (at first) and set the RMI hostname e.g. by :
52
+
53
+ $ jruby -J-Dcom.sun.management.jmxremote.ssl=false -J-D-Dcom.sun.management.jmxremote.authenticate=false -J-Djava.rmi.server.hostname=<trinidad-host-name> -S trinidad -e production
54
+
55
+ Next you will need to make sure you can SSH into the remote machine locally.
56
+
57
+ ### Local Setup
58
+
59
+ SSH tunnel (those ports) into the machine where Trinidad is running :
60
+
61
+ $ ssh -N -L9993:localhost:9993 -L9994:localhost:9994 user@remotehost
62
+
63
+ Download the *catalina-jmx-remote.jar* into your current working directory :
64
+
65
+ $ wget http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.30/bin/extras/catalina-jmx-remote.jar
66
+
67
+ You shall use the same *catalina-jmx-remote.jar* locally as the extension is
68
+ using on the remote Trinidad machine, this guide reflects the .jar distributed
69
+ with the latest version of the gem. When in doubt simply `gem install` the same
70
+ version locally and copy the .jar from the unpacked gem e.g. using :
71
+
72
+ $ jruby -rubygems -e "require 'trinidad_jmx_remote_extension'; puts Trinidad::Extensions::JmxRemote::JAR_PATH"
73
+
74
+ Now open `jconsole`, assuming your JMX connection string looks like this :
75
+ **service:jmx:rmi://localhost:9994/jndi/rmi://localhost:9993/jmxrmi**
76
+
77
+ $ jconsole -debug -J"-Djava.class.path=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/jconsole.jar:catalina-jmx-remote.jar" service:jmx:rmi://localhost:9994/jndi/rmi://localhost:9993/jmxrmi
78
+
79
+ This is assuming a standard JDK installation (non Apple Java) ...
80
+
81
+ For more details, this guide has been inspired by the following excellent post :
82
+ http://danielkunnath.com/post/9969130766/dancing-with-jmx-jconsole-tomcat-6-ssh
83
+
84
+ ## Copyright
85
+
86
+ Copyright (c) 2012 [Karol Bucek](https://github.com/kares).
87
+ See LICENSE (http://en.wikipedia.org/wiki/MIT_License) for details.
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ jar_path = 'lib/catalina-jmx-remote.jar'
5
+
6
+ desc "update (bundled) catalina-jmx-remote.jar"
7
+ task :update_jar, :version do |_, args| # e.g. `rake update_jar[7.0.30]`
8
+ require 'open-uri'; require 'fileutils'
9
+ uri_start = 'http://archive.apache.org/dist/tomcat/tomcat-7/'
10
+ uri_end = '/bin/extras/catalina-jmx-remote.jar'
11
+ jar_file = open(uri = "#{uri_start}v#{args[:version]}#{uri_end}",'rb')
12
+ Rake::Task['remove_jar'].invoke
13
+ File.open(jar_path, 'wb') { |file| file.write jar_file.read }
14
+ # and update README section to match the same .jar :
15
+ readme = File.expand_path('README.md', File.dirname(__FILE__))
16
+ old_uri = /#{Regexp.escape(uri_start)}v.*?#{Regexp.escape(uri_end)}/
17
+ lines = IO.readlines(readme).map { |line| line.gsub(old_uri, uri) }
18
+ File.open(readme, 'w') { |file| file.write(lines.join) }
19
+ end
20
+
21
+ task :remove_jar do
22
+ File.delete jar_path if File.exist? jar_path
23
+ end
24
+
25
+ require 'rake/testtask'
26
+ Rake::TestTask.new do |t|
27
+ t.libs << "test"
28
+ t.test_files = FileList['test/*test.rb']
29
+ t.verbose = true
30
+ end
31
+
32
+ task :default => :test
Binary file
@@ -0,0 +1,28 @@
1
+ require 'trinidad'
2
+ require "trinidad_jmx_remote_extension/version"
3
+
4
+ module Trinidad
5
+ module Extensions
6
+ module JmxRemote
7
+ unless const_defined?(:JAR_PATH)
8
+ JAR_PATH = File.expand_path('catalina-jmx-remote.jar', File.dirname(__FILE__))
9
+ end
10
+ end
11
+ class JmxRemoteServerExtension < ServerExtension
12
+
13
+ def configure(tomcat)
14
+ load JmxRemote::JAR_PATH
15
+ listener = Java::OrgApacheCatalinaMbeans::JmxRemoteLifecycleListener.new
16
+ options.each do |key, value| # e.g. useLocalPorts: true
17
+ if listener.respond_to? method = "set#{key.to_s.upcase}"
18
+ listener.send(method, value)
19
+ elsif listener.respond_to? method = "#{key}="
20
+ listener.send(method, value)
21
+ end
22
+ end
23
+ tomcat.server.add_lifecycle_listener listener
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ module Trinidad
2
+ module Extensions
3
+ module JmxRemote
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'bundler/setup'
6
+ end
7
+ Bundler.require(:default)
8
+
9
+ require 'test-unit'
10
+
11
+ require "trinidad"
12
+
13
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
data/test/trinidad.yml ADDED
@@ -0,0 +1,9 @@
1
+ ---
2
+ environment: production
3
+ port: 4444
4
+ trap: false
5
+ extensions:
6
+ jmx_remote:
7
+ useLocalPorts: true
8
+ rmiRegistryPortPlatform: 9993
9
+ rmiServerPortPlatform: 9994
@@ -0,0 +1,37 @@
1
+ require File.expand_path('test_helper', File.dirname(__FILE__))
2
+ require 'yaml'
3
+
4
+ module Trinidad
5
+ module Extensions
6
+ class JmxRemoteServerExtensionTest < Test::Unit::TestCase
7
+
8
+ test "loads jar and configures listener" do
9
+ config = File.expand_path('trinidad.yml', File.dirname(__FILE__))
10
+ options = YAML.load( File.read(config) )
11
+ config = Trinidad.configure!(options)
12
+ Trinidad::Extensions.configure_server_extensions(config[:extensions], tomcat)
13
+
14
+ begin
15
+ Java::OrgApacheCatalinaMbeans::JmxRemoteLifecycleListener
16
+ rescue NameError => e
17
+ flunk "failed loading classes from catalina-jmx-remote.jar #{e.inspect}"
18
+ end
19
+
20
+ listeners = tomcat.server.find_lifecycle_listeners
21
+ assert listeners.size > 0
22
+ assert_kind_of org.apache.catalina.mbeans.JmxRemoteLifecycleListener, listeners[0]
23
+ assert_true listeners[0].use_local_ports?
24
+
25
+ assert_equal 9993, listeners[0].rmi_registry_port_platform
26
+ assert_equal 9994, listeners[0].rmi_server_port_platform
27
+ end
28
+
29
+ private
30
+
31
+ def tomcat
32
+ @tomcat ||= org.apache.catalina.startup.Tomcat.new
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "trinidad_jmx_remote_extension/version"
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "trinidad_jmx_remote_extension"
7
+ gem.version = Trinidad::Extensions::JmxRemote::VERSION
8
+
9
+ gem.description = %q{JMX Remote Extension for Trinidad}
10
+ gem.summary = %q{The extension sets up a Tomcat lifecycle listener
11
+ which fixes the port used by JMX/RMI to static ones known ahead of time thus
12
+ making things much simpler if you need to connect JConsole or similar to a
13
+ remote Trinidad instance running behind a firewall (e.g. via SSH).}
14
+
15
+ gem.authors = ["Karol Bucek"]
16
+ gem.email = ["self@kares.org"]
17
+ gem.homepage = 'http://github.com/kares/trinidad_jmx_remote_extension'
18
+
19
+ gem.files = `git ls-files`.split("\n")
20
+ gem.test_files = `git ls-files -- {test}/*`.split("\n")
21
+
22
+ gem.rdoc_options = ["--charset=UTF-8"]
23
+ gem.extra_rdoc_files = %w[ README.md LICENSE ]
24
+
25
+ gem.require_paths = ["lib"]
26
+ gem.add_dependency('trinidad', '>= 1.3.5')
27
+ gem.add_development_dependency('rake')
28
+ gem.add_development_dependency('test-unit', '>= 2.4')
29
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trinidad_jmx_remote_extension
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Karol Bucek
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-10-09 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: trinidad
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.3.5
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :development
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: test-unit
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "2.4"
46
+ type: :development
47
+ version_requirements: *id003
48
+ description: JMX Remote Extension for Trinidad
49
+ email:
50
+ - self@kares.org
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - README.md
57
+ - LICENSE
58
+ files:
59
+ - .gitignore
60
+ - Gemfile
61
+ - LICENSE
62
+ - README.md
63
+ - Rakefile
64
+ - lib/catalina-jmx-remote.jar
65
+ - lib/trinidad_jmx_remote_extension.rb
66
+ - lib/trinidad_jmx_remote_extension/version.rb
67
+ - test/test_helper.rb
68
+ - test/trinidad.yml
69
+ - test/trinidad_jmx_remote_extension_test.rb
70
+ - trinidad_jmx_remote_extension.gemspec
71
+ homepage: http://github.com/kares/trinidad_jmx_remote_extension
72
+ licenses: []
73
+
74
+ post_install_message:
75
+ rdoc_options:
76
+ - --charset=UTF-8
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ requirements: []
92
+
93
+ rubyforge_project:
94
+ rubygems_version: 1.8.15
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: The extension sets up a Tomcat lifecycle listener which fixes the port used by JMX/RMI to static ones known ahead of time thus making things much simpler if you need to connect JConsole or similar to a remote Trinidad instance running behind a firewall (e.g. via SSH).
98
+ test_files: []
99
+