Skip to content

Commit

Permalink
fix: Overrides to enable (opt-out) Prometheus Java Agent in Java Bina…
Browse files Browse the repository at this point in the history
…ry image
  • Loading branch information
manusa committed Sep 21, 2020
1 parent 3df5077 commit 2981876
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Available environment variables for runtime configuration:
**HTTP_PROXY**, and will be used for both Maven builds and Java runtime.
* **`no_proxy`** / **NO_PROXY** A comma separated lists of hosts, IP addresses or domains that can be accessed directly.
This will be used for both Maven builds and Java runtime.
* **AB_PROMETHEUS_OFF** Disables the use of Prometheus Java Agent.
* **AB_PROMETHEUS_PORT** Port to use for the Prometheus JMX Exporter.

### jkube-tomcat9-binary-s2i

Expand Down
1 change: 1 addition & 0 deletions jkube-java-binary-s2i.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ modules:
- name: jboss.container.prometheus
- name: jboss.container.util.logging.bash
- name: jboss.container.java.jvm.bash.debug-options-override
- name: jboss.container.prometheus-override
- name: s2i-scripts

run:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh
# ==============================================================================
# Configure JVM options for Prometheus Agent
#
# Usage: JAVA_OPTS="$JAVA_OPTS $(source ${JBOSS_CONTAINER_PROMETHEUS_MODULE}/prometheus-opts && get_prometheus_opts)"
#
# Env Vars respected:
#
# AB_PROMETHEUS_OFF: Disables the use of Prometheus Java Agent.
#
# AB_PROMETHEUS_PORT: Port to use for the Prometheus JMX Exporter.
# Defaults to 9779.
#
# AB_PROMETHEUS_JMX_EXPORTER_CONFIG: Path to configuration to use for the
# Prometheus JMX Exporter. Defaults to:
# /opt/jboss/container/prometheus/etc/jmx-exporter-config.yaml
#

source "$JBOSS_CONTAINER_UTIL_LOGGING_MODULE/logging.sh"

# echo's a complete -javaagent option based on the above variables.
function get_prometheus_opts() {
if ! echo "${AB_PROMETHEUS_OFF:-false}" | grep -q -e '^\(true\|y\|yes\|1\)$'; then
echo "-javaagent:/usr/share/java/prometheus-jmx-exporter/jmx_prometheus_javaagent.jar=${AB_PROMETHEUS_PORT:-9779}:${AB_PROMETHEUS_JMX_EXPORTER_CONFIG:-/opt/jboss/container/prometheus/etc/jmx-exporter-config.yaml}"
fi
echo ""
}
13 changes: 13 additions & 0 deletions modules/jboss.container.prometheus-override/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
# Configure module
set -e

SCRIPT_DIR=$(dirname $0)
ARTIFACTS_DIR=${SCRIPT_DIR}/artifacts

chown -R jboss:root ${ARTIFACTS_DIR}
chmod 755 ${ARTIFACTS_DIR}/opt/jboss/container/prometheus/prometheus-opts

pushd ${ARTIFACTS_DIR}
cp -pr * /
popd
17 changes: 17 additions & 0 deletions modules/jboss.container.prometheus-override/module.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
schema_version: 1
name: jboss.container.prometheus-override
version: 1.0.0
description: ^
Overrides prometheus options script defined in jboss module.
https://github.com/jboss-openshift/cct_module/tree/8411125f8e1b45d48c93c8bcd51d39541ce4a755/jboss/container/prometheus

envs:
- name: AB_PROMETHEUS_OFF
description: Disable the use of prometheus agent
example: true
- name: AB_PROMETHEUS_PORT
description: Port to use for the Prometheus JMX Exporter.
example: 9799

execute:
- script: configure.sh

0 comments on commit 2981876

Please sign in to comment.