Merge "BUG-2288: deprecate old binding Notification API elements"
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / common / actor / MeteringBehavior.java
index d67d413d0963fff464503391002a3e6d3af15bee..c04e2e93402ad12915828812d4365016fabbda51 100644 (file)
@@ -26,25 +26,42 @@ import org.opendaylight.controller.cluster.reporting.MetricsReporter;
  * The information is reported to {@link org.opendaylight.controller.cluster.reporting.MetricsReporter}
  */
 public class MeteringBehavior implements Procedure<Object> {
+    public static final String DOMAIN = "org.opendaylight.controller.actor.metric";
 
     private final UntypedActor meteredActor;
 
-    private final MetricRegistry METRICREGISTRY = MetricsReporter.getInstance().getMetricsRegistry();
+    private final MetricRegistry METRICREGISTRY = MetricsReporter.getInstance(DOMAIN).getMetricsRegistry();
     private final String MSG_PROCESSING_RATE = "msg-rate";
 
-    private String actorName;
+    private String actorQualifiedName;
     private Timer msgProcessingTimer;
 
     /**
      *
      * @param actor whose behaviour needs to be metered
      */
-    public MeteringBehavior(UntypedActor actor){
+    public MeteringBehavior(AbstractUntypedActorWithMetering actor){
         Preconditions.checkArgument(actor != null, "actor must not be null");
+        this.meteredActor = actor;
 
+        String actorName = actor.getActorNameOverride() != null ? actor.getActorNameOverride()
+                                                                : actor.getSelf().path().name();
+        init(actorName);
+    }
+
+    public MeteringBehavior(UntypedActor actor){
+        Preconditions.checkArgument(actor != null, "actor must not be null");
         this.meteredActor = actor;
-        actorName = meteredActor.getSelf().path().toStringWithoutAddress();
-        final String msgProcessingTime = MetricRegistry.name(actorName, MSG_PROCESSING_RATE);
+
+        String actorName = actor.getSelf().path().name();
+        init(actorName);
+    }
+
+    private void init(String actorName){
+        actorQualifiedName = new StringBuilder(meteredActor.getSelf().path().parent().toStringWithoutAddress()).
+                append("/").append(actorName).toString();
+
+        final String msgProcessingTime = MetricRegistry.name(actorQualifiedName, MSG_PROCESSING_RATE);
         msgProcessingTimer = METRICREGISTRY.timer(msgProcessingTime);
     }
 
@@ -69,7 +86,7 @@ public class MeteringBehavior implements Procedure<Object> {
         final String messageType = message.getClass().getSimpleName();
 
         final String msgProcessingTimeByMsgType =
-                MetricRegistry.name(actorName, MSG_PROCESSING_RATE, messageType);
+                MetricRegistry.name(actorQualifiedName, MSG_PROCESSING_RATE, messageType);
 
         final Timer msgProcessingTimerByMsgType = METRICREGISTRY.timer(msgProcessingTimeByMsgType);