org.apache.hadoop.metrics2.annotation.Metric Java Examples

The following examples show how to use org.apache.hadoop.metrics2.annotation.Metric. 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: NameNodeMetrics.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Metric("Number of file system operations")
public long totalFileOps(){
  return
    getBlockLocations.value() +
    createFileOps.value() +
    filesAppended.value() +
    addBlockOps.value() +
    getAdditionalDatanodeOps.value() +
    filesRenamed.value() +
    filesTruncated.value() +
    deleteFileOps.value() +
    getListingOps.value() +
    fileInfoOps.value() +
    getLinkTargetOps.value() +
    createSnapshotOps.value() +
    deleteSnapshotOps.value() +
    allowSnapshotOps.value() +
    disallowSnapshotOps.value() +
    renameSnapshotOps.value() +
    listSnapshottableDirOps.value() +
    createSymlinkOps.value() +
    snapshotDiffReportOps.value();
}
 
Example #2
Source File: MethodMetric.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private MutableMetric newImpl(Metric.Type metricType) {
  Class<?> resType = method.getReturnType();
  switch (metricType) {
    case COUNTER:
      return newCounter(resType);
    case GAUGE:
      return newGauge(resType);
    case DEFAULT:
      return resType == String.class ? newTag(resType) : newGauge(resType);
    case TAG:
      return newTag(resType);
    default:
      checkArg(metricType, false, "unsupported metric type");
      return null;
  }
}
 
Example #3
Source File: MethodMetric.java    From big-c with Apache License 2.0 6 votes vote down vote up
private MutableMetric newImpl(Metric.Type metricType) {
  Class<?> resType = method.getReturnType();
  switch (metricType) {
    case COUNTER:
      return newCounter(resType);
    case GAUGE:
      return newGauge(resType);
    case DEFAULT:
      return resType == String.class ? newTag(resType) : newGauge(resType);
    case TAG:
      return newTag(resType);
    default:
      checkArg(metricType, false, "unsupported metric type");
      return null;
  }
}
 
Example #4
Source File: NameNodeMetrics.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Metric("Number of file system operations")
public long totalFileOps(){
  return
    getBlockLocations.value() +
    createFileOps.value() +
    filesAppended.value() +
    addBlockOps.value() +
    getAdditionalDatanodeOps.value() +
    filesRenamed.value() +
    filesTruncated.value() +
    deleteFileOps.value() +
    getListingOps.value() +
    fileInfoOps.value() +
    getLinkTargetOps.value() +
    createSnapshotOps.value() +
    deleteSnapshotOps.value() +
    allowSnapshotOps.value() +
    disallowSnapshotOps.value() +
    renameSnapshotOps.value() +
    listSnapshottableDirOps.value() +
    createSymlinkOps.value() +
    snapshotDiffReportOps.value();
}
 
Example #5
Source File: MutableMetricsFactory.java    From big-c with Apache License 2.0 5 votes vote down vote up
protected MetricsInfo getInfo(Metric annotation, String defaultName) {
  String[] value = annotation.value();
   if (value.length == 2) {
    return Interns.info(value[0], value[1]);
  }
  if (value.length == 1) {
    return Interns.info(defaultName, value[0]);
  }
  return Interns.info(defaultName, defaultName);
}
 
Example #6
Source File: JournalMetrics.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Metric("Last accepted epoch")
public long getLastPromisedEpoch() {
  try {
    return journal.getLastPromisedEpoch();
  } catch (IOException e) {
    return -1L;
  }
}
 
Example #7
Source File: JournalMetrics.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Metric("Number of transactions that this JN is lagging")
public long getCurrentLagTxns() {
  try {
    return journal.getCurrentLagTxns();
  } catch (IOException e) {
    return -1L;
  }
}
 
Example #8
Source File: MetricsSourceBuilder.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void add(Object source, Method method) {
  for (Annotation annotation : method.getAnnotations()) {
    if (!(annotation instanceof Metric)) continue;
    factory.newForMethod(source, method, (Metric) annotation, registry);
    hasAtMetric = true;
  }
}
 
