001/* 002 * (C) Copyright 2020 Nuxeo (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bdelbosc 018 */ 019package org.nuxeo.runtime.metrics.reporter; 020 021import java.util.Set; 022import java.util.concurrent.TimeUnit; 023 024import org.apache.logging.log4j.LogManager; 025import org.apache.logging.log4j.Logger; 026import org.nuxeo.runtime.metrics.AbstractMetricsReporter; 027 028import io.dropwizard.metrics5.MetricAttribute; 029import io.dropwizard.metrics5.MetricFilter; 030import io.dropwizard.metrics5.MetricRegistry; 031 032/** 033 * Reports metrics to JMX. 034 * 035 * @since 11.1 036 */ 037public class JmxReporter extends AbstractMetricsReporter { 038 039 private static final Logger log = LogManager.getLogger(JmxReporter.class); 040 041 private io.dropwizard.metrics5.jmx.JmxReporter reporter; 042 043 @Override 044 public void start(MetricRegistry registry, MetricFilter filter, Set<MetricAttribute> deniedExpansions) { 045 log.warn("Creating Jmx reporter"); 046 reporter = io.dropwizard.metrics5.jmx.JmxReporter.forRegistry(registry) 047 .convertRatesTo(TimeUnit.SECONDS) 048 .convertDurationsTo(TimeUnit.MICROSECONDS) 049 .filter(filter) 050 .build(); 051 reporter.start(); 052 } 053 054 @Override 055 public void stop() { 056 log.debug("Stop reporting"); 057 reporter.stop(); 058 reporter = null; 059 } 060 061}