Tomcat base image with JMX exporter¶
The Tomcat base image with JMX exporter is a containerized runtime environment designed for deploying Java web applications with integrated monitoring capabilities. It combines a standard Apache Tomcat distribution with a JMX Prometheus exporter agent, allowing metrics to be scraped by Prometheus without modifying the application code^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md].
Components¶
This base image typically includes the following key components:
- Apache Tomcat: The servlet container that serves the web applications^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md].
- JMX Exporter Java Agent: A JAR file (e.g.,
jmx_javaagent-0.3.1.jar) that acts as a Java Agent. It attaches to the JVM, exposes JMX metrics (such as memory, GC, and thread pools) via an HTTP endpoint, and formats them for Prometheus^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md]. - Configuration: A
config.ymlfile which defines the JMX patterns and rules the agent should use to collect metrics^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md].
Configuration Details¶
The image is configured to optimize performance and ensure consistent metric collection.
Timezone and Locale¶
The container environment is configured to use the Asia/Shanghai timezone and zh_CN.UTF-8 character encoding to ensure correct time logging and Chinese character support^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md].
JVM Options and Agent Injection¶
An entrypoint.sh script is used to launch the Tomcat server. This script dynamically constructs the JAVA_OPTS to inject the JMX exporter agent^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md].
The agent is activated using the -javaagent flag with specific parameters:
-javaagent:/opt/prom/jmx_javaagent-0.3.1.jar=$(hostname -i):${M_PORT:-"12346"}:/opt/prom/config.yml
This configuration ensures that:
* Metrics Endpoint: The metrics are exposed on port 12346 (by default) at the host's IP address^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md].
* Configuration Source: The agent reads rules from /opt/prom/config.yml^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md].
Tomcat Configuration¶
Before building the image, the Tomcat server.xml configuration is often tweaked to disable the AJP connector for security, and logging.properties is adjusted to remove default handlers for manager/host-manager apps and set the logging level to INFO^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md].
Prometheus Integration¶
To enable Prometheus to discover and scrape these metrics, the Kubernetes Deployment for the application using this base image requires specific annotations^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md].
Example annotations required on the Pod:
* prometheus_io_scrape: true
* prometheus_io_port: 12346
* prometheus_io_path: /
This setup allows the monitoring system to automatically detect the service and collect JVM and application performance data^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md].