Merge "Custom mailbox that is bounded and instrumented."
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / common / reporting / MetricsReporter.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.common.reporting;
9
10 import com.codahale.metrics.JmxReporter;
11 import com.codahale.metrics.MetricRegistry;
12
13 /**
14  * Maintains metrics registry that is provided to reporters.
15  * At the moment only one reporter exists {@code JmxReporter}.
16  * More reporters can be added.
17  * <p/>
18  * The consumers of this class will only be interested in {@code MetricsRegistry}
19  * where metrics for that consumer gets stored.
20  */
21 public class MetricsReporter implements AutoCloseable{
22
23     private final MetricRegistry METRICS_REGISTRY = new MetricRegistry();
24     private final String DOMAIN = "org.opendaylight.controller";
25
26     public final JmxReporter jmxReporter = JmxReporter.forRegistry(METRICS_REGISTRY).inDomain(DOMAIN).build();
27
28     private static MetricsReporter inst = new MetricsReporter();
29
30     private MetricsReporter(){
31         jmxReporter.start();
32     }
33
34     public static MetricsReporter getInstance(){
35         return inst;
36     }
37
38     public MetricRegistry getMetricsRegistry(){
39         return METRICS_REGISTRY;
40     }
41
42     @Override
43     public void close() throws Exception {
44         jmxReporter.close();
45     }
46 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.