org.apache.hadoop.metrics2.lib.MutableGaugeLong Java Examples

The following examples show how to use org.apache.hadoop.metrics2.lib.MutableGaugeLong. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExecutorStatusChore.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
protected void chore() {
  try{
    // thread pool monitor
    Map<String, ExecutorStatus> statuses = service.getAllExecutorStatuses();
    for (Map.Entry<String, ExecutorStatus> statusEntry : statuses.entrySet()) {
      String name = statusEntry.getKey();
      // Executor's name is generate by ExecutorType#getExecutorName
      // include ExecutorType & Servername(split by '-'), here we only need the ExecutorType
      String poolName = name.split("-")[0];
      ExecutorStatus status = statusEntry.getValue();
      MutableGaugeLong queued = metricsRegistry.getGauge(poolName + "_queued", 0L);
      MutableGaugeLong running = metricsRegistry.getGauge(poolName + "_running", 0L);
      int queueSize = status.getQueuedEvents().size();
      int runningSize = status.getRunning().size();
      if (queueSize > 0) {
        LOG.warn("{}'s size info, queued: {}, running: {}", poolName, queueSize, runningSize);
      }
      queued.set(queueSize);
      running.set(runningSize);
    }
  } catch(Throwable e) {
    LOG.error(e.getMessage(), e);
  }
}
 
Example #2
Source File: TestBaseSourceImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetGauge() throws Exception {
  bmsi.setGauge("testset", 100);
  assertEquals(100, ((MutableGaugeLong) bmsi.metricsRegistry.get("testset")).value());
  bmsi.setGauge("testset", 300);
  assertEquals(300, ((MutableGaugeLong) bmsi.metricsRegistry.get("testset")).value());

}
 
Example #3
Source File: TestBaseSourceImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testIncGauge() throws Exception {
  bmsi.incGauge("testincgauge", 100);
  assertEquals(100, ((MutableGaugeLong) bmsi.metricsRegistry.get("testincgauge")).value());
  bmsi.incGauge("testincgauge", 100);
  assertEquals(200, ((MutableGaugeLong) bmsi.metricsRegistry.get("testincgauge")).value());

}
 
Example #4
Source File: TestBaseSourceImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecGauge() throws Exception {
  bmsi.decGauge("testdec", 100);
  assertEquals(-100, ((MutableGaugeLong) bmsi.metricsRegistry.get("testdec")).value());
  bmsi.decGauge("testdec", 100);
  assertEquals(-200, ((MutableGaugeLong) bmsi.metricsRegistry.get("testdec")).value());

}
 
Example #5
Source File: ExecutorStatusChore.java    From hbase with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public Pair<Long, Long> getExecutorStatus(String poolName) {
  MutableGaugeLong running = metricsRegistry.getGauge(poolName + "_running", 0L);
  MutableGaugeLong queued = metricsRegistry.getGauge(poolName + "_queued", 0L);
  return new Pair<Long, Long>(running.value(), queued.value());
}
 
Example #6
Source File: MetricsZooKeeperSourceImpl.java    From hbase with Apache License 2.0 4 votes vote down vote up
private static void clearMetricIfNotNull(MutableGaugeLong metric) {
  if (metric != null) {
    metric.set(0L);
  }
}
 
Example #7
Source File: BaseSourceImpl.java    From hbase with Apache License 2.0 2 votes vote down vote up
/**
 * Set a single gauge to a value.
 *
 * @param gaugeName gauge name
 * @param value     the new value of the gauge.
 */
public void setGauge(String gaugeName, long value) {
  MutableGaugeLong gaugeInt = metricsRegistry.getGauge(gaugeName, value);
  gaugeInt.set(value);
}
 
Example #8
Source File: BaseSourceImpl.java    From hbase with Apache License 2.0 2 votes vote down vote up
/**
 * Add some amount to a gauge.
 *
 * @param gaugeName The name of the gauge to increment.
 * @param delta     The amount to increment the gauge by.
 */
public void incGauge(String gaugeName, long delta) {
  MutableGaugeLong gaugeInt = metricsRegistry.getGauge(gaugeName, 0L);
  gaugeInt.incr(delta);
}
 
Example #9
Source File: BaseSourceImpl.java    From hbase with Apache License 2.0 2 votes vote down vote up
/**
 * Decrease the value of a named gauge.
 *
 * @param gaugeName The name of the gauge.
 * @param delta     the ammount to subtract from a gauge value.
 */
public void decGauge(String gaugeName, long delta) {
  MutableGaugeLong gaugeInt = metricsRegistry.getGauge(gaugeName, 0L);
  gaugeInt.decr(delta);
}