Skip to content

Commit

Permalink
feat: expose prometheus metrics via jmx exporter (#1573)
Browse files Browse the repository at this point in the history
* feat: add support to expose prometheus metrics via jmx exporter

* docs: fix typo on prometheus-config file extension

* fix: add ARG to specify prometheus agent version

* feat(config-api): add support to expose prometheus metrics via jmx exporter

* feat(fido2): add support to expose prometheus metrics via jmx exporter

* feat(scim): add support to expose prometheus metrics via jmx exporter

* feat(client-api): add support to expose prometheus metrics via jmx exporter
  • Loading branch information
iromli authored Jun 21, 2022
1 parent 93e042a commit 205e320
Show file tree
Hide file tree
Showing 27 changed files with 225 additions and 6 deletions.
13 changes: 12 additions & 1 deletion docker-jans-auth-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ RUN python3 -m ensurepip \
&& pip3 install --no-cache-dir --default-timeout=300 -r /app/requirements.txt \
&& pip3 uninstall -y pip wheel

# ==========
# Prometheus
# ==========

ARG PROMETHEUS_JAVAAGENT_VERSION=0.17.0
COPY conf/prometheus-config.yaml /opt/prometheus/
RUN mkdir -p /opt/prometheus \
&& wget -q https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/${PROMETHEUS_JAVAAGENT_VERSION}/jmx_prometheus_javaagent-${PROMETHEUS_JAVAAGENT_VERSION}.jar -O /opt/prometheus/jmx_prometheus_javaagent.jar \
&& java -jar ${JETTY_HOME}/start.jar jetty.home=${JETTY_HOME} jetty.base=${JETTY_BASE}/jans-auth --add-module=jmx,stats

# =======
# Cleanup
# =======
Expand Down Expand Up @@ -231,7 +241,8 @@ ENV CN_MAX_RAM_PERCENTAGE=75.0 \
GOOGLE_PROJECT_ID="" \
GOOGLE_APPLICATION_CREDENTIALS=/etc/jans/conf/google-credentials.json \
ADMIN_UI_JWKS=http://0.0.0.0:8080/jans-auth/restv1/jwks \
CN_JETTY_REQUEST_HEADER_SIZE=8192
CN_JETTY_REQUEST_HEADER_SIZE=8192 \
CN_PROMETHEUS_PORT=""

# ==========
# misc stuff
Expand Down
11 changes: 11 additions & 0 deletions docker-jans-auth-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ The following environment variables are supported by the container:
- `CN_GOOGLE_SPANNER_DATABASE_ID`: Google Spanner database ID.
- `CN_JETTY_REQUEST_HEADER_SIZE`: Maximum size of request header accepted by Jetty (default to `8192`).
- `CN_AUTH_APP_LOGGERS`: Custom logging configuration in JSON-string format with hash type (see [Configure app loggers](#configure-app-loggers) section for details).
- `CN_PROMETHEUS_PORT`: Port used by Prometheus JMX agent (default to empty string). To enable Prometheus JMX agent, set the value to a number. See [Exposing metrics](#exposing-metrics) for details.

### Configure app loggers

Expand Down Expand Up @@ -146,3 +147,13 @@ As per v1.0.1, hybrid persistence supports all available persistence types. To c
"session": "spanner",
}
```

### Exposing metrics

As per v1.0.1, certain metrics can be exposed via Prometheus JMX exporter.
To expose the metrics, set the `CN_PROMETHEUS_PORT` environment variable, i.e. `CN_PROMETHEUS_PORT=9093`.
Afterwards, metrics can be scraped by Prometheus or accessed manually by making request to `/metrics` URL,
i.e. `http://container:9093/metrics`.

Note that Prometheus JMX exporter uses pre-defined config file (see `conf/prometheus-config.yaml`).
To customize the config, mount custom config file to `/opt/prometheus/prometheus-config.yaml` inside the container.
10 changes: 10 additions & 0 deletions docker-jans-auth-server/conf/prometheus-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
startDelaySeconds: 0
ssl: false
lowercaseOutputName: true
lowercaseOutputLabelNames: true
whitelistObjectNames: ["org.eclipse.jetty.server.handler:*"]
rules:
- pattern: ".*xx"
- pattern: ".*requests"
- pattern: ".*requestTimeTotal"
12 changes: 12 additions & 0 deletions docker-jans-auth-server/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ move_builtin_jars() {
fi
}

get_prometheus_opt() {
prom_opt=""

if [ -n "${CN_PROMETHEUS_PORT}" ]; then
prom_opt="
-javaagent:/opt/prometheus/jmx_prometheus_javaagent.jar=${CN_PROMETHEUS_PORT}:/opt/prometheus/prometheus-config.yaml
"
fi
echo "${prom_opt}"
}

# ==========
# ENTRYPOINT
# ==========
Expand All @@ -57,6 +68,7 @@ exec java \
-Djava.io.tmpdir=/tmp \
-Dlog4j2.configurationFile=resources/log4j2.xml \
$(get_debug_opt) \
$(get_prometheus_opt) \
${CN_JAVA_OPTIONS} \
-jar /opt/jetty/start.jar \
jetty.deploy.scanInterval=0 \
Expand Down
2 changes: 1 addition & 1 deletion docker-jans-client-api/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# include required files/directories
!scripts
!templates
!conf
!LICENSE
!requirements.txt
!jetty
12 changes: 11 additions & 1 deletion docker-jans-client-api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ RUN python3 -m ensurepip \
&& pip3 install --no-cache-dir -r /app/requirements.txt \
&& pip3 uninstall -y pip wheel

# ==========
# Prometheus
# ==========

ARG PROMETHEUS_JAVAAGENT_VERSION=0.17.0
COPY conf/prometheus-config.yaml /opt/prometheus/
RUN mkdir -p /opt/prometheus \
&& wget -q https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/${PROMETHEUS_JAVAAGENT_VERSION}/jmx_prometheus_javaagent-${PROMETHEUS_JAVAAGENT_VERSION}.jar -O /opt/prometheus/jmx_prometheus_javaagent.jar \
&& java -jar ${JETTY_HOME}/start.jar jetty.home=${JETTY_HOME} jetty.base=${JETTY_BASE}/jans-client-api --add-module=jmx,stats

# =====================
# jans-linux-setup sync
# =====================
Expand Down Expand Up @@ -206,7 +216,7 @@ LABEL name="janssenproject/client-api" \
RUN mkdir -p /etc/certs /etc/jans/conf ${JETTY_BASE}/jans-client-api/logs
COPY jetty/log4j2.xml ${JETTY_BASE}/jans-client-api/resources/
COPY scripts /app/scripts
COPY templates/*.tmpl /app/templates/
COPY conf/*.tmpl /app/templates/
RUN chmod +x /app/scripts/entrypoint.sh

# create non-root user
Expand Down
11 changes: 11 additions & 0 deletions docker-jans-client-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ The following environment variables are supported by the container:
- `GOOGLE_PROJECT_ID`: Google Project ID (default to empty string). Used when `CN_CONFIG_ADAPTER` or `CN_SECRET_ADAPTER` set to `google`.
- `GOOGLE_APPLICATION_CREDENTIALS`: Path to Google credentials JSON file (default to `/etc/jans/conf/google-credentials.json`). Used when `CN_CONFIG_ADAPTER` or `CN_SECRET_ADAPTER` set to `google`.
- `CN_CLIENT_API_APP_LOGGERS`: Custom logging configuration in JSON-string format with hash type (see [Configure app loggers](#configure-app-loggers) section for details).
- `CN_PROMETHEUS_PORT`: Port used by Prometheus JMX agent (default to empty string). To enable Prometheus JMX agent, set the value to a number. See [Exposing metrics](#exposing-metrics) for details.

### Configure app loggers

Expand Down Expand Up @@ -133,3 +134,13 @@ As per v1.0.1, hybrid persistence supports all available persistence types. To c
"session": "spanner",
}
```

### Exposing metrics

As per v1.0.1, certain metrics can be exposed via Prometheus JMX exporter.
To expose the metrics, set the `CN_PROMETHEUS_PORT` environment variable, i.e. `CN_PROMETHEUS_PORT=9093`.
Afterwards, metrics can be scraped by Prometheus or accessed manually by making request to `/metrics` URL,
i.e. `http://container:9093/metrics`.

Note that Prometheus JMX exporter uses pre-defined config file (see `conf/prometheus-config.yaml`).
To customize the config, mount custom config file to `/opt/prometheus/prometheus-config.yaml` inside the container.
10 changes: 10 additions & 0 deletions docker-jans-client-api/conf/prometheus-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
startDelaySeconds: 0
ssl: false
lowercaseOutputName: true
lowercaseOutputLabelNames: true
whitelistObjectNames: ["org.eclipse.jetty.server.handler:*"]
rules:
- pattern: ".*xx"
- pattern: ".*requests"
- pattern: ".*requestTimeTotal"
File renamed without changes.
12 changes: 12 additions & 0 deletions docker-jans-client-api/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

set -e

get_prometheus_opt() {
prom_opt=""

if [ -n "${CN_PROMETHEUS_PORT}" ]; then
prom_opt="
-javaagent:/opt/prometheus/jmx_prometheus_javaagent.jar=${CN_PROMETHEUS_PORT}:/opt/prometheus/prometheus-config.yaml
"
fi
echo "${prom_opt}"
}

python3 /app/scripts/wait.py
python3 /app/scripts/bootstrap.py

Expand All @@ -21,6 +32,7 @@ exec java \
-Djava.io.tmpdir=/tmp \
-Dpython.home=/opt/jython \
-Dlog4j2.configurationFile=resources/log4j2.xml \
$(get_prometheus_opt) \
${CN_JAVA_OPTIONS} \
-jar /opt/jetty/start.jar \
jetty.deploy.scanInterval=0 \
Expand Down
13 changes: 12 additions & 1 deletion docker-jans-config-api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ RUN python3 -m ensurepip \
&& pip3 install --no-cache-dir --default-timeout=300 -r /app/requirements.txt \
&& pip3 uninstall -y pip wheel

# ==========
# Prometheus
# ==========

ARG PROMETHEUS_JAVAAGENT_VERSION=0.17.0
COPY conf/prometheus-config.yaml /opt/prometheus/
RUN mkdir -p /opt/prometheus \
&& wget -q https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/${PROMETHEUS_JAVAAGENT_VERSION}/jmx_prometheus_javaagent-${PROMETHEUS_JAVAAGENT_VERSION}.jar -O /opt/prometheus/jmx_prometheus_javaagent.jar \
&& java -jar ${JETTY_HOME}/start.jar jetty.home=${JETTY_HOME} jetty.base=${JETTY_BASE}/jans-config-api --add-module=jmx,stats

# =======
# Cleanup
# =======
Expand Down Expand Up @@ -168,7 +178,8 @@ ENV CN_MAX_RAM_PERCENTAGE=75.0 \
CN_WAIT_SLEEP_DURATION=10 \
CN_JAVA_OPTIONS="" \
GOOGLE_PROJECT_ID="" \
GOOGLE_APPLICATION_CREDENTIALS=/etc/jans/conf/google-credentials.json
GOOGLE_APPLICATION_CREDENTIALS=/etc/jans/conf/google-credentials.json \
CN_PROMETHEUS_PORT=""

# ====
# misc
Expand Down
11 changes: 11 additions & 0 deletions docker-jans-config-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ The following environment variables are supported by the container:
- `CN_CONFIG_API_PLUGINS`: Comma-separated plugin names that should be enabled (available plugins are `admin-ui` and `scim`).
- `CN_TOKEN_SERVER_CERT_FILE`: Path to token server certificate (default to `/etc/certs/token_server.crt`).
- `CN_ADMIN_UI_PLUGIN_LOGGERS`: Custom logging configuration for AdminUI plugin in JSON-string format with hash type (see [Configure plugin loggers](#configure-plugin-loggers) section for details).
- `CN_PROMETHEUS_PORT`: Port used by Prometheus JMX agent (default to empty string). To enable Prometheus JMX agent, set the value to a number. See [Exposing metrics](#exposing-metrics) for details.

### Configure app loggers

Expand Down Expand Up @@ -167,3 +168,13 @@ As per v1.0.1, hybrid persistence supports all available persistence types. To c
"session": "spanner",
}
```

### Exposing metrics

As per v1.0.1, certain metrics can be exposed via Prometheus JMX exporter.
To expose the metrics, set the `CN_PROMETHEUS_PORT` environment variable, i.e. `CN_PROMETHEUS_PORT=9093`.
Afterwards, metrics can be scraped by Prometheus or accessed manually by making request to `/metrics` URL,
i.e. `http://container:9093/metrics`.

Note that Prometheus JMX exporter uses pre-defined config file (see `conf/prometheus-config.yaml`).
To customize the config, mount custom config file to `/opt/prometheus/prometheus-config.yaml` inside the container.
10 changes: 10 additions & 0 deletions docker-jans-config-api/conf/prometheus-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
startDelaySeconds: 0
ssl: false
lowercaseOutputName: true
lowercaseOutputLabelNames: true
whitelistObjectNames: ["org.eclipse.jetty.server.handler:*"]
rules:
- pattern: ".*xx"
- pattern: ".*requests"
- pattern: ".*requestTimeTotal"
12 changes: 12 additions & 0 deletions docker-jans-config-api/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ get_logging_files() {
echo $logs
}

get_prometheus_opt() {
prom_opt=""

if [ -n "${CN_PROMETHEUS_PORT}" ]; then
prom_opt="
-javaagent:/opt/prometheus/jmx_prometheus_javaagent.jar=${CN_PROMETHEUS_PORT}:/opt/prometheus/prometheus-config.yaml
"
fi
echo "${prom_opt}"
}

python3 /app/scripts/wait.py

copy_builtin_plugins
Expand All @@ -39,6 +50,7 @@ exec java \
-Dlog.base=/opt/jans/jetty/jans-config-api \
-Djava.io.tmpdir=/tmp \
-Dlog4j2.configurationFile=$(get_logging_files) \
$(get_prometheus_opt) \
${CN_JAVA_OPTIONS} \
-jar /opt/jetty/start.jar \
jetty.http.port=8074 \
Expand Down
13 changes: 12 additions & 1 deletion docker-jans-fido2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ RUN python3 -m ensurepip \
&& pip3 install --no-cache-dir -r /app/requirements.txt \
&& pip3 uninstall -y pip wheel

# ==========
# Prometheus
# ==========

ARG PROMETHEUS_JAVAAGENT_VERSION=0.17.0
COPY conf/prometheus-config.yaml /opt/prometheus/
RUN mkdir -p /opt/prometheus \
&& wget -q https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/${PROMETHEUS_JAVAAGENT_VERSION}/jmx_prometheus_javaagent-${PROMETHEUS_JAVAAGENT_VERSION}.jar -O /opt/prometheus/jmx_prometheus_javaagent.jar \
&& java -jar ${JETTY_HOME}/start.jar jetty.home=${JETTY_HOME} jetty.base=${JETTY_BASE}/jans-fido2 --add-module=jmx,stats

# =======
# Cleanup
# =======
Expand Down Expand Up @@ -179,7 +189,8 @@ ENV CN_MAX_RAM_PERCENTAGE=75.0 \
CN_WAIT_SLEEP_DURATION=10 \
CN_JAVA_OPTIONS="" \
GOOGLE_PROJECT_ID="" \
GOOGLE_APPLICATION_CREDENTIALS=/etc/jans/conf/google-credentials.json
GOOGLE_APPLICATION_CREDENTIALS=/etc/jans/conf/google-credentials.json \
CN_PROMETHEUS_PORT=""

# ==========
# misc stuff
Expand Down
11 changes: 11 additions & 0 deletions docker-jans-fido2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ The following environment variables are supported by the container:
- `GOOGLE_PROJECT_ID`: Google Project ID (default to empty string). Used when `CN_CONFIG_ADAPTER` or `CN_SECRET_ADAPTER` set to `google`.
- `GOOGLE_APPLICATION_CREDENTIALS`: Path to Google credentials JSON file (default to `/etc/jans/conf/google-credentials.json`). Used when `CN_CONFIG_ADAPTER` or `CN_SECRET_ADAPTER` set to `google`.
- `CN_FIDO2_APP_LOGGERS`: Custom logging configuration in JSON-string format with hash type (see [Configure app loggers](#configure-app-loggers) section for details).
- `CN_PROMETHEUS_PORT`: Port used by Prometheus JMX agent (default to empty string). To enable Prometheus JMX agent, set the value to a number. See [Exposing metrics](#exposing-metrics) for details.

### Configure app loggers

Expand Down Expand Up @@ -125,3 +126,13 @@ As per v1.0.1, hybrid persistence supports all available persistence types. To c
"session": "spanner",
}
```

### Exposing metrics

As per v1.0.1, certain metrics can be exposed via Prometheus JMX exporter.
To expose the metrics, set the `CN_PROMETHEUS_PORT` environment variable, i.e. `CN_PROMETHEUS_PORT=9093`.
Afterwards, metrics can be scraped by Prometheus or accessed manually by making request to `/metrics` URL,
i.e. `http://container:9093/metrics`.

Note that Prometheus JMX exporter uses pre-defined config file (see `conf/prometheus-config.yaml`).
To customize the config, mount custom config file to `/opt/prometheus/prometheus-config.yaml` inside the container.
10 changes: 10 additions & 0 deletions docker-jans-fido2/conf/prometheus-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
startDelaySeconds: 0
ssl: false
lowercaseOutputName: true
lowercaseOutputLabelNames: true
whitelistObjectNames: ["org.eclipse.jetty.server.handler:*"]
rules:
- pattern: ".*xx"
- pattern: ".*requests"
- pattern: ".*requestTimeTotal"
12 changes: 12 additions & 0 deletions docker-jans-fido2/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

set -e

get_prometheus_opt() {
prom_opt=""

if [ -n "${CN_PROMETHEUS_PORT}" ]; then
prom_opt="
-javaagent:/opt/prometheus/jmx_prometheus_javaagent.jar=${CN_PROMETHEUS_PORT}:/opt/prometheus/prometheus-config.yaml
"
fi
echo "${prom_opt}"
}

python3 /app/scripts/wait.py
python3 /app/scripts/bootstrap.py

Expand All @@ -16,5 +27,6 @@ exec java \
-Dlog.base=/opt/jans/jetty/jans-fido2 \
-Djava.io.tmpdir=/tmp \
-Dlog4j2.configurationFile=resources/log4j2.xml \
$(get_prometheus_opt) \
${CN_JAVA_OPTIONS} \
-jar /opt/jetty/start.jar jetty.deploy.scanInterval=0 jetty.httpConfig.sendServerVersion=false
13 changes: 12 additions & 1 deletion docker-jans-scim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ RUN python3 -m ensurepip \
&& pip3 install --no-cache-dir -r /app/requirements.txt \
&& pip3 uninstall -y pip wheel

# ==========
# Prometheus
# ==========

ARG PROMETHEUS_JAVAAGENT_VERSION=0.17.0
COPY conf/prometheus-config.yaml /opt/prometheus/
RUN mkdir -p /opt/prometheus \
&& wget -q https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/${PROMETHEUS_JAVAAGENT_VERSION}/jmx_prometheus_javaagent-${PROMETHEUS_JAVAAGENT_VERSION}.jar -O /opt/prometheus/jmx_prometheus_javaagent.jar \
&& java -jar ${JETTY_HOME}/start.jar jetty.home=${JETTY_HOME} jetty.base=${JETTY_BASE}/jans-scim --add-module=jmx,stats

# =======
# Cleanup
# =======
Expand Down Expand Up @@ -154,7 +164,8 @@ ENV CN_MAX_RAM_PERCENTAGE=75.0 \
CN_WAIT_SLEEP_DURATION=10 \
CN_JAVA_OPTIONS="" \
GOOGLE_PROJECT_ID="" \
GOOGLE_APPLICATION_CREDENTIALS=/etc/jans/conf/google-credentials.json
GOOGLE_APPLICATION_CREDENTIALS=/etc/jans/conf/google-credentials.json \
CN_PROMETHEUS_PORT=""

# ==========
# misc stuff
Expand Down
11 changes: 11 additions & 0 deletions docker-jans-scim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ The following environment variables are supported by the container:
- `GOOGLE_PROJECT_ID`: Google Project ID (default to empty string). Used when `CN_CONFIG_ADAPTER` or `CN_SECRET_ADAPTER` set to `google`.
- `GOOGLE_APPLICATION_CREDENTIALS`: Path to Google credentials JSON file (default to `/etc/jans/conf/google-credentials.json`). Used when `CN_CONFIG_ADAPTER` or `CN_SECRET_ADAPTER` set to `google`.
- `CN_SCIM_APP_LOGGERS`: Custom logging configuration in JSON-string format with hash type (see [Configure app loggers](#configure-app-loggers) section for details).
- `CN_PROMETHEUS_PORT`: Port used by Prometheus JMX agent (default to empty string). To enable Prometheus JMX agent, set the value to a number. See [Exposing metrics](#exposing-metrics) for details.

### Configure app loggers

Expand Down Expand Up @@ -131,3 +132,13 @@ As per v1.0.1, hybrid persistence supports all available persistence types. To c
"session": "spanner",
}
```

### Exposing metrics

As per v1.0.1, certain metrics can be exposed via Prometheus JMX exporter.
To expose the metrics, set the `CN_PROMETHEUS_PORT` environment variable, i.e. `CN_PROMETHEUS_PORT=9093`.
Afterwards, metrics can be scraped by Prometheus or accessed manually by making request to `/metrics` URL,
i.e. `http://container:9093/metrics`.

Note that Prometheus JMX exporter uses pre-defined config file (see `conf/prometheus-config.yaml`).
To customize the config, mount custom config file to `/opt/prometheus/prometheus-config.yaml` inside the container.
Loading

0 comments on commit 205e320

Please sign in to comment.