Exemple #1
0
 /**
  * Removes all the metrics for the named data source
  *
  * @param name the sub registry name
  * @param metricNames The metrics to remove
  */
 public void closeDataSource(final String name, final Collection<String> metricNames) {
   if (name == null || name.trim().isEmpty())
     throw new IllegalArgumentException("Metric registry name was null");
   final String mname = name.trim();
   MetricRegistry m = subRegistries.get(mname);
   if (m != null) {
     for (String s : metricNames) {
       m.remove(s);
     }
   }
 }
 /** {@inheritDoc} */
 @Override
 public void close() {
   registry.remove(MetricRegistry.name(poolName, "pool", "Wait"));
   registry.remove(MetricRegistry.name(poolName, "pool", "Usage"));
   registry.remove(MetricRegistry.name(poolName, "pool", "TotalConnections"));
   registry.remove(MetricRegistry.name(poolName, "pool", "IdleConnections"));
   registry.remove(MetricRegistry.name(poolName, "pool", "ActiveConnections"));
   registry.remove(MetricRegistry.name(poolName, "pool", "PendingConnections"));
 }
Exemple #3
0
  /**
   * Closes the named registry
   *
   * @param name the registry name to close
   */
  public void closeRegistry(final String name) {
    if (name == null || name.trim().isEmpty())
      throw new IllegalArgumentException("Metric registry name was null");
    final String mname = name.trim();
    MetricRegistry m = subRegistries.remove(mname);
    if (m != null) {
      for (String metricName : m.getNames()) {
        m.remove(metricName);
      }
    }
    JmxReporter reporter = subReporters.remove(mname);
    if (reporter != null) {

      try {
        reporter.close();
      } catch (Exception x) {
        /* No Op */
      }
    }
  }
  @Test
  @InSequence(4)
  public void removeCounterFromRegistry() {
    assertThat("Counter is not registered correctly", registry.getCounters(), hasKey(COUNTER_NAME));
    Counter counter = registry.getCounters().get(COUNTER_NAME);

    // Remove the counter from metrics registry
    registry.remove(COUNTER_NAME);

    try {
      // Call the counted method and assert an exception is thrown
      bean.countedMethod(
          new Callable<Long>() {
            @Override
            public Long call() throws Exception {
              return null;
            }
          });
    } catch (Exception cause) {
      assertThat(cause, is(instanceOf(IllegalStateException.class)));
      assertThat(
          cause.getMessage(),
          is(
              equalTo(
                  "No counter with name ["
                      + COUNTER_NAME
                      + "] found in registry ["
                      + registry
                      + "]")));
      // Make sure that the counter hasn't been called
      assertThat(
          "Counter count is incorrect", counter.getCount(), is(equalTo(COUNTER_COUNT.get())));
      return;
    }

    fail("No exception has been re-thrown!");
  }
 /**
  * Removes a Source.
  *
  * @param source the source to remove
  */
 public void removeSource(Source source) {
   mSources.remove(source);
   mMetricRegistry.remove(source.getName());
 }
Exemple #6
0
 public static boolean remove(String name) {
   return metrics.remove(name);
 }