org.apache.hadoop.metrics2.lib.Interns Java Examples

The following examples show how to use org.apache.hadoop.metrics2.lib.Interns. 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: SCMContainerMetrics.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("SuspiciousMethodCalls")
public void getMetrics(MetricsCollector collector, boolean all) {
  Map<String, Integer> stateCount = scmmxBean.getContainerStateCount();

  collector.addRecord(SOURCE)
      .addGauge(Interns.info("OpenContainers",
          "Number of open containers"),
          stateCount.get(OPEN.toString()))
      .addGauge(Interns.info("ClosingContainers",
          "Number of containers in closing state"),
          stateCount.get(CLOSING.toString()))
      .addGauge(Interns.info("QuasiClosedContainers",
          "Number of containers in quasi closed state"),
          stateCount.get(QUASI_CLOSED.toString()))
      .addGauge(Interns.info("ClosedContainers",
          "Number of containers in closed state"),
          stateCount.get(CLOSED.toString()))
      .addGauge(Interns.info("DeletingContainers",
          "Number of containers in deleting state"),
          stateCount.get(DELETING.toString()))
      .addGauge(Interns.info("DeletedContainers",
          "Number of containers in deleted state"),
          stateCount.get(DELETED.toString()));
}
 
Example #2
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 #3
Source File: RocksDBStoreMBean.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Collect all histogram metrics from RocksDB statistics.
 * @param rb Metrics Record Builder.
 */
private void getHistogramData(MetricsRecordBuilder rb) {
  for (HistogramType histogramType : HistogramType.values()) {
    HistogramData histogram =
        statistics.getHistogramData(
            HistogramType.valueOf(histogramType.name()));
    for (String histogramAttribute : histogramAttributes) {
      try {
        Method method =
            HistogramData.class.getMethod("get" + histogramAttribute);
        double metricValue =  (double) method.invoke(histogram);
        rb.addGauge(Interns.info(histogramType.name() + "_" +
                histogramAttribute.toUpperCase(), "RocksDBStat"),
            metricValue);
      } catch (Exception e) {
        LOG.error("Error reading histogram data", e);
      }
    }
  }
}
 
Example #4
Source File: HadoopMetrics2Reporter.java    From kylin with Apache License 2.0 6 votes vote down vote up
private HadoopMetrics2Reporter(MetricRegistry registry, TimeUnit rateUnit, TimeUnit durationUnit,
        MetricFilter filter, MetricsSystem metrics2System, String jmxContext, String description, String recordName,
        String context) {
    super(registry, "hadoop-metrics2-reporter", filter, rateUnit, durationUnit);
    this.metrics2Registry = new MetricsRegistry(Interns.info(jmxContext, description));
    this.metrics2System = metrics2System;
    this.recordName = recordName;
    this.context = context;

    // These could really be Collection.emptyMap(), but this makes testing a bit easier.
    this.dropwizardGauges = EMPTY_GAUGE_MAP;
    this.dropwizardCounters = EMPTY_COUNTER_MAP;
    this.dropwizardHistograms = EMPTY_HISTOGRAM_MAP;
    this.dropwizardMeters = EMPTY_METER_MAP;
    this.dropwizardTimers = EMPTY_TIMER_MAP;

    // Register this source with the Metrics2 system.
    // Make sure this is the last thing done as getMetrics() can be called at any time after.
    this.metrics2System.register(Objects.requireNonNull(jmxContext), Objects.requireNonNull(description), this);
}
 
Example #5
Source File: ProtocolMessageMetrics.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
  counters.forEach((key, value) -> {
    MetricsRecordBuilder builder =
        collector.addRecord(name);
    builder.add(
        new MetricsTag(Interns.info("type", "Message type"), key.toString()));
    builder.addCounter(new MetricName("counter", "Number of distinct calls"),
        value.longValue());
    builder.addCounter(
        new MetricName("time", "Sum of the duration of the calls"),
        elapsedTimes.get(key).longValue());
    builder.endRecord();

  });
}
 