Example #9
Source File: MutableMetricsFactory.java    From big-c with Apache License 2.0 5 votes vote down vote up
MutableMetric newForField(Field field, Metric annotation,
                          MetricsRegistry registry) {
  if (LOG.isDebugEnabled()) {
    LOG.debug("field "+ field +" with annotation "+ annotation);
  }
  MetricsInfo info = getInfo(annotation, field);
  MutableMetric metric = newForField(field, annotation);
  if (metric != null) {
    registry.add(info.name(), metric);
    return metric;
  }
  final Class<?> cls = field.getType();
  if (cls == MutableCounterInt.class) {
    return registry.newCounter(info, 0);
  }
  if (cls == MutableCounterLong.class) {
    return registry.newCounter(info, 0L);
  }
  if (cls == MutableGaugeInt.class) {
    return registry.newGauge(info, 0);
  }
  if (cls == MutableGaugeLong.class) {
    return registry.newGauge(info, 0L);
  }
  if (cls == MutableRate.class) {
    return registry.newRate(info.name(), info.description(),
                            annotation.always());
  }
  if (cls == MutableRates.class) {
    return new MutableRates(registry);
  }
  if (cls == MutableStat.class) {
    return registry.newStat(info.name(), info.description(),
                            annotation.sampleName(), annotation.valueName(),
                            annotation.always());
  }
  throw new MetricsException("Unsupported metric field "+ field.getName() +
                             " of type "+ field.getType().getName());
}
 
Example #10
Source File: MutableMetricsFactory.java    From big-c with Apache License 2.0 5 votes vote down vote up
MutableMetric newForMethod(Object source, Method method, Metric annotation,
                           MetricsRegistry registry) {
  if (LOG.isDebugEnabled()) {
    LOG.debug("method "+ method +" with annotation "+ annotation);
  }
  MetricsInfo info = getInfo(annotation, method);
  MutableMetric metric = newForMethod(source, method, annotation);
  metric = metric != null ? metric :
      new MethodMetric(source, method, info, annotation.type());
  registry.add(info.name(), metric);
  return metric;
}
 
Example #11
Source File: JournalMetrics.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Metric("Current writer's epoch")
public long getLastWriterEpoch() {
  try {
    return journal.getLastWriterEpoch();
  } catch (IOException e) {
    return -1L;
  }
}
 
Example #12
Source File: MethodMetric.java    From hadoop with Apache License 2.0 5 votes vote down vote up
MethodMetric(Object obj, Method method, MetricsInfo info, Metric.Type type) {
  this.obj = checkNotNull(obj, "object");
  this.method = checkArg(method, method.getParameterTypes().length == 0,
                         "Metric method should have no arguments");
  this.method.setAccessible(true);
  this.info = checkNotNull(info, "info");
  impl = newImpl(checkNotNull(type, "metric type"));
}
 
Example #13
Source File: MutableMetricsFactory.java    From hadoop with Apache License 2.0 5 votes vote down vote up
protected MetricsInfo getInfo(Metric annotation, String defaultName) {
  String[] value = annotation.value();
   if (value.length == 2) {
    return Interns.info(value[0], value[1]);
  }
  if (value.length == 1) {
    return Interns.info(defaultName, value[0]);
  }
  return Interns.info(defaultName, defaultName);
}
 
Example #14
Source File: MethodMetric.java    From big-c with Apache License 2.0 5 votes vote down vote up
MethodMetric(Object obj, Method method, MetricsInfo info, Metric.Type type) {
  this.obj = checkNotNull(obj, "object");
  this.method = checkArg(method, method.getParameterTypes().length == 0,
                         "Metric method should have no arguments");
  this.method.setAccessible(true);
  this.info = checkNotNull(info, "info");
  impl = newImpl(checkNotNull(type, "metric type"));
}
 
Example #15
Source File: MutableMetricsFactory.java    From hadoop with Apache License 2.0 5 votes vote down vote up
MutableMetric newForMethod(Object source, Method method, Metric annotation,
                           MetricsRegistry registry) {
  if (LOG.isDebugEnabled()) {
    LOG.debug("method "+ method +" with annotation "+ annotation);
  }
  MetricsInfo info = getInfo(annotation, method);
  MutableMetric metric = newForMethod(source, method, annotation);
  metric = metric != null ? metric :
      new MethodMetric(source, method, info, annotation.type());
  registry.add(info.name(), metric);
  return metric;
}
 
