BUG-1704: do not emit separator
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / 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.cluster.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.actor.metric";
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 }