private MetricName makeMetricName(final String gaugeName) { return new MetricName(ValidationMetrics.class, gaugeName); }
/** * Convert a Yammer metric to a CruiseControlMetric */ public static CruiseControlMetric toCruiseControlMetric(long now, int brokerId, com.yammer.metrics.core.MetricName metricName, double value, String attribute) { CruiseControlMetric ccm = toCruiseControlMetric(now, brokerId, metricName.getName(), yammerMetricScopeToTags(metricName.getScope()), value, attribute); if (ccm == null) { throw new IllegalArgumentException(String.format("Cannot convert yammer metric %s to a Cruise Control metric for " + "broker %d at time %d for tag %s", metricName, brokerId, now, attribute)); } return ccm; }
@Override protected String sanitizeName(MetricName name) { return name.getName(); } };
private void copyIndexingMetricsToCounters(Context context) { final String COUNTER_GROUP = "HBase Indexer Metrics"; SortedMap<String, SortedMap<MetricName, Metric>> groupedMetrics = Metrics.defaultRegistry().groupedMetrics( new IndexerMetricsUtil.IndexerMetricPredicate()); for (Entry<String, SortedMap<MetricName, Metric>> metricsGroupEntry : groupedMetrics.entrySet()) { SortedMap<MetricName, Metric> metricsGroupMap = metricsGroupEntry.getValue(); for (Entry<MetricName, Metric> metricEntry : metricsGroupMap.entrySet()) { MetricName metricName = metricEntry.getKey(); Metric metric = metricEntry.getValue(); String counterName = metricName.getType() + ": " + metricName.getName(); if (metric instanceof Counter) { Counter counter = (Counter) metric; context.getCounter(COUNTER_GROUP, counterName).increment(counter.count()); } else if (metric instanceof Meter) { Meter meter = (Meter) metric; context.getCounter(COUNTER_GROUP, counterName).increment(meter.count()); } else if (metric instanceof Timer) { Timer timer = (Timer) metric; context.getCounter(COUNTER_GROUP, counterName).increment((long) timer.sum()); } } } }
@Override public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { final Metered metered = method.getAnnotation(Metered.class); final String group = MetricName.chooseGroup(metered.group(), targetClass); final String type = MetricName.chooseType(metered.type(), targetClass); final String name = MetricName.chooseName(metered.name(), method); final MetricName metricName = new MetricName(group, type, name, scope); final Meter meter = metrics.newMeter(metricName, metered.eventType(), metered.rateUnit()); meters.put(method.getName(), meter); if (log.isDebugEnabled()) { log.debug("Created metric " + metricName + " for method " + method.getName()); } }
@Override public boolean matches(MetricName name, Metric metric) { return name.getType().equals(getType()); } };
private void reportYammerMetrics(long now) throws Exception { LOG.debug("Reporting yammer metrics."); YammerMetricProcessor.Context context = new YammerMetricProcessor.Context(this, now, _brokerId, _reportingIntervalMs); for (Map.Entry<com.yammer.metrics.core.MetricName, Metric> entry : Metrics.defaultRegistry().allMetrics().entrySet()) { LOG.trace("Processing yammer metric {}, scope = {}", entry.getKey(), entry.getKey().getScope()); entry.getValue().processWith(_yammerMetricProcessor, entry.getKey(), context); } LOG.debug("Finished reporting yammer metrics."); }
@Test public void testWithOptimer() { setupClient(); final MetricsRegistry registry = new MetricsRegistry(); final MetricsOpTimer opTimer = new MetricsOpTimer(registry, "TEST_CLUSTER", TimeUnit.NANOSECONDS, TimeUnit.SECONDS); connectionManager.setTimer(opTimer); connectionManager.operateWithFailover(new NullOp()); final SortedMap<String, SortedMap<MetricName, Metric>> metrics = registry.groupedMetrics(); assertNotNull("Hector metric should exist in metrics registry", metrics); assertFalse("Hector metrics should exist in metrics register", metrics.isEmpty()); final Entry<String, SortedMap<MetricName, Metric>> entry = metrics.entrySet().iterator().next(); assertEquals("Incorrect metrics key should be [cluster_name].hector", "TEST_CLUSTER.hector", entry.getKey()); final Entry<MetricName, Metric> metric = entry.getValue().entrySet().iterator().next(); assertEquals("Incorrect metrics name should be META_READ", "META_READ", metric.getKey() .getName()); assertEquals("Incorrect metrics type should be timer", Timer.class, metric.getValue() .getClass()); }
private void copyIndexingMetricsToCounters(Context context) { final String COUNTER_GROUP = "HBase Indexer Metrics"; SortedMap<String, SortedMap<MetricName, Metric>> groupedMetrics = Metrics.defaultRegistry().groupedMetrics( new IndexerMetricsUtil.IndexerMetricPredicate()); for (Entry<String, SortedMap<MetricName, Metric>> metricsGroupEntry : groupedMetrics.entrySet()) { SortedMap<MetricName, Metric> metricsGroupMap = metricsGroupEntry.getValue(); for (Entry<MetricName, Metric> metricEntry : metricsGroupMap.entrySet()) { MetricName metricName = metricEntry.getKey(); Metric metric = metricEntry.getValue(); String counterName = metricName.getType() + ": " + metricName.getName(); if (metric instanceof Counter) { Counter counter = (Counter) metric; context.getCounter(COUNTER_GROUP, counterName).increment(counter.count()); } else if (metric instanceof Meter) { Meter meter = (Meter) metric; context.getCounter(COUNTER_GROUP, counterName).increment(meter.count()); } else if (metric instanceof Timer) { Timer timer = (Timer) metric; context.getCounter(COUNTER_GROUP, counterName).increment((long) timer.sum()); } } } }
/** * Convert a Yammer metric to a CruiseControlMetric */ public static CruiseControlMetric toCruiseControlMetric(long now, int brokerId, com.yammer.metrics.core.MetricName metricName, double value, String attribute) { CruiseControlMetric ccm = toCruiseControlMetric(now, brokerId, metricName.getName(), yammerMetricScopeToTags(metricName.getScope()), value, attribute); if (ccm == null) { throw new IllegalArgumentException(String.format("Cannot convert yammer metric %s to a Cruise Control metric for " + "broker %d at time %d for tag %s", metricName, brokerId, now, attribute)); } return ccm; }
private void reportYammerMetrics(long now) throws Exception { LOG.debug("Reporting yammer metrics."); YammerMetricProcessor.Context context = new YammerMetricProcessor.Context(this, now, _brokerId, _reportingIntervalMs); for (Map.Entry<com.yammer.metrics.core.MetricName, Metric> entry : Metrics.defaultRegistry().allMetrics().entrySet()) { LOG.trace("Processing yammer metric {}, scope = {}", entry.getKey(), entry.getKey().getScope()); entry.getValue().processWith(_yammerMetricProcessor, entry.getKey(), context); } LOG.debug("Finished reporting yammer metrics."); }
public NettyServerMetrics(MetricsRegistry registry, String group) { _requestsReceived = MetricsHelper.newCounter(registry, new MetricName(group, "", REQUESTS_RECEIVED)); _bytesSent = MetricsHelper.newCounter(registry, new MetricName(group, "", BYTES_SENT)); _bytesReceived = MetricsHelper.newCounter(registry, new MetricName(group, "", BYTES_RECEIVED)); _errors = MetricsHelper.newCounter(registry, new MetricName(group, "", ERRORS)); _sendResponseMsHistogram = MetricsHelper.newHistogram(registry, new MetricName(group, "", SEND_RESPONSE_MS), false); _processingLatencyMsHistogram = MetricsHelper.newHistogram(registry, new MetricName(group, "", PROCESSING_LATENCY_MS), false); }