Integrate Hibernate JMX metrics with Datadog

11/14/2019

I have a web application running on Google Cloud Platform using Docker and Kubernetes. We are using Datadog version 5 to visualize our metrics, and it's already integrated with our system.

My problem is that I enabled Hibernate JMX reporting (verified with JConsole that it works), but I could not figure out the right configuration to enable these metrics in Datadog.

I followed this article to integrate, but for Hibernate, it looks a bit different, see the two images below (how Hibernate looks like on JConsole). The blacked text is our application name):

JConsole for domain -> type -> bean -> attribute

JConsole for domain -> bean -> attribute

Here's the working datadog configuration we use:

annotations:
        service-discovery.datadoghq.com/web-api-new-vpc.check_names: '["jmx"]'
        service-discovery.datadoghq.com/web-api-new-vpc.init_configs: '[{}]'
        service-discovery.datadoghq.com/web-api-new-vpc.instances: >
          [{
            "host": "%%host%%",
            "jmx_url": "service:jmx:rmi:///jndi/rmi://%%host%%:4567/jmxrmi",
            "tags": {"kubernetes_pod_name":"%%host%%"},
            "conf": [{
              "include": {
                "domain": "metrics",
                "attribute": [
                  "99thPercentile",
                  "Count",
                  "Max",
                  "Mean",
                  "OneMinuteRate",
                  "RateUnit",
                  "Value"
                ]
              }
            },{
              "include": {
                "domain": "org.eclipse.jetty.server",
                "attribute": [
                  "acceptQueueSize"
                ]
              }
            }]
          }]

And based on the tutorial I've linked, this is what I've tried:

annotations:
        service-discovery.datadoghq.com/web-api-new-vpc.check_names: '["jmx"]'
        service-discovery.datadoghq.com/web-api-new-vpc.init_configs: '[{}]'
        service-discovery.datadoghq.com/web-api-new-vpc.instances: >
          [
            {
              "host": "%%host%%",
              "jmx_url": "service:jmx:rmi:///jndi/rmi://%%host%%:4567/jmxrmi",
              "tags": {
                "kubernetes_pod_name": "%%host%%"
              },
              "conf": [
                {
                  "include": {
                    "domain": "metrics",
                    "attribute": [
                      "99thPercentile",
                      "Count",
                      "Max",
                      "Mean",
                      "OneMinuteRate",
                      "RateUnit",
                      "Value"
                    ]
                  }
                },
                {
                  "include": {
                    "domain": "org.eclipse.jetty.server",
                    "attribute": [
                      "acceptQueueSize"
                    ]
                  }
                },
                {
                  "include": {
                    "domain": "org.hibernate.core",
                    "bean": "org.hibernate.core:sessionFactory=my-application,serviceRole=org.hibernate.stat.spi.StatisticsImplementor,serviceType=org.hibernate.stat.internal.StatisticsImpl",
                    "attribute": [
                      {
                        "QueryExecutionCount": {
                          "alias": "hibernate.queryexecutioncount"
                        }
                      },
                      {
                        "EntityLoadCount": {
                          "alias": "hibernate.entityloadcount"
                        }
                      }
                    ]
                  }
                }
              ]
            }
          ]

I'm pretty sure that my problem is just a matter of configuration entries, but so far I was unable to figure out the right one.

-- maestro
datadog
hibernate
java
jmx
kubernetes

0 Answers