Java Code Examples for org.apache.hadoop.metrics2.MetricsInfo

The following examples show how to use org.apache.hadoop.metrics2.MetricsInfo. 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: big-c   Source File: MetricsSystemImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override public synchronized <T>
T register(String name, String desc, T source) {
  MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(source);
  final MetricsSource s = sb.build();
  MetricsInfo si = sb.info();
  String name2 = name == null ? si.name() : name;
  final String finalDesc = desc == null ? si.description() : desc;
  final String finalName = // be friendly to non-metrics tests
      DefaultMetricsSystem.sourceName(name2, !monitoring);
  allSources.put(finalName, s);
  LOG.debug(finalName +", "+ finalDesc);
  if (monitoring) {
    registerSource(finalName, finalDesc, s);
  }
  // We want to re-register the source to pick up new config when the
  // metrics system restarts.
  register(finalName, new AbstractCallback() {
    @Override public void postStart() {
      registerSource(finalName, finalDesc, s);
    }
  });
  return source;
}
 
Example 2
Source Project: hadoop   Source File: JvmMetrics.java    License: Apache License 2.0 6 votes vote down vote up
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.getNumGcWarnThreadholdExceeded());
    rb.addCounter(GcNumInfoThresholdExceeded,
        pauseMonitor.getNumGcInfoThresholdExceeded());
    rb.addCounter(GcTotalExtraSleepTime,
        pauseMonitor.getTotalGcExtraSleepTime());
  }
}
 
Example 3
Source Project: phoenix   Source File: GlobalMetricRegistriesAdapter.java    License: Apache License 2.0 6 votes vote down vote up
private void addGauge(String name, Gauge<?> gauge, MetricsRecordBuilder builder) {
    MetricsInfo info = Interns.info(name, "");
    Object o = gauge.getValue();
    if (o instanceof Integer) {
        builder.addGauge(info, (Integer)o);
    } else if (o instanceof Long) {
        builder.addGauge(info, (Long)o);
    } else if (o instanceof Float) {
        builder.addGauge(info, (Float)o);
    } else if (o instanceof Double) {
        builder.addGauge(info, (Double)o);
    } else {
        LOGGER.warn("Ignoring Gauge (" + name + ") with unhandled type: " + o.getClass());
    }

}
 
Example 4
Source Project: big-c   Source File: TestInterns.java    License: Apache License 2.0 6 votes vote down vote up
@Test public void testInfoOverflow() {
  MetricsInfo i0 = info("m0", "m desc");
  for (int i = 0; i < MAX_INFO_NAMES + 1; ++i) {
    info("m"+ i, "m desc");
    if (i < MAX_INFO_NAMES) {
      assertSame("m0 is still there", i0, info("m0", "m desc"));
    }
  }
  assertNotSame("m0 is gone", i0, info("m0", "m desc"));

  MetricsInfo i1 = info("m1", "m desc");
  for (int i = 0; i < MAX_INFO_DESCS; ++i) {
    info("m1", "m desc"+ i);
    if (i < MAX_INFO_DESCS - 1) {
      assertSame("i1 is still there", i1, info("m1", "m desc"));
    }
  }
  assertNotSame("i1 is gone", i1,  info("m1", "m desc"));
}
 
Example 5
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 6
Source Project: phoenix   Source File: GlobalMetricRegistriesAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void snapshotAllMetrics(MetricRegistry metricRegistry, MetricsCollector collector) {
    MetricRegistryInfo hbaseMetricRegistryInfo = metricRegistry.getMetricRegistryInfo();
    MetricsInfo hadoopMetricsInfo = Interns.info(hbaseMetricRegistryInfo.getMetricsName(), hbaseMetricRegistryInfo.getMetricsDescription());
    MetricsRecordBuilder builder = collector.addRecord(hadoopMetricsInfo);
    builder.setContext(hbaseMetricRegistryInfo.getMetricsContext());
    builder.tag(hadoopMetricsInfo, metricTag);
    this.snapshotAllMetrics(metricRegistry, builder);
}
 
Example 7
Source Project: big-c   Source File: MetricsRegistry.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a mutable long integer gauge
 * @param info  metadata of the metric
 * @param iVal  initial value
 * @return a new gauge object
 */
public synchronized MutableGaugeLong newGauge(MetricsInfo info, long iVal) {
  checkMetricName(info.name());
  MutableGaugeLong ret = new MutableGaugeLong(info, iVal);
  metricsMap.put(info.name(), ret);
  return ret;
}
 
