Search in sources :

Example 6 with MetricName

use of com.yammer.metrics.core.MetricName in project Dempsy by Dempsy.

the class TestStatsCollectorCoda method testEnvPrefixFromSystemProperty.

@Test
public void testEnvPrefixFromSystemProperty() throws Throwable {
    tearDown();
    System.setProperty(StatsCollectorFactoryCoda.environmentPrefixSystemPropertyName, "Hello.");
    setUp();
    StatsCollectorFactoryCoda.MetricNamingStrategy strategy = statsCollectorFactory.getNamingStrategy();
    ClusterId clusterId = new ClusterId("app", "cluster");
    MetricName name = strategy.createName(clusterId, "metric");
    assertEquals("metric", name.getName());
    assertEquals("app-cluster", name.getGroup());
    assertTrue(strategy.buildPrefix(clusterId, new Destination() {

        @Override
        public String toString() {
            return "destination";
        }
    }).startsWith("Hello."));
    // make sure setting the environment prefix doesn't effect the -D option
    statsCollectorFactory.setEnvironmentPrefix("otherEnvPrefix");
    assertTrue(strategy.buildPrefix(clusterId, new Destination() {

        @Override
        public String toString() {
            return "destination";
        }
    }).startsWith("Hello."));
    // make sure that without the system property the setEnvironmentPrefix value works
    System.getProperties().remove(StatsCollectorFactoryCoda.environmentPrefixSystemPropertyName);
    assertTrue(strategy.buildPrefix(clusterId, new Destination() {

        @Override
        public String toString() {
            return "destination";
        }
    }).startsWith("otherEnvPrefix"));
    // make sure that delting the environmentPrefix doesn't create an issue.
    statsCollectorFactory.setEnvironmentPrefix(null);
    strategy.buildPrefix(clusterId, new Destination() {

        @Override
        public String toString() {
            return "destination";
        }
    }).startsWith("otherEnvPrefix");
}
Also used : MetricName(com.yammer.metrics.core.MetricName) Destination(com.nokia.dempsy.messagetransport.Destination) ClusterId(com.nokia.dempsy.config.ClusterId) Test(org.junit.Test)

Example 7 with MetricName

use of com.yammer.metrics.core.MetricName in project pinot by linkedin.

the class MetricsHelperTest method testMetricsHelperRegistration.

@Test
public void testMetricsHelperRegistration() {
    listenerOneOkay = false;
    listenerTwoOkay = false;
    Map<String, String> configKeys = new HashMap<String, String>();
    configKeys.put("pinot.broker.metrics.metricsRegistryRegistrationListeners", ListenerOne.class.getName() + "," + ListenerTwo.class.getName());
    Configuration configuration = new MapConfiguration(configKeys);
    MetricsRegistry registry = new MetricsRegistry();
    // Initialize the MetricsHelper and create a new timer
    MetricsHelper.initializeMetrics(configuration.subset("pinot.broker.metrics"));
    MetricsHelper.registerMetricsRegistry(registry);
    MetricsHelper.newTimer(registry, new MetricName(MetricsHelperTest.class, "dummy"), TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS);
    // Check that the two listeners fired
    assertTrue(listenerOneOkay);
    assertTrue(listenerTwoOkay);
}
Also used : MetricName(com.yammer.metrics.core.MetricName) MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) Configuration(org.apache.commons.configuration.Configuration) MapConfiguration(org.apache.commons.configuration.MapConfiguration) HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) Test(org.testng.annotations.Test)

Example 8 with MetricName

use of com.yammer.metrics.core.MetricName in project pinot by linkedin.

the class AbstractMetrics method addMeteredGlobalValue.

/**
   * Logs a value to a meter.
   *
   * @param meter The meter to use
   * @param unitCount The number of units to add to the meter
   */
public void addMeteredGlobalValue(final M meter, final long unitCount) {
    final String fullMeterName;
    String meterName = meter.getMeterName();
    fullMeterName = _metricPrefix + meterName;
    final MetricName metricName = new MetricName(_clazz, fullMeterName);
    MetricsHelper.newMeter(_metricsRegistry, metricName, meter.getUnit(), TimeUnit.SECONDS).mark(unitCount);
}
Also used : MetricName(com.yammer.metrics.core.MetricName)

Example 9 with MetricName

use of com.yammer.metrics.core.MetricName in project pinot by linkedin.

the class AbstractMetrics method addMeteredQueryValue.

/**
   * Logs a value to a meter for a specific query.
   *
   * @param request The broker request associated with this query
   * @param meter The meter to use
   * @param unitCount The number of units to add to the meter
   */
public void addMeteredQueryValue(final BrokerRequest request, final M meter, final long unitCount) {
    final String fullMeterName;
    String meterName = meter.getMeterName();
    if (request != null) {
        fullMeterName = buildMetricName(request, meterName);
    } else {
        fullMeterName = _metricPrefix + meterName;
    }
    final MetricName metricName = new MetricName(_clazz, fullMeterName);
    MetricsHelper.newMeter(_metricsRegistry, metricName, meter.getUnit(), TimeUnit.SECONDS).mark(unitCount);
}
Also used : MetricName(com.yammer.metrics.core.MetricName)

Example 10 with MetricName

use of com.yammer.metrics.core.MetricName in project pinot by linkedin.

the class AbstractMetrics method addValueToTimer.

/**
   * Logs the timing for a metric
   *
   * @param fullTimerName The full name of timer
   * @param duration The log time duration time value
   * @param timeUnit The log time duration time unit
   */
private void addValueToTimer(String fullTimerName, final long duration, final TimeUnit timeUnit) {
    final MetricName metricName = new MetricName(_clazz, fullTimerName);
    MetricsHelper.newTimer(_metricsRegistry, metricName, TimeUnit.MILLISECONDS, TimeUnit.SECONDS).update(duration, timeUnit);
}
Also used : MetricName(com.yammer.metrics.core.MetricName)

Aggregations

MetricName (com.yammer.metrics.core.MetricName)12 ClusterId (com.nokia.dempsy.config.ClusterId)1 Destination (com.nokia.dempsy.messagetransport.Destination)1 Counter (com.yammer.metrics.core.Counter)1 Meter (com.yammer.metrics.core.Meter)1 Metric (com.yammer.metrics.core.Metric)1 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)1 DateFormat (java.text.DateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 SortedMap (java.util.SortedMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Configuration (org.apache.commons.configuration.Configuration)1 MapConfiguration (org.apache.commons.configuration.MapConfiguration)1 Test (org.junit.Test)1 Test (org.testng.annotations.Test)1