Monitor Active Users in Docker with Apache & Tomcat: A Guide (2026)

Discover how to monitor active users in a Docker container running Apache and Tomcat. Leverage Jolokia and alternatives for effective IT monitoring with Icinga 2.

Monitor Active Users in Docker with Apache & Tomcat: A Guide (2026)

Monitor Active Users in Docker with Apache & Tomcat: A Guide (2026)

Monitoring active users in a Docker container running Apache and Tomcat is crucial for ensuring optimal performance and resource allocation. In this guide, we'll explore how to achieve this monitoring using Jolokia and alternative methods, even when Jolokia cannot be embedded directly.

Key Takeaways

  • Learn how to monitor active users in a Docker container with Apache and Tomcat.
  • Understand how to use Jolokia for JMX metric monitoring without embedding it in the container.
  • Discover alternative approaches if Jolokia is not feasible.
  • Integrate monitoring with Icinga 2 for comprehensive IT management.

Monitoring user activity is essential for diagnosing issues and scaling resources effectively. While Jolokia is a powerful tool for JMX metric monitoring, embedding it in the container might not always be possible. This tutorial will guide you through setting up monitoring from outside the container and using alternative solutions if needed.

Prerequisites

  • Basic understanding of Docker, Apache, and Tomcat.
  • Access to the Docker container running Apache and Tomcat.
  • Basic knowledge of Icinga 2 for IT monitoring.
  • Familiarity with JMX metrics and Jolokia (optional).

Step 1: Set Up Jolokia Outside the Container

If embedding Jolokia inside the container is not feasible, you can run Jolokia as a sidecar pattern or on the host system. This setup allows you to remotely access JMX metrics exposed by the Java application inside the container.

# Start Jolokia as a sidecar container
$ docker run -d --name jolokia-agent \
  --network container:your-tomcat-container \
  jolokia/jolokia

Ensure Jolokia is configured to communicate with the Tomcat instance inside your container. You may need to adjust its configuration to match the JMX port and authentication settings.

Step 2: Configure Apache and Tomcat for Monitoring

Configure Apache and Tomcat to expose the necessary metrics. For Apache, you can use the mod_status module, and for Tomcat, ensure JMX monitoring is enabled.

<!-- Enable JMX in Tomcat's server.xml -->
<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" 
          rmiRegistryPortPlatform="9099" 
          rmiServerPortPlatform="9100"/>

For Apache, ensure mod_status is enabled and accessible:

# Load the status module
LoadModule status_module modules/mod_status.so

# Allow server-status from localhost

    SetHandler server-status
    Require host localhost

Step 3: Access and Monitor JMX Metrics

With Jolokia running, you can access JMX metrics using HTTP. Use curl or any HTTP client to query Jolokia for metrics related to active sessions and user activities.

# Query Jolokia for active sessions
$ curl http://localhost:8080/jolokia/read/Catalina:type=Manager,*

The output will provide insights into active sessions, which you can use to determine user activity.

Step 4: Integrate with Icinga 2

Integrate your setup with Icinga 2 to automate and visualize monitoring. Use Icinga's plugins to fetch metrics from Jolokia or Apache's server-status page.

# Example Icinga2 command to check Apache status
object CheckCommand "apache-status" {
  command = [ PluginDir + "/check_http" ]
  arguments = {
    "-I" = {
      value = "$apache_vhost$"
      description = "Virtual host to connect to"
    }
    "-u" = {
      value = "/server-status"
      description = "URL path"
    }
  }
}

This integration allows you to visualize active user data on Icinga's dashboard, setting alerts for when user activity reaches predefined thresholds.

Step 5: Explore Alternative Monitoring Solutions

If Jolokia is not suitable, consider using alternative monitoring solutions like Prometheus with JMX exporter or Elastic APM for more extensive application monitoring.

# Sample Prometheus configuration for JMX exporter
scrape_configs:
  - job_name: 'tomcat'
    static_configs:
      - targets: ['localhost:9273']

Common Errors/Troubleshooting

During setup, you may encounter common issues like network communication errors or authentication problems. Ensure Jolokia has correct access permissions and that firewalls allow traffic to the JMX and Jolokia ports. Verify the configuration files for Apache and Tomcat for any misconfigurations.

By following these steps, you'll be able to effectively monitor active users in a Docker container running Apache and Tomcat, even without embedding Jolokia inside the container.

Frequently Asked Questions

Can Jolokia be used without embedding it in a Docker container?

Yes, Jolokia can be run as a sidecar container or on the host to access JMX metrics remotely.

What are the alternatives to Jolokia for monitoring?

Alternatives include Prometheus with JMX exporter, Elastic APM, and native Tomcat JMX monitoring tools.

How do I integrate monitoring with Icinga 2?

Use Icinga 2 plugins to fetch data from Jolokia or Apache and visualize it on Icinga's dashboard.

What are common issues when setting up Jolokia?

Common issues include network communication errors and misconfigurations in access permissions and authentication.