Example 8
Source Project: hadoop   Source File: GangliaMetricVisitor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void counter(MetricsInfo info, long value) {
  // MetricCounterLong.class ==> "float"
  type = FLOAT;
  // counters have positive slope
  slope = GangliaSlope.positive;
}
 
Example 9
Source Project: hadoop   Source File: JvmMetrics.java    License: Apache License 2.0 5 votes vote down vote up
private MetricsInfo[] getGcInfo(String gcName) {
  MetricsInfo[] gcInfo = gcInfoCache.get(gcName);
  if (gcInfo == null) {
    gcInfo = new MetricsInfo[2];
    gcInfo[0] = Interns.info("GcCount" + gcName, "GC Count for " + gcName);
    gcInfo[1] = Interns
        .info("GcTimeMillis" + gcName, "GC Time for " + gcName);
    MetricsInfo[] previousGcInfo = gcInfoCache.putIfAbsent(gcName, gcInfo);
    if (previousGcInfo != null) {
      return previousGcInfo;
    }
  }
  return gcInfo;
}
 
Example 10
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 11
Source Project: big-c   Source File: GangliaMetricVisitor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void counter(MetricsInfo info, long value) {
  // MetricCounterLong.class ==> "float"
  type = FLOAT;
  // counters have positive slope
  slope = GangliaSlope.positive;
}
 
Example 12
Source Project: hadoop   Source File: MetricsInfoImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override public boolean equals(Object obj) {
  if (obj instanceof MetricsInfo) {
    MetricsInfo other = (MetricsInfo) obj;
    return Objects.equal(name, other.name()) &&
           Objects.equal(description, other.description());
  }
  return false;
}
 
Example 13
Source Project: hadoop   Source File: MutableQuantiles.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a new {@link MutableQuantiles} for a metric that rolls itself
 * over on the specified time interval.
 * 
 * @param name
 *          of the metric
 * @param description
 *          long-form textual description of the metric
 * @param sampleName
 *          type of items in the stream (e.g., "Ops")
 * @param valueName
 *          type of the values
 * @param interval
 *          rollover interval (in seconds) of the estimator
 */
public MutableQuantiles(String name, String description, String sampleName,
    String valueName, int interval) {
  String ucName = StringUtils.capitalize(name);
  String usName = StringUtils.capitalize(sampleName);
  String uvName = StringUtils.capitalize(valueName);
  String desc = StringUtils.uncapitalize(description);
  String lsName = StringUtils.uncapitalize(sampleName);
  String lvName = StringUtils.uncapitalize(valueName);

  numInfo = info(ucName + "Num" + usName, String.format(
      "Number of %s for %s with %ds interval", lsName, desc, interval));
  // Construct the MetricsInfos for the quantiles, converting to percentiles
  quantileInfos = new MetricsInfo[quantiles.length];
  String nameTemplate = ucName + "%dthPercentile" + uvName;
  String descTemplate = "%d percentile " + lvName + " with " + interval
      + " second interval for " + desc;
  for (int i = 0; i < quantiles.length; i++) {
    int percentile = (int) (100 * quantiles[i].quantile);
    quantileInfos[i] = info(String.format(nameTemplate, percentile),
        String.format(descTemplate, percentile));
  }

  estimator = new SampleQuantiles(quantiles);

  this.interval = interval;
  scheduler.scheduleAtFixedRate(new RolloverSample(this), interval, interval,
      TimeUnit.SECONDS);
}
 
Example 14
Source Project: big-c   Source File: MetricsRegistry.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a mutable long integer counter
 * @param info  metadata of the metric
 * @param iVal  initial value
 * @return a new counter object
 */
public synchronized
MutableCounterLong newCounter(MetricsInfo info, long iVal) {
  checkMetricName(info.name());
  MutableCounterLong ret = new MutableCounterLong(info, iVal);
  metricsMap.put(info.name(), ret);
  return ret;
}
 
Example 15
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 16
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 17
Source Project: hadoop   Source File: MetricsRegistry.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a mutable long integer gauge
 * @param info  metadata of the metric
 * @param iVal  initial value
 * @return a new gauge object
 */
public synchronized MutableGaugeLong newGauge(MetricsInfo info, long iVal) {
  checkMetricName(info.name());
  MutableGaugeLong ret = new MutableGaugeLong(info, iVal);
  metricsMap.put(info.name(), ret);
  return ret;
}
 
Example 18
Source Project: hbase   Source File: MetricsInfoImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override public boolean equals(Object obj) {
  if (obj instanceof MetricsInfo) {
    MetricsInfo other = (MetricsInfo) obj;
    return Objects.equal(name, other.name()) &&
        Objects.equal(description, other.description());
  }
  return false;
}
 
