org.apache.hadoop.metrics2.MetricsInfo Java Examples

The following examples show how to use org.apache.hadoop.metrics2.MetricsInfo. 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: GlobalMetricRegistriesAdapter.java    From phoenix with 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 #2
Source File: TestInterns.java    From big-c with 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 #3
Source File: JvmMetrics.java    From hadoop with 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 #4
Source File: MetricsSystemImpl.java    From big-c with 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 #5
Source File: GangliaMetricVisitor.java    From big-c with 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 #6
Source File: GlobalMetricRegistriesAdapter.java    From phoenix with 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 File: MetricsRecordBuilderImpl.java    From hadoop with 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 #8
Source File: MetricsInfoImpl.java    From big-c with 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 #9
Source File: MetricsRegistry.java    From big-c with 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 #10
Source File: MetricsRecordBuilderImpl.java    From hadoop with 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 #11
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 #12
Source File: MetricsRegistry.java    From big-c with 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 #13
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 #14
Source File: MetricsInfoImpl.java    From hbase with 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 #15
Source File: MetricsRegistry.java    From hadoop with 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 #16
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 #17
Source File: MetricsCollectorImpl.java    From hadoop with 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 #18
Source File: MetricsRecordBuilderImpl.java    From hadoop with 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 #19
Source File: MetricsRecordBuilderImpl.java    From hadoop with 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 #20
Source File: MetricsRecordBuilderImpl.java    From big-c with 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 File: GangliaMetricVisitor.java    From hadoop with 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 #22
Source File: JvmMetrics.java    From hadoop with 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 File: MetricsRegistry.java    From big-c with 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 #24
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 #25
Source File: MutableQuantiles.java    From hadoop with 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 #26
Source File: MetricsInfoImpl.java    From hadoop with 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 #27
Source File: JvmMetrics.java    From big-c with 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 #28
Source File: MutableRangeHistogram.java    From hbase with Apache License 2.0 4 votes vote down vote up
public MutableRangeHistogram(MetricsInfo info) {
  this(info.name(), info.description());
}
 
Example #29
Source File: MetricGaugeFloat.java    From hadoop with Apache License 2.0 4 votes vote down vote up
MetricGaugeFloat(MetricsInfo info, float value) {
  super(info);
  this.value = value;
}
 
Example #30
Source File: MBeanInfoBuilder.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public void gauge(MetricsInfo info, long value) {
  attrs.add(newAttrInfo(info, "java.lang.Long"));
}