当前位置: 首页>>代码示例>>Java>>正文


Java MetricsRecordBuilder类代码示例

本文整理汇总了Java中org.apache.hadoop.metrics2.MetricsRecordBuilder的典型用法代码示例。如果您正苦于以下问题:Java MetricsRecordBuilder类的具体用法?Java MetricsRecordBuilder怎么用?Java MetricsRecordBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MetricsRecordBuilder类属于org.apache.hadoop.metrics2包,在下文中一共展示了MetricsRecordBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getGcUsage

import org.apache.hadoop.metrics2.MetricsRecordBuilder; //导入依赖的package包/类
private void getGcUsage(MetricsRecordBuilder rb) {
  long count = 0;
  long timeMillis = 0;
  for (GarbageCollectorMXBean gcBean : gcBeans) {
    long c = gcBean.getCollectionCount();
    long t = gcBean.getCollectionTime();
    MetricsInfo[] gcInfo = getGcInfo(gcBean.getName());
    rb.addCounter(gcInfo[0], c).addCounter(gcInfo[1], t);
    count += c;
    timeMillis += t;
  }
  rb.addCounter(GcCount, count)
    .addCounter(GcTimeMillis, timeMillis);
  
  if (pauseMonitor != null) {
    rb.addCounter(GcNumWarnThresholdExceeded,
        pauseMonitor.getNumGcWarnThresholdExceeded());
    rb.addCounter(GcNumInfoThresholdExceeded,
        pauseMonitor.getNumGcInfoThresholdExceeded());
    rb.addCounter(GcTotalExtraSleepTime,
        pauseMonitor.getTotalGcExtraSleepTime());
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:24,代码来源:JvmMetrics.java

示例2: getThreadUsage

import org.apache.hadoop.metrics2.MetricsRecordBuilder; //导入依赖的package包/类
private void getThreadUsage(MetricsRecordBuilder rb) {
  int threadsNew = 0;
  int threadsRunnable = 0;
  int threadsBlocked = 0;
  int threadsWaiting = 0;
  int threadsTimedWaiting = 0;
  int threadsTerminated = 0;
  long threadIds[] = threadMXBean.getAllThreadIds();
  for (ThreadInfo threadInfo : threadMXBean.getThreadInfo(threadIds, 0)) {
    if (threadInfo == null) continue; // race protection
    switch (threadInfo.getThreadState()) {
      case NEW:           threadsNew++;           break;
      case RUNNABLE:      threadsRunnable++;      break;
      case BLOCKED:       threadsBlocked++;       break;
      case WAITING:       threadsWaiting++;       break;
      case TIMED_WAITING: threadsTimedWaiting++;  break;
      case TERMINATED:    threadsTerminated++;    break;
    }
  }
  rb.addGauge(ThreadsNew, threadsNew)
    .addGauge(ThreadsRunnable, threadsRunnable)
    .addGauge(ThreadsBlocked, threadsBlocked)
    .addGauge(ThreadsWaiting, threadsWaiting)
    .addGauge(ThreadsTimedWaiting, threadsTimedWaiting)
    .addGauge(ThreadsTerminated, threadsTerminated);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:27,代码来源:JvmMetrics.java

示例3: newTag

import org.apache.hadoop.metrics2.MetricsRecordBuilder; //导入依赖的package包/类
MutableMetric newTag(Class<?> resType) {
  if (resType == String.class) {
    return new MutableMetric() {
      @Override public void snapshot(MetricsRecordBuilder rb, boolean all) {
        try {
          Object ret = method.invoke(obj, (Object[]) null);
          rb.tag(info, (String) ret);
        }
        catch (Exception ex) {
          LOG.error("Error invoking method "+ method.getName(), ex);
        }
      }
    };
  }
  throw new MetricsException("Unsupported tag type: "+ resType.getName());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:MethodMetric.java

示例4: testProtoBufRpc2

import org.apache.hadoop.metrics2.MetricsRecordBuilder; //导入依赖的package包/类
@Test (timeout=5000)
public void testProtoBufRpc2() throws Exception {
  TestRpcService2 client = getClient2();
  
  // Test ping method
  EmptyRequestProto emptyRequest = EmptyRequestProto.newBuilder().build();
  client.ping2(null, emptyRequest);
  
  // Test echo method
  EchoRequestProto echoRequest = EchoRequestProto.newBuilder()
      .setMessage("hello").build();
  EchoResponseProto echoResponse = client.echo2(null, echoRequest);
  Assert.assertEquals(echoResponse.getMessage(), "hello");
  
  // Ensure RPC metrics are updated
  MetricsRecordBuilder rpcMetrics = getMetrics(server.getRpcMetrics().name());
  assertCounterGt("RpcQueueTimeNumOps", 0L, rpcMetrics);
  assertCounterGt("RpcProcessingTimeNumOps", 0L, rpcMetrics);
  
  MetricsRecordBuilder rpcDetailedMetrics = 
      getMetrics(server.getRpcDetailedMetrics().name());
  assertCounterGt("Echo2NumOps", 0L, rpcDetailedMetrics);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:TestProtoBufRpc.java

示例5: snapshot

import org.apache.hadoop.metrics2.MetricsRecordBuilder; //导入依赖的package包/类
@Override
public synchronized void snapshot(MetricsRecordBuilder builder, boolean all) {
  if (all || changed()) {
    builder.addGauge(numInfo, previousCount);
    for (int i = 0; i < quantiles.length; i++) {
      long newValue = 0;
      // If snapshot is null, we failed to update since the window was empty
      if (previousSnapshot != null) {
        newValue = previousSnapshot.get(quantiles[i]);
      }
      builder.addGauge(quantileInfos[i], newValue);
    }
    if (changed()) {
      clearChanged();
    }
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:18,代码来源:MutableQuantiles.java

示例6: snapshot

import org.apache.hadoop.metrics2.MetricsRecordBuilder; //导入依赖的package包/类
@Override
public synchronized void snapshot(MetricsRecordBuilder builder, boolean all) {
  if (all || changed()) {
    numSamples += intervalStat.numSamples();
    builder.addCounter(numInfo, numSamples)
           .addGauge(avgInfo, lastStat().mean());
    if (extended) {
      builder.addGauge(stdevInfo, lastStat().stddev())
             .addGauge(iMinInfo, lastStat().min())
             .addGauge(iMaxInfo, lastStat().max())
             .addGauge(minInfo, minMax.min())
             .addGauge(maxInfo, minMax.max())
             .addGauge(iNumInfo, lastStat().numSamples());
    }
    if (changed()) {
      if (numSamples > 0) {
        intervalStat.copyTo(prevStat);
        intervalStat.reset();
      }
      clearChanged();
    }
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:24,代码来源:MutableStat.java

示例7: newCounter

import org.apache.hadoop.metrics2.MetricsRecordBuilder; //导入依赖的package包/类
MutableMetric newCounter(final Class<?> type) {
  if (isInt(type) || isLong(type)) {
    return new MutableMetric() {
      @Override public void snapshot(MetricsRecordBuilder rb, boolean all) {
        try {
          Object ret = method.invoke(obj, (Object[])null);
          if (isInt(type)) rb.addCounter(info, ((Integer) ret).intValue());
          else rb.addCounter(info, ((Long) ret).longValue());
        } catch (Exception ex) {
          LOG.error("Error invoking method "+ method.getName(), ex);
        }
      }
    };
  }
  throw new MetricsException("Unsupported counter type: "+ type.getName());
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:17,代码来源:MethodMetric.java

示例8: newGauge

import org.apache.hadoop.metrics2.MetricsRecordBuilder; //导入依赖的package包/类
MutableMetric newGauge(final Class<?> t) {
  if (isInt(t) || isLong(t) || isFloat(t) || isDouble(t)) {
    return new MutableMetric() {
      @Override public void snapshot(MetricsRecordBuilder rb, boolean all) {
        try {
          Object ret = method.invoke(obj, (Object[]) null);
          if (isInt(t)) rb.addGauge(info, ((Integer) ret).intValue());
          else if (isLong(t)) rb.addGauge(info, ((Long) ret).longValue());
          else if (isFloat(t)) rb.addGauge(info, ((Float) ret).floatValue());
          else rb.addGauge(info, ((Double) ret).doubleValue());
        } catch (Exception ex) {
          LOG.error("Error invoking method "+ method.getName(), ex);
        }
      }
    };
  }
  throw new MetricsException("Unsupported gauge type: "+ t.getName());
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:19,代码来源:MethodMetric.java

示例9: testPresence

import org.apache.hadoop.metrics2.MetricsRecordBuilder; //导入依赖的package包/类
@Test
public void testPresence() {
  pauseMonitor = new JvmPauseMonitor();
  pauseMonitor.init(new Configuration());
  pauseMonitor.start();
  JvmMetrics jvmMetrics = new JvmMetrics("test", "test");
  jvmMetrics.setPauseMonitor(pauseMonitor);
  MetricsRecordBuilder rb = getMetrics(jvmMetrics);
  MetricsCollector mc = rb.parent();

  verify(mc).addRecord(JvmMetrics);
  verify(rb).tag(ProcessName, "test");
  verify(rb).tag(SessionId, "test");
  for (JvmMetricsInfo info : JvmMetricsInfo.values()) {
    if (info.name().startsWith("Mem"))
      verify(rb).addGauge(eq(info), anyFloat());
    else if (info.name().startsWith("Gc"))
      verify(rb).addCounter(eq(info), anyLong());
    else if (info.name().startsWith("Threads"))
      verify(rb).addGauge(eq(info), anyInt());
    else if (info.name().startsWith("Log"))
      verify(rb).addCounter(eq(info), anyLong());
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:25,代码来源:TestJvmMetrics.java

示例10: testHybrid

import org.apache.hadoop.metrics2.MetricsRecordBuilder; //导入依赖的package包/类
@Test public void testHybrid() {
  HybridMetrics metrics = new HybridMetrics();
  MetricsSource source = MetricsAnnotations.makeSource(metrics);

  assertSame(metrics, source);
  metrics.C0.incr();
  MetricsRecordBuilder rb = getMetrics(source);
  MetricsCollector collector = rb.parent();

  verify(collector).addRecord("foo");
  verify(collector).addRecord("bar");
  verify(collector).addRecord(info("HybridMetrics", "HybridMetrics"));
  verify(rb).setContext("foocontext");
  verify(rb).addCounter(info("C1", "C1 desc"), 1);
  verify(rb).setContext("barcontext");
  verify(rb).addGauge(info("G1", "G1 desc"), 1);
  verify(rb).add(tag(MsInfo.Context, "hybrid"));
  verify(rb).addCounter(info("C0", "C0 desc"), 1);
  verify(rb).addGauge(info("G0", "G0"), 0);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:21,代码来源:TestMetricsAnnotations.java

示例11: testMutableQuantilesEmptyRollover

import org.apache.hadoop.metrics2.MetricsRecordBuilder; //导入依赖的package包/类
/**
 * Test that {@link MutableQuantiles} rolls over correctly even if no items
 * have been added to the window
 */
@Test(timeout = 30000)
public void testMutableQuantilesEmptyRollover() throws Exception {
  MetricsRecordBuilder mb = mockMetricsRecordBuilder();
  MetricsRegistry registry = new MetricsRegistry("test");
  // Use a 5s rollover period
  MutableQuantiles quantiles = registry.newQuantiles("foo", "stat", "Ops",
      "Latency", 5);

  // Check it initially
  quantiles.snapshot(mb, true);
  verify(mb).addGauge(
      info("FooNumOps", "Number of ops for stat with 5s interval"), (long) 0);
  Thread.sleep(6000);
  quantiles.snapshot(mb, false);
  verify(mb, times(2)).addGauge(
      info("FooNumOps", "Number of ops for stat with 5s interval"), (long) 0);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:22,代码来源:TestMutableMetrics.java

示例12: mockMetricsRecordBuilder

import org.apache.hadoop.metrics2.MetricsRecordBuilder; //导入依赖的package包/类
public static MetricsRecordBuilder mockMetricsRecordBuilder() {
  final MetricsCollector mc = mock(MetricsCollector.class);
  MetricsRecordBuilder rb = mock(MetricsRecordBuilder.class,
      new Answer<Object>() {
    @Override
    public Object answer(InvocationOnMock invocation) {
      Object[] args = invocation.getArguments();
      StringBuilder sb = new StringBuilder();
      for (Object o : args) {
        if (sb.length() > 0) sb.append(", ");
        sb.append(String.valueOf(o));
      }
      String methodName = invocation.getMethod().getName();
      LOG.debug(methodName +": "+ sb);
      return methodName.equals("parent") || methodName.equals("endRecord") ?
             mc : invocation.getMock();
    }
  });
  when(mc.addRecord(anyString())).thenReturn(rb);
  when(mc.addRecord(anyInfo())).thenReturn(rb);
  return rb;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:23,代码来源:MetricsAsserts.java

示例13: getMetrics

import org.apache.hadoop.metrics2.MetricsRecordBuilder; //导入依赖的package包/类
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
  MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName);

  if (wrapper != null) {
    mrb.addGauge(Interns.info(QUEUE_SIZE_NAME, QUEUE_SIZE_DESC), wrapper.getTotalQueueSize())
        .addGauge(Interns.info(GENERAL_QUEUE_NAME, GENERAL_QUEUE_DESC),
            wrapper.getGeneralQueueLength())
        .addGauge(Interns.info(REPLICATION_QUEUE_NAME,
            REPLICATION_QUEUE_DESC), wrapper.getReplicationQueueLength())
        .addGauge(Interns.info(PRIORITY_QUEUE_NAME, PRIORITY_QUEUE_DESC),
            wrapper.getPriorityQueueLength())
        .addGauge(Interns.info(NUM_OPEN_CONNECTIONS_NAME,
            NUM_OPEN_CONNECTIONS_DESC), wrapper.getNumOpenConnections())
        .addGauge(Interns.info(NUM_ACTIVE_HANDLER_NAME,
            NUM_ACTIVE_HANDLER_DESC), wrapper.getActiveRpcHandlerCount());
  }

  metricsRegistry.snapshot(mrb, all);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:21,代码来源:MetricsHBaseServerSourceImpl.java

示例14: snapshot

import org.apache.hadoop.metrics2.MetricsRecordBuilder; //导入依赖的package包/类
public synchronized void snapshot(MetricsRecordBuilder builder, boolean all) {
  if (all || changed()) {
    numSamples += intervalStat.numSamples();
    builder.addCounter(numInfo, numSamples)
           .addGauge(avgInfo, lastStat().mean());
    if (extended) {
      builder.addGauge(stdevInfo, lastStat().stddev())
             .addGauge(iMinInfo, lastStat().min())
             .addGauge(iMaxInfo, lastStat().max())
             .addGauge(minInfo, minMax.min())
             .addGauge(maxInfo, minMax.max());
    }
    if (changed()) {
      if (numSamples > 0) {
        intervalStat.copyTo(prevStat);
        intervalStat.reset();
      }
      clearChanged();
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:MutableStat.java

示例15: checkMetrics

import org.apache.hadoop.metrics2.MetricsRecordBuilder; //导入依赖的package包/类
private void checkMetrics(int launched, int completed, int failed, int killed,
    int initing, int running, int allocatedGB,
    int allocatedContainers, int availableGB, int allocatedVCores,
    int availableVCores, int allocatedGCores, int availableGCores) {
  MetricsRecordBuilder rb = getMetrics("NodeManagerMetrics");
  assertCounter("ContainersLaunched", launched, rb);
  assertCounter("ContainersCompleted", completed, rb);
  assertCounter("ContainersFailed", failed, rb);
  assertCounter("ContainersKilled", killed, rb);
  assertGauge("ContainersIniting", initing, rb);
  assertGauge("ContainersRunning", running, rb);
  assertGauge("AllocatedGB", allocatedGB, rb);
  assertGauge("AllocatedVCores", allocatedVCores, rb);
  assertGauge("AllocatedGCores", allocatedGCores, rb);
  assertGauge("AllocatedContainers", allocatedContainers, rb);
  assertGauge("AvailableGB", availableGB, rb);
  assertGauge("AvailableVCores",availableVCores, rb);
  assertGauge("AvailableGCores", availableGCores, rb);

}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:TestNodeManagerMetrics.java


注:本文中的org.apache.hadoop.metrics2.MetricsRecordBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。