Example #6
Source File: HadoopMetrics2Reporter.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private HadoopMetrics2Reporter(MetricRegistry registry, TimeUnit rateUnit, TimeUnit durationUnit,
        MetricFilter filter, MetricsSystem metrics2System, String jmxContext, String description, String recordName,
        String context) {
    super(registry, "hadoop-metrics2-reporter", filter, rateUnit, durationUnit);
    this.metrics2Registry = new MetricsRegistry(Interns.info(jmxContext, description));
    this.metrics2System = metrics2System;
    this.recordName = recordName;
    this.context = context;

    // These could really be Collection.emptyMap(), but this makes testing a bit easier.
    this.dropwizardGauges = EMPTY_GAUGE_MAP;
    this.dropwizardCounters = EMPTY_COUNTER_MAP;
    this.dropwizardHistograms = EMPTY_HISTOGRAM_MAP;
    this.dropwizardMeters = EMPTY_METER_MAP;
    this.dropwizardTimers = EMPTY_TIMER_MAP;

    // Register this source with the Metrics2 system.
    // Make sure this is the last thing done as getMetrics() can be called at any time after.
    this.metrics2System.register(Objects.requireNonNull(jmxContext), Objects.requireNonNull(description), this);
}
 
Example #7
Source File: MetricsMasterQuotaSourceImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
  MetricsRecordBuilder record = metricsCollector.addRecord(metricsRegistry.info());
  if (wrapper != null) {
    // Summarize the tables
    Map<String,Entry<Long,Long>> tableUsages = wrapper.getTableSpaceUtilization();
    String tableSummary = "[]";
    if (tableUsages != null && !tableUsages.isEmpty()) {
      tableSummary = generateJsonQuotaSummary(tableUsages.entrySet(), "table");
    }
    record.tag(Interns.info(TABLE_QUOTA_USAGE_NAME, TABLE_QUOTA_USAGE_DESC), tableSummary);

    // Summarize the namespaces
    String nsSummary = "[]";
    Map<String,Entry<Long,Long>> namespaceUsages = wrapper.getNamespaceSpaceUtilization();
    if (namespaceUsages != null && !namespaceUsages.isEmpty()) {
      nsSummary = generateJsonQuotaSummary(namespaceUsages.entrySet(), "namespace");
    }
    record.tag(Interns.info(NS_QUOTA_USAGE_NAME, NS_QUOTA_USAGE_DESC), nsSummary);
  }
  metricsRegistry.snapshot(record, all);
}
 
