Giter Club home page Giter Club logo

tomcat_exporter's Introduction

Prometheus Tomcat Exporter

A set of collectors that can be used to monitor Apache Tomcat instances.

Available metrics

The following Tomcat related metrics are provided:

  • Thread pool metrics
  • Session metrics
  • Request processor metrics
  • Database connection pool metrics
  • Tomcat version info
  • Servlet response time metrics
  • Database response time metrics

Using this library

If you are running Tomcat in the conventional non-embedded setup we recommended to add the following jars (see pom.xml) to the $CATALINA_BASE/lib directory or another directory on the Tomcat common.loader path. Using the common.loader is important as we need to make sure that all metrics are registered using the same class loader.

Next, rename tomcat_exporter_servlet war file to metrics.war and add it to the webapps directory of Tomcat. After restart of tomcat you should be able to access metrics via the /metrics/ endpoint.

Servlet response time metrics

If you want servlet response time metrics you can configure the TomcatServletMetricsFilter by adding it to the $CATALINA_BASE/conf/web.xml as shown below. There is no need to modify already deployed applications.

<filter>
  <filter-name>ServletMetricsFilter</filter-name>
  <filter-class>nl.nlighten.prometheus.tomcat.TomcatServletMetricsFilter</filter-class>
  <async-supported>true</async-supported>
  <init-param>
    <param-name>buckets</param-name>
    <param-value>.01, .05, .1, .25, .5, 1, 2.5, 5, 10, 30</param-value>
  </init-param>
</filter>

<filter-mapping>
  <filter-name>ServletMetricsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

For an explanation on histograms and buckets please see the prometheus documentation.

Database response time metrics

Database response time metrics are only available when using the Tomcat JDBC Pool as this collector uses an interceptor mechanism that is only available for this type of pool.

The interceptor will collect the following metrics:

  • A histogram with global query response times
  • A histogram with per query response times for slow queries (optional)
  • A gauge with per query error counts (optional)

Configuration is usually done in Tomcat's server.xml or context.xml

<Resource name="jdbc/TestDB"
           auth="Container"
           type="javax.sql.DataSource"
           factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
           jdbcInterceptors="nl.nlighten.prometheus.tomcat.TomcatJdbcInterceptor(logFailed=true,logSlow=true,threshold=1000,buckets=.01|.05|.1|1|10,slowQueryBuckets=1|10|30)"
           username="root"
           password="password"
           driverClassName="com.mysql.jdbc.Driver"
           url="jdbc:mysql://localhost:3306/mysql"/>

Configuration options of the interceptor are as shown above and have the following meaning:

  • logFailed: if set to 'true' collect metrics on failed queries
  • logSlow: if set to 'true' collect metrics on metrics exceeding threshold
  • threshold: the threshold in ms above which metrics will be collected if logSlow=true
  • buckets: the buckets separated by a pipe ("|") symbol to be used for the global query response times, defaults to .01|.05|.1|.25|.5|1|2.5|10
  • slowQueryBuckets: the buckets separated by a pipe ("|") symbol to be used for the global query response times, defaults to 1|2.5|10|30

NOTE: enabling logFailed and logSlow may lead to a lot of additional metrics., so be careful !!!

Embedded mode

If you run Tomcat in embedded mode, please look at the AbstractTomcatMetricsTest for an example on how to configure the various exporters when running embedded.

Javadocs

There are canonical examples defined in the class definition Javadoc of the client packages.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.