public synchronized void addJmxReporter(final String domain, final String agentId) {
        if (null != jmxReporter) {
            log.debug("Metrics JmxReporter already active; not creating another");
            return;
        }

        JmxReporter.Builder b = JmxReporter.forRegistry(getRegistry());

        if (null != domain) {
            b.inDomain(domain);
        }

        if (null != agentId) {
            List<MBeanServer> servs = MBeanServerFactory.findMBeanServer(agentId);
            if (null != servs && 1 == servs.size()) {
                b.registerWith(servs.get(0));
            } else {
                log.error("Metrics Slf4jReporter agentId {} does not resolve to a single MBeanServer", agentId);
            }
        }

        jmxReporter = b.build();
        jmxReporter.start();

        log.info("Configured Metrics JmxReporter configured with domain={} and agentId={}",
                Optional.ofNullable(domain).orElse(""), Optional.ofNullable(agentId).orElse(""));
    }
Create a {@link JmxReporter} attached to the {@code MetricsRegistry}.
<p/>
If {@code domain} or {@code agentId} is null, then Metrics's uses its own
internal default value(s).
<p/>
If {@code agentId} is non-null, then
MBeanServerFactory#findMBeanServer(agentId) must return exactly
one {@code MBeanServer}. The reporter will register with that server. If
the {@code findMBeanServer(agentId)} call returns no or multiple servers,
then this method logs an error and falls back on the Metrics default for
{@code agentId}.

@param domain  the JMX domain in which to continuously expose metrics
@param agentId the JMX agent ID
gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/MetricManager.java