Example #8
Source File: HBaseMetrics2HadoopMetricsAdapter.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void addGauge(String name, Gauge<?> gauge, MetricsRecordBuilder builder) {
  final MetricsInfo info = Interns.info(name, EMPTY_STRING);
  final Object o = gauge.getValue();

  // Figure out which gauge types metrics2 supports and call the right method
  if (o instanceof Integer) {
    builder.addGauge(info, (int) 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 {
    LOG.warn("Ignoring Gauge (" + name + ") with unhandled type: " + o.getClass());
  }
}
 
Example #9
Source File: HadoopMetrics2ReporterTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testCounterReporting() {
    final Counter counter = new Counter();

    TreeMap<String, Counter> counters = new TreeMap<>();
    counters.put("my_counter", counter);
    // Add the metrics objects to the internal "queues" by hand
    metrics2Reporter.setDropwizardCounters(counters);

    // Set some values
    counter.inc(5L);

    MetricsCollector collector = mock(MetricsCollector.class);
    MetricsRecordBuilder recordBuilder = mock(MetricsRecordBuilder.class);

    Mockito.when(collector.addRecord(recordName)).thenReturn(recordBuilder);

    metrics2Reporter.getMetrics(collector, true);

    verify(recordBuilder).addCounter(Interns.info("my_counter", ""), 5L);
    verifyRecordBuilderUnits(recordBuilder);

    // Should not be the same instance we gave before. Our map should have gotten swapped out.
    assertTrue("Should not be the same map instance after collection",
            counters != metrics2Reporter.getDropwizardCounters());
}
 
Example #10
Source File: HadoopMetrics2ReporterTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Test
public void testCounterReporting() {
    final Counter counter = new Counter();

    TreeMap<String, Counter> counters = new TreeMap<>();
    counters.put("my_counter", counter);
    // Add the metrics objects to the internal "queues" by hand
    metrics2Reporter.setDropwizardCounters(counters);

    // Set some values
    counter.inc(5L);

    MetricsCollector collector = mock(MetricsCollector.class);
    MetricsRecordBuilder recordBuilder = mock(MetricsRecordBuilder.class);

    Mockito.when(collector.addRecord(recordName)).thenReturn(recordBuilder);

    metrics2Reporter.getMetrics(collector, true);

    verify(recordBuilder).addCounter(Interns.info("my_counter", ""), 5L);
    verifyRecordBuilderUnits(recordBuilder);

    // Should not be the same instance we gave before. Our map should have gotten swapped out.
    assertTrue("Should not be the same map instance after collection",
            counters != metrics2Reporter.getDropwizardCounters());
}
 
Example #11
Source File: SCMPipelineMetrics.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
void createPerPipelineMetrics(Pipeline pipeline) {
  numBlocksAllocated.put(pipeline.getId(), new MutableCounterLong(Interns
      .info(getBlockAllocationMetricName(pipeline),
          "Number of blocks allocated in pipeline " + pipeline.getId()), 0L));
  numBytesWritten.put(pipeline.getId(), new MutableCounterLong(Interns
      .info(getBytesWrittenMetricName(pipeline),
          "Number of bytes written into pipeline " + pipeline.getId()), 0L));
}
 
Example #12
Source File: MetricsRecordBuilderImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public MetricsRecordBuilderImpl tag(MetricsInfo info, String value) {
  if (acceptable) {
    tags.add(Interns.tag(info, value));
  }
  return this;
}
 
Example #13
Source File: TraceMetricSource.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void receiveSpan(Span span) {
  Metric builder = new Metric(span);
  // add all the metrics for the span
  builder.addCounter(Interns.info(SPAN.traceName, EMPTY_STRING), span.getSpanId());
  builder.addCounter(Interns.info(PARENT.traceName, EMPTY_STRING), span.getParentId());
  builder.addCounter(Interns.info(START.traceName, EMPTY_STRING), span.getStartTimeMillis());
  builder.addCounter(Interns.info(END.traceName, EMPTY_STRING), span.getStopTimeMillis());
  // add the tags to the span. They were written in order received so we mark them as such
  for (TimelineAnnotation ta : span.getTimelineAnnotations()) {
    builder.add(new MetricsTag(Interns.info(TAG.traceName, Long.toString(ta.getTime())), ta
        .getMessage()));
  }

  // add the annotations. We assume they are serialized as strings and integers, but that can
  // change in the future
  Map<byte[], byte[]> annotations = span.getKVAnnotations();
  for (Entry<byte[], byte[]> annotation : annotations.entrySet()) {
    Pair<String, String> val =
        TracingUtils.readAnnotation(annotation.getKey(), annotation.getValue());
    builder.add(new MetricsTag(Interns.info(ANNOTATION.traceName, val.getFirst()), val
        .getSecond()));
  }

  // add the span to the list we care about
  synchronized (this) {
    spans.add(builder);
  }
}
 
Example #14
Source File: HadoopMetrics2Reporter.java    From kylin with Apache License 2.0 5 votes vote down vote up
/**
 * Add Dropwizard-Metrics value-distribution data to a Hadoop-Metrics2 record building, converting
 * the durations to the appropriate unit.
 *
 * @param builder A Hadoop-Metrics2 record builder.
 * @param name A base name for this record.
 * @param desc A description for this record.
 * @param snapshot The distribution of measured values.
 */
private void addSnapshot(MetricsRecordBuilder builder, String name, String desc, Snapshot snapshot) {
    builder.addGauge(Interns.info(name + "_mean", desc), convertDuration(snapshot.getMean()));
    builder.addGauge(Interns.info(name + "_min", desc), convertDuration(snapshot.getMin()));
    builder.addGauge(Interns.info(name + "_max", desc), convertDuration(snapshot.getMax()));
    builder.addGauge(Interns.info(name + "_median", desc), convertDuration(snapshot.getMedian()));
    builder.addGauge(Interns.info(name + "_stddev", desc), convertDuration(snapshot.getStdDev()));

    builder.addGauge(Interns.info(name + "_75thpercentile", desc), convertDuration(snapshot.get75thPercentile()));
    builder.addGauge(Interns.info(name + "_95thpercentile", desc), convertDuration(snapshot.get95thPercentile()));
    builder.addGauge(Interns.info(name + "_98thpercentile", desc), convertDuration(snapshot.get98thPercentile()));
    builder.addGauge(Interns.info(name + "_99thpercentile", desc), convertDuration(snapshot.get99thPercentile()));
    builder.addGauge(Interns.info(name + "_999thpercentile", desc), convertDuration(snapshot.get999thPercentile()));
}
 
Example #15
Source File: HadoopMetrics2ReporterTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGaugeReporting() {
    final AtomicLong gaugeValue = new AtomicLong(0L);
    @SuppressWarnings("rawtypes")
    final Gauge gauge = new Gauge<Long>() {
        @Override
        public Long getValue() {
            return gaugeValue.get();
        }
    };

    @SuppressWarnings("rawtypes")
    TreeMap<String, Gauge> gauges = new TreeMap<>();
    gauges.put("my_gauge", gauge);
    // Add the metrics objects to the internal "queues" by hand
    metrics2Reporter.setDropwizardGauges(gauges);

    // Set some values
    gaugeValue.set(5L);

    MetricsCollector collector = mock(MetricsCollector.class);
    MetricsRecordBuilder recordBuilder = mock(MetricsRecordBuilder.class);

    Mockito.when(collector.addRecord(recordName)).thenReturn(recordBuilder);

    // Make sure a value of 5 gets reported
    metrics2Reporter.getMetrics(collector, true);

    verify(recordBuilder).addGauge(Interns.info("my_gauge", ""), gaugeValue.get());
    verifyRecordBuilderUnits(recordBuilder);

    // Should not be the same instance we gave before. Our map should have gotten swapped out.
    assertTrue("Should not be the same map instance after collection",
            gauges != metrics2Reporter.getDropwizardGauges());
}
 
Example #16
Source File: HBaseMetrics2HadoopMetricsAdapter.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Iterates over the MetricRegistry and adds them to the {@code collector}.
 *
 * @param collector A metrics collector
 */
public void snapshotAllMetrics(MetricRegistry metricRegistry,
                               MetricsCollector collector) {
  MetricRegistryInfo info = metricRegistry.getMetricRegistryInfo();
  MetricsRecordBuilder builder = collector.addRecord(Interns.info(info.getMetricsName(),
      info.getMetricsDescription()));
  builder.setContext(info.getMetricsContext());

  snapshotAllMetrics(metricRegistry, builder);
}
 
Example #17
Source File: HBaseMetrics2HadoopMetricsAdapter.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Add Dropwizard-Metrics rate information to a Hadoop-Metrics2 record builder, converting the
 * rates to the appropriate unit.
 *
 * @param builder A Hadoop-Metrics2 record builder.
 * @param name A base name for this record.
 */
private void addMeter(String name, Meter meter, MetricsRecordBuilder builder) {
  builder.addGauge(Interns.info(name + "_count", EMPTY_STRING), meter.getCount());
  builder.addGauge(Interns.info(name + "_mean_rate", EMPTY_STRING), meter.getMeanRate());
  builder.addGauge(Interns.info(name + "_1min_rate", EMPTY_STRING), meter.getOneMinuteRate());
  builder.addGauge(Interns.info(name + "_5min_rate", EMPTY_STRING), meter.getFiveMinuteRate());
  builder.addGauge(Interns.info(name + "_15min_rate", EMPTY_STRING),
      meter.getFifteenMinuteRate());
}
 
Example #18
Source File: MetricsUserAggregateSourceImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
  MetricsRecordBuilder mrb = collector.addRecord(metricsName);

  if (userSources != null) {
    for (MetricsUserSource userMetricSource : userSources.values()) {
      if (userMetricSource instanceof MetricsUserSourceImpl) {
        ((MetricsUserSourceImpl) userMetricSource).snapshot(mrb, all);
      }
    }
    mrb.addGauge(Interns.info(NUM_USERS, NUMBER_OF_USERS_DESC), userSources.size());
    metricsRegistry.snapshot(mrb, all);
  }
}
 
Example #19
Source File: MetricsIOSourceImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
  MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName);

  // wrapper can be null because this function is called inside of init.
  if (wrapper != null) {
    mrb.addCounter(Interns.info(CHECKSUM_FAILURES_KEY, CHECKSUM_FAILURES_DESC),
      wrapper.getChecksumFailures());
  }

  metricsRegistry.snapshot(mrb, all);
}
 
