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

The following examples show how to use org.apache.hadoop.metrics2.annotation.Metric. These examples are extracted from open source projects. 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 Project: hadoop   Source File: NameNodeMetrics.java    License: 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 Project: hadoop   Source File: MethodMetric.java    License: 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 Project: big-c   Source File: NameNodeMetrics.java    License: 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 4
Source Project: big-c   Source File: MethodMetric.java    License: 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 5
Source Project: hadoop   Source File: JournalMetrics.java    License: 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 6
Source Project: hadoop   Source File: JournalMetrics.java    License: 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 Project: hadoop   Source File: JournalMetrics.java    License: 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 Project: hadoop   Source File: MetricsSourceBuilder.java    License: 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 Project: hadoop   Source File: MutableMetricsFactory.java    License: 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 Project: hadoop   Source File: MutableMetricsFactory.java    License: 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 Project: hadoop   Source File: MutableMetricsFactory.java    License: 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 12
Source Project: hadoop   Source File: MethodMetric.java    License: 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 Project: big-c   Source File: JournalMetrics.java    License: 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 14
Source Project: big-c   Source File: JournalMetrics.java    License: 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 15
Source Project: big-c   Source File: JournalMetrics.java    License: 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 16
Source Project: big-c   Source File: MetricsSourceBuilder.java    License: 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 17
Source Project: big-c   Source File: MutableMetricsFactory.java    License: 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 18
Source Project: big-c   Source File: MutableMetricsFactory.java    License: 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 19
Source Project: big-c   Source File: MutableMetricsFactory.java    License: 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 20
Source Project: big-c   Source File: MethodMetric.java    License: 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 21
Source Project: hadoop   Source File: IPCLoggerChannelMetrics.java    License: 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 22
Source Project: hadoop   Source File: IPCLoggerChannelMetrics.java    License: 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 23
Source Project: hadoop   Source File: IPCLoggerChannelMetrics.java    License: 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 Project: hadoop   Source File: IPCLoggerChannelMetrics.java    License: 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 Project: hadoop   Source File: JournalMetrics.java    License: Apache License 2.0 4 votes vote down vote up
@Metric("The highest txid stored on this JN")
public long getLastWrittenTxId() {
  return journal.getHighestWrittenTxId();
}
 
Example 26
Source Project: hadoop   Source File: MutableMetricsFactory.java    License: Apache License 2.0 4 votes vote down vote up
protected MetricsInfo getInfo(Metric annotation, Field field) {
  return getInfo(annotation, getName(field));
}
 
Example 27
Source Project: hadoop   Source File: MutableMetricsFactory.java    License: Apache License 2.0 4 votes vote down vote up
protected MetricsInfo getInfo(Metric annotation, Method method) {
  return getInfo(annotation, getName(method));
}
 
Example 28
Source Project: hadoop   Source File: RpcMetrics.java    License: Apache License 2.0 4 votes vote down vote up
@Metric("Number of open connections") public int numOpenConnections() {
  return server.getNumOpenConnections();
}
 
Example 29
Source Project: hadoop   Source File: RpcMetrics.java    License: Apache License 2.0 4 votes vote down vote up
@Metric("Length of the call queue") public int callQueueLength() {
  return server.getCallQueueLen();
}
 
Example 30
Source Project: hadoop   Source File: TestFileSink.java    License: Apache License 2.0 4 votes vote down vote up
@Metric(value={"testTag1", ""}, type=Type.TAG) 
String testTag1() { return "testTagValue1"; }