Skip to content

Commit

Permalink
Merge pull request #112 from OneBusAway/feat/jmx-setup
Browse files Browse the repository at this point in the history
Feat/jmx-setup
  • Loading branch information
aaronbrethorst authored Jan 7, 2025
2 parents 4809c6f + 6541cb4 commit 5f38be8
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 10 deletions.
1 change: 1 addition & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ services:
# Access the webapp on your host machine at a path like
# http://localhost:8080/onebusaway-api-webapp/api/where/agency/${YOUR_AGENCY}.json?key=TEST
- "8080:8080"
- "1234:1234" # JMX exporter port
# restart: always
labels:
caddy: "${DOMAIN}"
Expand Down
14 changes: 13 additions & 1 deletion docker-compose.standalone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,20 @@ services:
# Access the webapp on your host machine at a path like
# http://localhost:8080/onebusaway-api-webapp/api/where/agency/${YOUR_AGENCY}.json?key=TEST
- "8080:8080"
- "1234:1234" # JMX exporter port

# Uncomment the following section to test with prometheus and the JMX exporter in localhost
# networks:
# - monitoring
# - default
# restart: always

# Uncomment the following section to test with prometheus and the JMX exporter in localhost
# networks:
# monitoring:
# external: true


volumes:
mysql-data:
pg-data:
pg-data:
13 changes: 12 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,19 @@ services:
# Access the webapp on your host machine at a path like
# http://localhost:8080/onebusaway-api-webapp/api/where/agency/${YOUR_AGENCY}.json?key=TEST
- "8080:8080"
- "1234:1234" # JMX exporter port

# networks:
# - monitoring
# - default
# restart: always


# Uncomment the following section to test with prometheus and the JMX exporter in localhost
# networks:
# monitoring:
# external: true

volumes:
mysql-data:
pg-data:
pg-data:
29 changes: 21 additions & 8 deletions oba/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,23 @@ WORKDIR $CATALINA_HOME/webapps
##########

COPY --from=builder \
--chown=oba_user:oba_group \
/oba/libs/onebusaway-api-webapp.war .
--chown=oba_user:oba_group \
/oba/libs/onebusaway-api-webapp.war .

RUN mkdir ROOT && \
cd ROOT && \
jar xvf ../onebusaway-api-webapp.war && \
rm ../onebusaway-api-webapp.war

COPY --from=builder \
--chown=oba_user:oba_group \
/oba/libs/mysql-connector-j.jar \
$CATALINA_HOME/webapps/ROOT/WEB-INF/lib/
--chown=oba_user:oba_group \
/oba/libs/mysql-connector-j.jar \
$CATALINA_HOME/webapps/ROOT/WEB-INF/lib/

COPY --from=builder \
--chown=oba_user:oba_group \
/oba/libs/postgresql.jar \
$CATALINA_HOME/webapps/ROOT/WEB-INF/lib/
--chown=oba_user:oba_group \
/oba/libs/postgresql.jar \
$CATALINA_HOME/webapps/ROOT/WEB-INF/lib/

RUN mkdir -p /opt/oba/logs
RUN chown -R oba_user:oba_group /opt/oba/logs
Expand Down Expand Up @@ -157,10 +157,23 @@ COPY --from=builder \
RUN apt-get autoremove -y && apt-get clean
RUN rm -rf /oba/webapps



# Jmx exporter

RUN mkdir -p /app && \
wget -O /app/jmx_prometheus_javaagent.jar https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.19.0/jmx_prometheus_javaagent-0.19.0.jar
COPY ./jmx_exporter_config.yml /app/jmx_exporter_config.yml

# Set JVM options to include JMX exporter
ENV JAVA_OPTS="-javaagent:/app/jmx_prometheus_javaagent.jar=1234:/app/jmx_exporter_config.yml"


##########
# Bootstrapper and Supervisor
##########


COPY bootstrap.sh /oba/bootstrap.sh
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN chmod +x /oba/bootstrap.sh
Expand Down
28 changes: 28 additions & 0 deletions oba/jmx_exporter_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
lowercaseOutputLabelNames: true
lowercaseOutputName: true
whitelistObjectNames:
- "java.lang:type=OperatingSystem"
- "java.lang:type=Memory"
- "java.lang:type=MemoryPool,name=*"
blacklistObjectNames: []
rules:
- pattern: "java.lang<type=OperatingSystem><>(committed_virtual_memory|free_physical_memory|free_swap_space|total_physical_memory|total_swap_space)_size:"
name: os_$1_bytes
type: GAUGE
attrNameSnakeCase: true
- pattern: 'java.lang<type=OperatingSystem><>((?!process_cpu_time)\w+):'
name: os_$1
type: GAUGE
attrNameSnakeCase: true

- pattern: "java.lang<type=Memory><>HeapMemoryUsage"
name: "jvm_memory_used_bytes"
type: GAUGE
- pattern: "java.lang<type=Memory><>NonHeapMemoryUsage"
name: jvm_memory_non_heap_usage
type: GAUGE
- pattern: "java.lang<type=MemoryPool, name=.*><>Usage"
name: jvm_memory_pool_usage
type: GAUGE
labels:
pool: "$1"

0 comments on commit 5f38be8

Please sign in to comment.