Example 19
Source Project: big-c   Source File: MetricsRegistry.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a mutable integer gauge
 * @param info  metadata of the metric
 * @param iVal  initial value
 * @return a new gauge object
 */
public synchronized MutableGaugeInt newGauge(MetricsInfo info, int iVal) {
  checkMetricName(info.name());
  MutableGaugeInt ret = new MutableGaugeInt(info, iVal);
  metricsMap.put(info.name(), ret);
  return ret;
}
 
Example 20
Source Project: big-c   Source File: MetricsRecordBuilderImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public MetricsRecordBuilderImpl addCounter(MetricsInfo info, int value) {
  if (acceptable && (metricFilter == null ||
      metricFilter.accepts(info.name()))) {
    metrics.add(new MetricCounterInt(info, value));
  }
  return this;
}
 
Example 21
Source Project: hadoop   Source File: MetricsRecordBuilderImpl.java    License: Apache License 2.0 5 votes vote down vote up
MetricsRecordBuilderImpl(MetricsCollector parent, MetricsInfo info,
                         MetricsFilter rf, MetricsFilter mf,
                         boolean acceptable) {
  this.parent = parent;
  timestamp = Time.now();
  recInfo = info;
  metrics = Lists.newArrayList();
  tags = Lists.newArrayList();
  recordFilter = rf;
  metricFilter = mf;
  this.acceptable = acceptable;
}
 
Example 22
Source Project: big-c   Source File: JvmMetrics.java    License: Apache License 2.0 5 votes vote down vote up
private MetricsInfo[] getGcInfo(String gcName) {
  MetricsInfo[] gcInfo = gcInfoCache.get(gcName);
  if (gcInfo == null) {
    gcInfo = new MetricsInfo[2];
    gcInfo[0] = Interns.info("GcCount" + gcName, "GC Count for " + gcName);
    gcInfo[1] = Interns
        .info("GcTimeMillis" + gcName, "GC Time for " + gcName);
    MetricsInfo[] previousGcInfo = gcInfoCache.putIfAbsent(gcName, gcInfo);
    if (previousGcInfo != null) {
      return previousGcInfo;
    }
  }
  return gcInfo;
}
 
Example 23
Source Project: hadoop   Source File: MetricsRecordBuilderImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public MetricsRecordBuilderImpl addCounter(MetricsInfo info, int value) {
  if (acceptable && (metricFilter == null ||
      metricFilter.accepts(info.name()))) {
    metrics.add(new MetricCounterInt(info, value));
  }
  return this;
}
 
Example 24
Source Project: big-c   Source File: MetricsInfoImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override public boolean equals(Object obj) {
  if (obj instanceof MetricsInfo) {
    MetricsInfo other = (MetricsInfo) obj;
    return Objects.equal(name, other.name()) &&
           Objects.equal(description, other.description());
  }
  return false;
}
 
Example 25
Source Project: hadoop   Source File: MetricsRecordBuilderImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public MetricsRecordBuilderImpl addGauge(MetricsInfo info, float value) {
  if (acceptable && (metricFilter == null ||
      metricFilter.accepts(info.name()))) {
    metrics.add(new MetricGaugeFloat(info, value));
  }
  return this;
}
 
Example 26
Source Project: hadoop   Source File: MetricsRecordBuilderImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public MetricsRecordBuilderImpl addGauge(MetricsInfo info, double value) {
  if (acceptable && (metricFilter == null ||
      metricFilter.accepts(info.name()))) {
    metrics.add(new MetricGaugeDouble(info, value));
  }
  return this;
}
 
Example 27
Source Project: hadoop   Source File: MetricsCollectorImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public MetricsRecordBuilderImpl addRecord(MetricsInfo info) {
  boolean acceptable = recordFilter == null ||
                       recordFilter.accepts(info.name());
  MetricsRecordBuilderImpl rb = new MetricsRecordBuilderImpl(this, info,
      recordFilter, metricFilter, acceptable);
  if (acceptable) rbs.add(rb);
  return rb;
}
 
Example 28
Source Project: big-c   Source File: QueueMetrics.java    License: Apache License 2.0 4 votes vote down vote up
protected QueueMetrics tag(MetricsInfo info, String value) {
  registry.tag(info, value);
  return this;
}
 
Example 29
Source Project: big-c   Source File: MetricCounterInt.java    License: Apache License 2.0 4 votes vote down vote up
MetricCounterInt(MetricsInfo info, int value) {
  super(info);
  this.value = value;
}
 
Example 30
Source Project: big-c   Source File: MetricsRegistry.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return the info object of the metrics registry
 */
public MetricsInfo info() {
  return metricsInfo;
}