Example #20
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 #21
Source File: GlobalMetricRegistriesAdapter.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void addMeter(String name, Meter meter, MetricsRecordBuilder builder) {
    builder.addGauge(Interns.info(name + "_count", ""), meter.getCount());
    builder.addGauge(Interns.info(name + "_mean_rate", ""), meter.getMeanRate());
    builder.addGauge(Interns.info(name + "_1min_rate", ""), meter.getOneMinuteRate());
    builder.addGauge(Interns.info(name + "_5min_rate", ""), meter.getFiveMinuteRate());
    builder.addGauge(Interns.info(name + "_15min_rate", ""), meter.getFifteenMinuteRate());
}
 
Example #22
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 #23
Source File: MetricsRecordBuilderImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public MetricsRecordBuilderImpl tag(MetricsInfo info, String value) {
  if (acceptable) {
    tags.add(Interns.tag(info, value));
  }
  return this;
}
 
Example #24
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 #25
Source File: TestSCMContainerMetrics.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@Test
public void testSCMContainerMetrics() {
  SCMMXBean scmmxBean = mock(SCMMXBean.class);

  Map<String, Integer> stateInfo = new HashMap<String, Integer>() {{
      put(HddsProtos.LifeCycleState.OPEN.toString(), 2);
      put(HddsProtos.LifeCycleState.CLOSING.toString(), 3);
      put(HddsProtos.LifeCycleState.QUASI_CLOSED.toString(), 4);
      put(HddsProtos.LifeCycleState.CLOSED.toString(), 5);
      put(HddsProtos.LifeCycleState.DELETING.toString(), 6);
      put(HddsProtos.LifeCycleState.DELETED.toString(), 7);
    }};


  when(scmmxBean.getContainerStateCount()).thenReturn(stateInfo);

  MetricsRecordBuilder mb = mock(MetricsRecordBuilder.class);
  when(mb.addGauge(any(MetricsInfo.class), anyInt())).thenReturn(mb);

  MetricsCollector metricsCollector = mock(MetricsCollector.class);
  when(metricsCollector.addRecord(anyString())).thenReturn(mb);

  SCMContainerMetrics containerMetrics = new SCMContainerMetrics(scmmxBean);

  containerMetrics.getMetrics(metricsCollector, true);

  verify(mb, times(1)).addGauge(Interns.info("OpenContainers",
      "Number of open containers"), 2);
  verify(mb, times(1)).addGauge(Interns.info("ClosingContainers",
      "Number of containers in closing state"), 3);
  verify(mb, times(1)).addGauge(Interns.info("QuasiClosedContainers",
      "Number of containers in quasi closed state"), 4);
  verify(mb, times(1)).addGauge(Interns.info("ClosedContainers",
      "Number of containers in closed state"), 5);
  verify(mb, times(1)).addGauge(Interns.info("DeletingContainers",
      "Number of containers in deleting state"), 6);
  verify(mb, times(1)).addGauge(Interns.info("DeletedContainers",
      "Number of containers in deleted state"), 7);
}
 
