exporter_type: sidecar
app_name_short: Tomcat
app_name: Apache {{app_name_short}}
app_site_name: {{app_name}}
app_site_url: https://tomcat.apache.org/
exporter_name: the JMX exporter
exporter_pkg_name: jmx-exporter
exporter_repo_url: https://github.com/bitnami/containers/tree/main/bitnami/jmx-exporter
dashboard_available: true
minimum_exporter_version: "0.17.0"
multiple_dashboards: false
dashboard_display_name: {{app_name_short}} Prometheus Overview
config_mods: |
  apiVersion: v1
  kind: ConfigMap
  metadata:
    name: tomcat-exporter
  data:
    config.yml: |
      hostPort: 127.0.0.1:9010
      lowercaseOutputLabelNames: true
      lowercaseOutputName: true
      rules:
      - pattern: 'Catalina<type=GlobalRequestProcessor, name=\"(\w+-\w+)-(\d+)\"><>(\w+):'
        name: tomcat_$3_total
        labels:
          port: "$2"
          protocol: "$1"
        help: Tomcat global $3
        type: COUNTER
      - pattern: 'Catalina<j2eeType=Servlet, WebModule=//([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), name=([-a-zA-Z0-9+/$%~_-|!.]*), J2EEApplication=none, J2EEServer=none><>(requestCount|maxTime|processingTime|errorCount):'
        name: tomcat_servlet_$3_total
        labels:
          module: "$1"
          servlet: "$2"
        help: Tomcat servlet $3 total
        type: COUNTER
      - pattern: 'Catalina<type=ThreadPool, name="(\w+-\w+)-(\d+)"><>(currentThreadCount|currentThreadsBusy|keepAliveCount|pollerThreadCount|connectionCount):'
        name: tomcat_threadpool_$3
        labels:
          port: "$2"
          protocol: "$1"
        help: Tomcat threadpool $3
        type: GAUGE
      - pattern: 'Catalina<type=Manager, host=([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), context=([-a-zA-Z0-9+/$%~_-|!.]*)><>(processingTime|sessionCounter|rejectedSessions|expiredSessions):'
        name: tomcat_session_$3_total
        labels:
          context: "$2"
          host: "$1"
        help: Tomcat session $3 total
        type: COUNTER
  ---
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: tomcat
  spec:
    selector:
      matchLabels:
  +     app.kubernetes.io/name: tomcat
    template:
      metadata:
        labels:
  +       app.kubernetes.io/name: tomcat
      spec:
        containers:
          - name: tomcat
            image: tomcat:9.0.46-jdk11-openjdk-buster
            ports:
              - containerPort: 8080
                name: http
            env:
  +           - name: CATALINA_OPTS
  +             value: "-Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.rmi.port=9010"
  +       - name: exporter
  +         image: bitnami/jmx-exporter:0.17.0
  +         ports:
  +           - containerPort: 9113
  +             name: prometheus
  +         command:
  +           - java
  +           - -jar
  +           - jmx_prometheus_httpserver.jar
  +         args:
  +           - "9113"
  +           - /opt/jmx_exporter/config.yml
  +         volumeMounts:
  +           - mountPath: /opt/jmx_exporter/config.yml
  +             subPath: config.yml
  +             name: tomcat-exporter
  +     volumes:
  +       - name: tomcat-exporter
  +         configMap:
  +           name: tomcat-exporter
  +           items:
  +             - key: config.yml
  +               path: config.yml
additional_prereq_info: |
  Tomcat supports JMX, which can be enabled by configuring the `CATALINA_OPTS`
  environment variable.
podmonitoring_config: |
  apiVersion: monitoring.googleapis.com/v1
  kind: PodMonitoring
  metadata:
    name: tomcat
    labels:
      app.kubernetes.io/name: tomcat
      app.kubernetes.io/part-of: google-cloud-managed-prometheus
  spec:
    endpoints:
    - port: prometheus
      scheme: http
      interval: 30s
      path: /metrics
    selector:
      matchLabels:
        app.kubernetes.io/name: tomcat
sample_promql_query: up{job="tomcat", cluster="{{cluster_name}}", namespace="{{namespace_name}}"}
alerts_config: |
  apiVersion: monitoring.googleapis.com/v1
  kind: Rules
  metadata:
    name: tomcat-rules
    labels:
      app.kubernetes.io/component: rules
      app.kubernetes.io/name: tomcat-rules
      app.kubernetes.io/part-of: google-cloud-managed-prometheus
  spec:
    groups:
    - name: tomcat
      interval: 30s
      rules:
      - alert: TomcatHighRequestRate
        annotations:
          description: |-
            Tomcat high request rate
              VALUE = {{ $value }}
              LABELS: {{ $labels }}
          summary: Tomcat high request rate (instance {{ $labels.instance }})
        expr: rate(tomcat_requestcount_total[5m]) >= 100
        for: 5m
        labels:
          severity: warning
      - alert: TomcatLowRequestRate
        annotations:
          description: |-
            Tomcat low request rate
              VALUE = {{ $value }}
              LABELS: {{ $labels }}
          summary: Tomcat low request rate (instance {{ $labels.instance }})
        expr: rate(tomcat_requestcount_total[5m]) <= 10
        for: 5m
        labels:
          severity: warning
      - alert: TomcatHighErrorRate
        annotations:
          description: |-
            Tomcat high error rate
              VALUE = {{ $value }}
              LABELS: {{ $labels }}
          summary: Tomcat high error rate (instance {{ $labels.instance }})
        expr: rate(tomcat_errorcount_total[5m]) > 100
        for: 5m
        labels:
          severity: warning
additional_alert_info: You can adjust the alert thresholds to suit your application.
