> OctoPerf load testing - Apache Tomcat Monitor documentation page. How to configure the Apache Tomcat monitor. Supported versions and available counters.

Source: https://api.octoperf.com/doc/monitoring/create-connection/apache-tomcat/

# Apache Tomcat

![Apache Tomcat Monitoring](https://api.octoperf.com/doc/monitoring/create-connection/apache-tomcat/img/apache-tomcat-logo.png "Apache Tomcat Monitoring")

[Apache Tomcat](http://tomcat.apache.org/) is an open-source web server which can be monitored using the [JMX](https://en.wikipedia.org/wiki/Java_Management_Extensions) protocol. In order to monitor a Tomcat web server, it must be configured to enable JMX monitoring connections.

## Supported versions

Apache Tomcat 7 and above can be monitored. Both anonymous and authenticated JMX connections are supported.

## Enabling JMX Remote

To enable JMX monitoring connections on Tomcat, please follow the relevant procedure depending on the operating system. **TomcatHome** refers to tomcat installation folder. The procedures below are inspired from Tomcat documentation explaining how to <a href="https://tomcat.apache.org/tomcat-7.0-doc/monitoring.html#Enabling_JMX_Remote" target="_blank" rel="noreferrer">enable JMX remoting</a>.

### Linux

Create a file named setenv.sh and put inside:

```bash
#!/bin/bash
CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
```

### Windows

Create a file named setenv.bat and put inside:

```bat
set CATALINA_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false
```

### Optional Authentication

**Enabling authentication is optional**. Authentication protects your server JMX endpoint from being accessible to anyone. An alternative to authentication is to filter access to JMX port (9004 by default) using **IPTables**.

**Enabling authentication**

Add the following JVM parameters to CATALINA_OPTS:

```bat
-Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access
```

Edit the file $CATALINA_BASE/conf/jmxremote.access:

```properties
MonitorRole readonly
controlRole readwrite
```

Edit the file $CATALINA_BASE/conf/jmxremote.password:

```properties
MonitorRole tomcat
controlRole tomcat
```

## Configuration

![Apache Tomcat Wizard](https://api.octoperf.com/doc/monitoring/create-connection/apache-tomcat/img/apache-tomcat-wizard.png "Apache Tomcat Wizard")

*Apache Tomcat Configuration Wizard.*

The Apache Tomcat monitor requires the following settings:

* **Hostname**: hostname or IP of the Apache Tomcat server. It must be reachable from the monitoring agent container,
* **Port**: JMX Remoting port, 9004 by default,
* **Domain**: Defines the Apache Tomcat MBeans domain. *Catalina* is by default,
* **Authentication**: Optionally define username and password.

### Applications

To tailor a monitor counter list fitting the monitored system, the Apache Tomcat monitor asks to select the web applications to monitor.

In this configuration step, a table lists all the web applications deployed on the Tomcat server. select the deployed web applications to monitor then click on *Next*.

### Monitored Counters

The Apache Tomcat monitoring module collects the following metrics:

* **Sessions**:

    * **{hostname}**:

        * **{webapp}**:

            * **activeSessions**: Number of currently active sessions,
            * **sessionCounter**: Total number of created sessions,
            * **maxActive**: Max number of active sessions,
            * **sessionMaxAliveTime**: Max session alive time in ms,
            * **sessionAverageAliveTime**: Average session alive time in ms,
            * **rejectedSessions**: Number of rejected sessions,
            * **expiredSessions**: Number of expired sessions,
            * **% rejectedSessions**: Percent of rejected sessions.

* **RequestProcessor**:

    * **{processor}**:

        * **requestCount**: Number of requests received,
        * **errorCount**: Number of errors encountered,
        * **bytesSent**: Number of bytes sent,
        * **maxTime**: Maximum processing time since server startup in ms,
        * **processingTime**: Current processing time in ms,
        * **% errorCount**: Percent of errors encountered (errorCount / requestCount).

* **DataSource**:

    * **{hostname}**:

        * **{webapp}**:

            * **{datasource}**:

                * **numActive**: Number of active JDBC connections,
                * **numTestsPerEvictionRun**: determines the number of objects examined in each run of the idle object evictor,
                * **numIdle**: Number of idle JDBC connections,
                * **maxActive**: Maximum number of active JDBC connections since server startup,
                * **% numActive**: Percent of active JDBC connections,
                * **maxIdle**: Maximum of idle JDBC connections since server startup,
                * **poolConfiguration**: Textual JDBC connections pool configuration.

* **ThreadPool**:

    * **{threadpool}**:

        * **currentThreadsBusy**: Current number of threads being busy,
        * **currentThreadCount**: Current number of threads being alive,
        * **maxThreads**: Maximum number of threads the pool can spawn,
        * **threadsConfiguration**: Textual thread pool configuration.

* **JVM**:

    * **Memory**:

        * **used**: memory used by the JVM in bytes,
        * **commited**: memory commited by the JVM in bytes,
        * **max**: max JVM memory in bytes,
        * **% used**: Percent used memory (used / max).

    * **Garbage Collector**:

        * **{gcname}**:

            * **CollectionCount**:  Number of garbage collections,
		    * **CollectionTime**: Time spend in garbage collection.

    * **Threading**:

        * **ThreadCount**: Number of threads currently running in the JVM,
        * **DaemonThreadCount**: Number of daemon threads currently running in the JVM,
        * **PeakThreadCount**: Maximum number of threads running since JVM startup.

* **Configuration**:

    * **Operating System**:

        * **Host**: operating system host configuration (CPU, RAM and Swap),

    * **Runtime**:

        * **JVM**: Textual Java Virtual Machine name and version.

The available counters may vary depending on the Tomcat version being monitored.