Example #26
Source File: RocksDBStoreMBean.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Collect all Counter metrics from RocksDB statistics.
 * @param rb Metrics Record Builder.
 */
private void getTickerTypeData(MetricsRecordBuilder rb) {
  for (TickerType tickerType : TickerType.values()) {
    rb.addCounter(Interns.info(tickerType.name(), "RocksDBStat"),
        statistics.getTickerCount(tickerType));
  }
}
 
Example #27
Source File: HadoopMetrics2Reporter.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Add Dropwizard-Metrics value-distribution data to a Hadoop-Metrics2 record building, converting
 * the durations to the appropriate unit.
 *
 * @param builder A Hadoop-Metrics2 record builder.
 * @param name A base name for this record.
 * @param desc A description for this record.
 * @param snapshot The distribution of measured values.
 */
private void addSnapshot(MetricsRecordBuilder builder, String name, String desc, Snapshot snapshot) {
    builder.addGauge(Interns.info(name + "_mean", desc), convertDuration(snapshot.getMean()));
    builder.addGauge(Interns.info(name + "_min", desc), convertDuration(snapshot.getMin()));
    builder.addGauge(Interns.info(name + "_max", desc), convertDuration(snapshot.getMax()));
    builder.addGauge(Interns.info(name + "_median", desc), convertDuration(snapshot.getMedian()));
    builder.addGauge(Interns.info(name + "_stddev", desc), convertDuration(snapshot.getStdDev()));

    builder.addGauge(Interns.info(name + "_75thpercentile", desc), convertDuration(snapshot.get75thPercentile()));
    builder.addGauge(Interns.info(name + "_95thpercentile", desc), convertDuration(snapshot.get95thPercentile()));
    builder.addGauge(Interns.info(name + "_98thpercentile", desc), convertDuration(snapshot.get98thPercentile()));
    builder.addGauge(Interns.info(name + "_99thpercentile", desc), convertDuration(snapshot.get99thPercentile()));
    builder.addGauge(Interns.info(name + "_999thpercentile", desc), convertDuration(snapshot.get999thPercentile()));
}
 