Example #16
Source File: MutableMetricsFactory.java    From hadoop with Apache License 2.0 5 votes vote down vote up
MutableMetric newForField(Field field, Metric annotation,
                          MetricsRegistry registry) {
  if (LOG.isDebugEnabled()) {
    LOG.debug("field "+ field +" with annotation "+ annotation);
  }
  MetricsInfo info = getInfo(annotation, field);
  MutableMetric metric = newForField(field, annotation);
  if (metric != null) {
    registry.add(info.name(), metric);
    return metric;
  }
  final Class<?> cls = field.getType();
  if (cls == MutableCounterInt.class) {
    return registry.newCounter(info, 0);
  }
  if (cls == MutableCounterLong.class) {
    return registry.newCounter(info, 0L);
  }
  if (cls == MutableGaugeInt.class) {
    return registry.newGauge(info, 0);
  }
  if (cls == MutableGaugeLong.class) {
    return registry.newGauge(info, 0L);
  }
  if (cls == MutableRate.class) {
    return registry.newRate(info.name(), info.description(),
                            annotation.always());
  }
  if (cls == MutableRates.class) {
    return new MutableRates(registry);
  }
  if (cls == MutableStat.class) {
    return registry.newStat(info.name(), info.description(),
                            annotation.sampleName(), annotation.valueName(),
                            annotation.always());
  }
  throw new MetricsException("Unsupported metric field "+ field.getName() +
                             " of type "+ field.getType().getName());
}
 
Example #17
Source File: MetricsSourceBuilder.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void add(Object source, Method method) {
  for (Annotation annotation : method.getAnnotations()) {
    if (!(annotation instanceof Metric)) continue;
    factory.newForMethod(source, method, (Metric) annotation, registry);
    hasAtMetric = true;
  }
}
 
Example #18
Source File: JournalMetrics.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Metric("Number of transactions that this JN is lagging")
public long getCurrentLagTxns() {
  try {
    return journal.getCurrentLagTxns();
  } catch (IOException e) {
    return -1L;
  }
}
 
Example #19
Source File: JournalMetrics.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Metric("Last accepted epoch")
public long getLastPromisedEpoch() {
  try {
    return journal.getLastPromisedEpoch();
  } catch (IOException e) {
    return -1L;
  }
}
 
Example #20
Source File: JournalMetrics.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Metric("Current writer's epoch")
public long getLastWriterEpoch() {
  try {
    return journal.getLastWriterEpoch();
  } catch (IOException e) {
    return -1L;
  }
}
 
Example #21
Source File: IPCLoggerChannelMetrics.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Metric("The number of transactions the remote log is lagging behind the " +
        "quorum")
public long getCurrentLagTxns() {
  return ch.getLagTxns();
}
 
Example #22
Source File: IPCLoggerChannelMetrics.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Metric("Is the remote logger out of sync with the quorum")
public String isOutOfSync() {
  return Boolean.toString(ch.isOutOfSync()); 
}
 
Example #23
Source File: IPCLoggerChannelMetrics.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Metric("The number of milliseconds the remote log is lagging behind the " +
        "quorum")
public long getLagTimeMillis() {
  return ch.getLagTimeMillis();
}
 
Example #24
Source File: IPCLoggerChannelMetrics.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Metric("The number of bytes of pending data to be sent to the remote node")
public int getQueuedEditsSize() {
  return ch.getQueuedEditsSize();
}
 
Example #25
Source File: TestFileSink.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Metric(value={"testTag1", ""}, type=Type.TAG) 
String testTag1() { return "testTagValue1"; }
 
Example #26
Source File: IPCLoggerChannelMetrics.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Metric("Is the remote logger out of sync with the quorum")
public String isOutOfSync() {
  return Boolean.toString(ch.isOutOfSync()); 
}
 
Example #27
Source File: RpcMetrics.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Metric("Number of open connections") public int numOpenConnections() {
  return server.getNumOpenConnections();
}
 
Example #28
Source File: TestFileSink.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Metric(value={"testTag2", ""}, type=Type.TAG) 
String gettestTag2() { return "testTagValue2"; }
 
Example #29
Source File: TestFileSink.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Metric(value={"testTag22", ""}, type=Type.TAG) 
String testTag1() { return "testTagValue22"; }
 
Example #30
Source File: RpcMetrics.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Metric("Length of the call queue") public int callQueueLength() {
  return server.getCallQueueLen();
}