|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.celeborn.common.metrics.sink |
| 19 | + |
| 20 | +import java.util.Properties |
| 21 | + |
| 22 | +import com.codahale.metrics.MetricRegistry |
| 23 | +import com.codahale.metrics.jmx.JmxReporter |
| 24 | + |
| 25 | +class JmxSink(val property: Properties, val registry: MetricRegistry) extends Sink { |
| 26 | + |
| 27 | + // Publish MBeans under a configurable, Celeborn-specific JMX domain (defaulting to |
| 28 | + // `celeborn`) rather than JmxReporter's global default domain `metrics`. This avoids |
| 29 | + // MBean name collisions when other components using Dropwizard metrics run in the |
| 30 | + // same JVM. The domain can be overridden via `*.sink.jmx.domain=<domain>`. |
| 31 | + val domain: String = |
| 32 | + Option(property.getProperty(JmxSink.JMX_DOMAIN_KEY)) |
| 33 | + .map(_.trim) |
| 34 | + .filter(_.nonEmpty) |
| 35 | + .getOrElse(JmxSink.JMX_DEFAULT_DOMAIN) |
| 36 | + |
| 37 | + val reporter: JmxReporter = JmxReporter.forRegistry(registry) |
| 38 | + .inDomain(domain) |
| 39 | + .build() |
| 40 | + |
| 41 | + override def start(): Unit = { |
| 42 | + reporter.start() |
| 43 | + } |
| 44 | + |
| 45 | + override def stop(): Unit = { |
| 46 | + reporter.stop() |
| 47 | + } |
| 48 | + |
| 49 | + override def report(): Unit = {} |
| 50 | +} |
| 51 | + |
| 52 | +object JmxSink { |
| 53 | + val JMX_DOMAIN_KEY = "domain" |
| 54 | + val JMX_DEFAULT_DOMAIN = "celeborn" |
| 55 | +} |
0 commit comments