Example #28
Source File: HadoopMetrics2ReporterTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGaugeReporting() {
    final AtomicLong gaugeValue = new AtomicLong(0L);
    @SuppressWarnings("rawtypes")
    final Gauge gauge = new Gauge<Long>() {
        @Override
        public Long getValue() {
            return gaugeValue.get();
        }
    };

    @SuppressWarnings("rawtypes")
    TreeMap<String, Gauge> gauges = new TreeMap<>();
    gauges.put("my_gauge", gauge);
    // Add the metrics objects to the internal "queues" by hand
    metrics2Reporter.setDropwizardGauges(gauges);

    // Set some values
    gaugeValue.set(5L);

    MetricsCollector collector = mock(MetricsCollector.class);
    MetricsRecordBuilder recordBuilder = mock(MetricsRecordBuilder.class);

    Mockito.when(collector.addRecord(recordName)).thenReturn(recordBuilder);

    // Make sure a value of 5 gets reported
    metrics2Reporter.getMetrics(collector, true);

    verify(recordBuilder).addGauge(Interns.info("my_gauge", ""), gaugeValue.get());
    verifyRecordBuilderUnits(recordBuilder);

    // Should not be the same instance we gave before. Our map should have gotten swapped out.
    assertTrue("Should not be the same map instance after collection",
            gauges != metrics2Reporter.getDropwizardGauges());
}
 
Example #29
Source File: SCMPipelineMetrics.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
/**
 * Increments the number of total bytes that write into the pipeline.
 */
void incNumPipelineBytesWritten(Pipeline pipeline, long bytes) {
  numBytesWritten.put(pipeline.getId(), new MutableCounterLong(
      Interns.info(getBytesWrittenMetricName(pipeline), "Number of" +
          " bytes written into pipeline " + pipeline.getId()), bytes));
}
 
Example #30
Source File: MetricsSystemImpl.java    From big-c with Apache License 2.0 4 votes vote down vote up
private synchronized void configureSystem() {
  injectedTags.add(Interns.tag(MsInfo.Hostname, getHostname()));
}