Skip to content

Commit 4d561a3

Browse files
committed
JMX Framework
This change adds a framework that contributes JMX configuration to an application. Note that this is only useful in Diego-based containers with SSH access enabled. [#107537380]
1 parent ae4a734 commit 4d561a3

12 files changed

Lines changed: 184 additions & 7 deletions

File tree

.idea/dictionaries/bhale.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ To learn how to configure various properties of the buildpack, follow the "Confi
8282
* [Introscope Agent](docs/framework-introscope_agent.md) ([Configuration](docs/framework-introscope_agent.md#configuration))
8383
* [Java Options](docs/framework-java_opts.md) ([Configuration](docs/framework-java_opts.md#configuration))
8484
* [JRebel Agent](docs/framework-jrebel_agent.md) ([Configuration](docs/framework-jrebel_agent.md#configuration))
85+
* [JMX](docs/framework-jmx.md) ([Configuration](docs/jmx.md#configuration))
8586
* [Luna Security Provider](docs/framework-luna_security_provider.md) ([Configuration](docs/framework-luna_security_provider.md#configuration))
8687
* [MariaDB JDBC](docs/framework-maria_db_jdbc.md) ([Configuration](docs/framework-maria_db_jdbc.md#configuration))
8788
* [New Relic Agent](docs/framework-new_relic_agent.md) ([Configuration](docs/framework-new_relic_agent.md#configuration))

config/components.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ frameworks:
3939
- "JavaBuildpack::Framework::Debug"
4040
# - "JavaBuildpack::Framework::DynaTraceAgent"
4141
# - "JavaBuildpack::Framework::IntroscopeAgent"
42+
- "JavaBuildpack::Framework::Jmx"
4243
- "JavaBuildpack::Framework::JrebelAgent"
4344
# - "JavaBuildpack::Framework::LunaSecurityProvider"
4445
- "JavaBuildpack::Framework::MariaDbJDBC"

config/jmx.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Cloud Foundry Java Buildpack
2+
# Copyright 2014-2015 the original author or authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# JMX configuration
17+
---
18+
enabled: false
19+
port: 5000

docs/framework-debug.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The Debug Framework contributes Java debug configuration to the application at r
88
</tr>
99
<tr>
1010
<td><strong>Tags</strong></td>
11-
<td><tt>debug</tt></td>
11+
<td><tt>debug=&lt;port&gt;</tt></td>
1212
</tr>
1313
</table>
1414
Tags are printed to standard output by the buildpack detect script
@@ -20,7 +20,7 @@ The framework can be configured by creating or modifying the [`config/debug.yml`
2020

2121
| Name | Description
2222
| ---- | -----------
23-
| `enabled` | Whether to enable Java debuging
23+
| `enabled` | Whether to enable Java debugging
2424
| `port` | The port that the debug agent will listen on. Defaults to `8000`.
2525
| `suspend` | Whether to suspend execution until a debugger has attached. Note, enabling this may cause application start to timeout and be restarted.
2626

docs/framework-jmx-jconsole.png

75.5 KB
Loading

docs/framework-jmx.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# JMX Framework
2+
The JMX Framework contributes Java JMX configuration to the application at runtime. **Note:** This framework is only useful in Diego-based containers with SSH access enabled.
3+
4+
<table>
5+
<tr>
6+
<td><strong>Detection Criterion</strong></td>
7+
<td><tt>enabled</tt> set in the <tt>config/jmx.yml</tt> file</td>
8+
</tr>
9+
<tr>
10+
<td><strong>Tags</strong></td>
11+
<td><tt>jmx=&lt;port&gt;</tt></td>
12+
</tr>
13+
</table>
14+
Tags are printed to standard output by the buildpack detect script
15+
16+
## Configuration
17+
For general information on configuring the buildpack, including how to specify configuration values through environment variables, refer to [Configuration and Extension][].
18+
19+
The framework can be configured by creating or modifying the [`config/jmx.yml`][] file in the buildpack fork.
20+
21+
| Name | Description
22+
| ---- | -----------
23+
| `enabled` | Whether to enable JMX
24+
| `port` | The port that the debug agent will listen on. Defaults to `5000`.
25+
26+
## Creating SSH Tunnel
27+
After starting an application with JMX enabled, an SSH tunnel must be created to the container. To create that SSH container, execute the following command:
28+
29+
```bash
30+
$ cf ssh -N -T -L <LOCAL_PORT>:localhost:<REMOTE_PORT> <APPLICATION_NAME>
31+
```
32+
33+
The `REMOTE_PORT` should match the `port` configuration for the application (`5000` by default). The `LOCAL_PORT` can be any open port on your computer, but typically matches the `REMOTE_PORT` where possible.
34+
35+
Once the SSH tunnel has been created, your JConsole should connect to `localhost:<LOCAL_PORT>` for debugging.
36+
37+
![JConsole Configuration](framework-jmx-jconsole.png)
38+
39+
[`config/jmx.yml`]: ../config/jmx.yml
40+
[Configuration and Extension]: ../README.md#configuration-and-extension

lib/java_buildpack/framework/debug.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Debug < JavaBuildpack::Component::BaseComponent
2626

2727
# (see JavaBuildpack::Component::BaseComponent#detect)
2828
def detect
29-
enabled? ? Debug.to_s.dash_case : nil
29+
enabled? ? "#{Debug.to_s.dash_case}=#{port}" : nil
3030
end
3131

3232
# (see JavaBuildpack::Component::BaseComponent#compile)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Encoding: utf-8
2+
# Cloud Foundry Java Buildpack
3+
# Copyright 2013-2015 the original author or authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
require 'java_buildpack/component/base_component'
18+
require 'java_buildpack/framework'
19+
require 'java_buildpack/util/dash_case'
20+
21+
module JavaBuildpack
22+
module Framework
23+
24+
# Encapsulates the functionality for contributing Java JMX options to an application.
25+
class Jmx < JavaBuildpack::Component::BaseComponent
26+
27+
# (see JavaBuildpack::Component::BaseComponent#detect)
28+
def detect
29+
enabled? ? "#{Jmx.to_s.dash_case}=#{port}" : nil
30+
end
31+
32+
# (see JavaBuildpack::Component::BaseComponent#compile)
33+
def compile
34+
end
35+
36+
# (see JavaBuildpack::Component::BaseComponent#release)
37+
def release
38+
@droplet.java_opts
39+
.add_system_property('java.rmi.server.hostname', '127.0.0.1')
40+
.add_system_property('com.sun.management.jmxremote.authenticate', false)
41+
.add_system_property('com.sun.management.jmxremote.port', port)
42+
.add_system_property('com.sun.management.jmxremote.rmi.port', port)
43+
end
44+
45+
private
46+
47+
def enabled?
48+
@configuration['enabled']
49+
end
50+
51+
def port
52+
@configuration['port'] || 5000
53+
end
54+
55+
end
56+
57+
end
58+
end

0 commit comments

Comments
 (0)