Added performance-related metrics for the Topology and Intents:

===

 * "Topology.EventNotification.LastEventTimestamp"
   Timestamp of the last Topology event (system nanoseconds)

 * "Topology.EventNotification.ListenerEventRate"
   Rate of the Topology events published to the Topology listeners

===

 * "Intents.AddOperation.BeginOperationTimestamp"
   Timestamp of the incoming Add Intent API operation (system nanoseconds)

 * "Intents.AddOperation.EndOperationTimestamp"
   Timestamp of the Add Intent operation completion (system nanoseconds)

 * "Intents.AddOperation.IncomingRate"
   Rate of the incoming Add Intent API operations

 * "Intents.AddOperation.ProcessingRate"
   Rate of processing the Add Intent operations

===

 * "Intents.RemoveOperation.BeginOperationTimestamp"
   Timestamp of the incoming Remove Intent API operation (system nanoseconds)

 * "Intents.RemoveOperation.EndOperationTimestamp"
   Timestamp of the Remove Intent operation completion (system nanoseconds)

 * "Intents.RemoveOperation.IncomingRate"
   Rate of the incoming Remove Intent API operations

 * "Intents.RemoveOperation.ProcessingRate"
   Rate of processing the Remove Intent operations

===

All performance metrics are exposed via the Metrics REST API:

 * GET all metrics:
url = "http://%s:%s/wm/onos/metrics" % (self.onos_ip, self.onos_port)

 * GET a specific metric:
url = "http://%s:%s/wm/onos/metrics?ids=%s" % (self.onos_ip, self.onos_port, args.metric_id)

   where "metric_id" is the name of the Metric. E.g.:
   ids=Topology.EventNotification.LastEventTimestamp

 * GET multiple metrics:
url = "http://%s:%s/wm/onos/metrics?ids=%s" % (self.onos_ip, self.onos_port, args.metric_id)

   where "metric_id" is comma-separated list of Metric names. E.g:
   ids=Topology.EventNotification.LastEventTimestamp,Topology.EventNotification.ListenerEventRate

===

The JSON format of the output is the following:

{
    "meters": [
        {
            "name": "Intents.AddOperation.IncomingRate",
            "meter": {
                "count": 2,
                "mean_rate": 0.007488255279864508,
                "m5_rate": 0.006082798637345469,
                "m15_rate": 0.021083988195124116,
                "units": "events/second",
                "m1_rate": 0.002155350653737004
            }
        },
        ...
    ],
    "histograms": [],
    "timers": [],
    "gauges": [
        {
            "gauge": {
                "value": 179956769775795
            },
            "name": "Intents.AddOperation.BeginOperationTimestamp"
        },
        ...
    ],
    "counters": []
}

where
  - "meter.count" is the number of events
  - "meter.mean_rate" is the mean rate of the events
  - "meter.m5_rate" is the rate of the events over the last 5-minute interval
  - "meter.m15_rate" is the rate of the events over the last 15-minute interval
  - "meter.m1_rate" is the rate of the events over the last 1-minute interval
  - "meter.units" is the units of the rate (should be "events/second")

  - "gauge.value" is the value of the particular metric.
     In case of the "*Timestamp" metrics, it is the system nanoseconds
     timestamp for the particular event or operation.

Also, fixed some of the unit tests.
NOTE: Currently, for some of the tests we have to explicitly
remove all metrics when tearing-down a test.
In the future we should have a single base unit test class,
and only its tearDown() method should do such cleanup.

Change-Id: Iad5b47b908a29dcfd9fb08e7a010ddf2627fd808
diff --git a/src/test/java/net/onrc/onos/core/intent/runtime/UseCaseTest.java b/src/test/java/net/onrc/onos/core/intent/runtime/UseCaseTest.java
index b7de7b0..b56b3e1 100644
--- a/src/test/java/net/onrc/onos/core/intent/runtime/UseCaseTest.java
+++ b/src/test/java/net/onrc/onos/core/intent/runtime/UseCaseTest.java
@@ -28,6 +28,7 @@
 import net.onrc.onos.core.intent.PathIntentMap;
 import net.onrc.onos.core.intent.ShortestPathIntent;
 import net.onrc.onos.core.intent.runtime.web.IntentWebRoutable;
+import net.onrc.onos.core.metrics.OnosMetrics;
 import net.onrc.onos.core.registry.IControllerRegistryService;
 import net.onrc.onos.core.topology.HostEvent;
 import net.onrc.onos.core.topology.ITopologyListener;
@@ -40,6 +41,7 @@
 import net.onrc.onos.core.topology.TopologyEvents;
 import net.onrc.onos.core.util.SwitchPort;
 
+import com.codahale.metrics.MetricFilter;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -130,6 +132,7 @@
         verify(controllerRegistryService);
         PowerMock.verify(persistIntent, PersistIntent.class);
         verify(restApi);
+        OnosMetrics.removeMatching(MetricFilter.ALL);
     }
 
     private void showResult(PathIntentMap intents) {