@Override public <T2> void processWith(MetricProcessor<T2> processor, MetricName name, T2 context) throws Exception { for (T h : _histograms) { if (h instanceof Metric) { ((Metric) h).processWith(processor, name, context); } } } }
@Override public <T> void processWith(MetricProcessor<T> processor, MetricName name, T context) throws Exception { for (Metric c : _counters) { c.processWith(processor, name, context); } }
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."); }
@Override public void onMetricAdded(MetricName name, Metric metric) { if (metric != null) { try { metric.processWith(this, name, new Context(name, new ObjectName(name.getMBeanName()))); } catch (Exception e) { LOGGER.warn("Error processing {}", name, e); } } }
private void printRegularMetrics() { for (Map.Entry<String, SortedMap<MetricName, Metric>> entry : getMetricsRegistry().groupedMetrics().entrySet()) { for (Map.Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) { final Metric metric = subEntry.getValue(); if (metric != null) { try { metric.processWith(this, subEntry.getKey(), null); } catch (Exception suppressed) { log.error("Error printing regular metrics:", suppressed); } } } } }
protected void printRegularMetrics(long epoch) { for (Map.Entry<String, SortedMap<MetricName, Metric>> entry : getMetricsRegistry().groupedMetrics(predicate).entrySet()) { for (Map.Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) { final Metric metric = subEntry.getValue(); if (metric != null) { try { metric.processWith(this, subEntry.getKey(), epoch); } catch (Exception ignored) { LOG.error("Error printing regular metrics:", ignored); } } } } }
protected void printRegularMetrics(final Long epoch) { for (Entry<String,SortedMap<MetricName,Metric>> entry : getMetricsRegistry().groupedMetrics( predicate).entrySet()) { for (Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) { final Metric metric = subEntry.getValue(); if (metric != null) { try { metric.processWith(this, subEntry.getKey(), epoch); } catch (Exception ignored) { LOG.error("Error printing regular metrics:", ignored); } } } } }
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."); }
protected void pushRegularMetrics(long epoch) { for (Entry<String, SortedMap<MetricName, Metric>> entry : getMetricsRegistry() .groupedMetrics(predicate).entrySet()) { for (Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) { final Metric metric = subEntry.getValue(); if (metric != null) { try { metric.processWith(this, subEntry.getKey(), epoch); } catch (Exception e) { LOG.error("Error pushing metric", e); } } } } }
@Override public void run() { for (Map.Entry<String, SortedMap<MetricName, Metric>> entry : getMetricsRegistry().groupedMetrics( MetricPredicate.ALL).entrySet()) { try { for (Map.Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) { out.print(" " + subEntry.getKey().getName()); out.println(':'); subEntry.getValue().processWith(this, subEntry.getKey(), out); } } catch (Exception e) { e.printStackTrace(out); } } }
private void processEntry(Map.Entry<MetricName, Metric> entry) { try { MetricName metricName = entry.getKey(); Metric metric = entry.getValue(); if (metricTranslator != null) { Pair<MetricName, Metric> pair = metricTranslator.apply(Pair.of(metricName, metric)); if (pair == null) return; metricName = pair._1; metric = pair._2; } metric.processWith(socketMetricProcessor, metricName, null); metricsGeneratedLastPass.incrementAndGet(); } catch (Exception e) { throw new RuntimeException(e); } } }
public void writeRegularMetrics(JsonGenerator json, String classPrefix, boolean showFullSamples) throws IOException { for (Map.Entry<String, SortedMap<MetricName, Metric>> entry : registry.groupedMetrics().entrySet()) { if (classPrefix == null || entry.getKey().startsWith(classPrefix)) { json.writeFieldName(entry.getKey()); json.writeStartObject(); { for (Map.Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) { json.writeFieldName(subEntry.getKey().getName()); try { subEntry.getValue() .processWith(this, subEntry.getKey(), new Context(json, showFullSamples)); } catch (Exception e) { LOGGER.warn("Error writing out {}", subEntry.getKey(), e); } } } json.writeEndObject(); } } }
/** * Filter gauges that should have been deleted, ugly workaround for KAFKA-1866 with Kafka 0.8.x * @return {@code false} if gauge is not cleaned. */ private boolean cleanInvalidGauge(MetricName name, Metric metric, String metricName) { try { metric.processWith(metricProcessor, name, null); } catch (InvalidGaugeException ex) { LOGGER.info("Deleting metric {} from registry", metricName); Metrics.defaultRegistry().removeMetric(name); return true; } catch (Exception ex) { LOGGER.error("Caught an Exception while processing metric " + metricName, ex); } return false; }
@Override public void run() { for (Map.Entry<String, SortedMap<MetricName, Metric>> group : getMetricsRegistry().groupedMetrics().entrySet()) { for (Map.Entry<MetricName, Metric> entry : group.getValue().entrySet()) { if (entry.getValue() == null || entry.getKey() == null) { logger.severe("Application Error! Pulled null value from metrics registry."); } MetricName metricName = entry.getKey(); Metric metric = entry.getValue(); try { TimeSeries timeSeries = TimeSeriesUtils.fromMetricName(metricName); metric.processWith(flushProcessor, metricName, new FlushProcessorContext(timeSeries, prefix, pointHandler)); } catch (Exception e) { logger.log(Level.SEVERE, "Uncaught exception in MetricsReporter", e); } } } }
@Override public void run() { for (Map.Entry<String, SortedMap<MetricName, Metric>> group : getMetricsRegistry().groupedMetrics().entrySet()) { for (Map.Entry<MetricName, Metric> entry : group.getValue().entrySet()) { if (entry.getValue() == null || entry.getKey() == null) { logger.severe("Application Error! Pulled null value from metrics registry."); } MetricName metricName = entry.getKey(); Metric metric = entry.getValue(); try { TimeSeries timeSeries = TimeSeriesUtils.fromMetricName(metricName); metric.processWith(flushProcessor, metricName, new FlushProcessorContext(timeSeries, prefix, pointHandler)); } catch (Exception e) { logger.log(Level.SEVERE, "Uncaught exception in MetricsReporter", e); } } } }
out.print(subEntry.getKey().getName()); out.println(':'); subEntry.getValue().processWith(this, subEntry.getKey(), out); out.println();
@Override public void run() { final long time = TimeUnit.MILLISECONDS.toSeconds(clock.time() - startTime); final Set<Entry<MetricName, Metric>> metrics = getMetricsRegistry().allMetrics().entrySet(); try { for (Entry<MetricName, Metric> entry : metrics) { final MetricName metricName = entry.getKey(); final Metric metric = entry.getValue(); if (predicate.matches(metricName, metric)) { final Context context = new Context() { @Override public PrintStream getStream(String header) throws IOException { final PrintStream stream = getPrintStream(metricName, header); stream.print(time); stream.print(','); return stream; } }; metric.processWith(this, entry.getKey(), context); } } } catch (Exception e) { e.printStackTrace(); } }
private boolean maybeIngestLog( BiFunction<MetricName, MetricMatcher, Metric> metricLoader, MetricMatcher metricMatcher, LogsMessage logsMessage) { Double[] output = {null}; TimeSeries timeSeries = metricMatcher.timeSeries(logsMessage, output); if (timeSeries == null) return false; MetricName metricName = TimeSeriesUtils.toMetricName(timeSeries); Metric metric = metricLoader.apply(metricName, metricMatcher); try { metric.processWith(readProcessor, metricName, new ReadProcessorContext(output[0])); } catch (Exception e) { logger.log(Level.SEVERE, "Could not process metric " + metricName.toString(), e); } return true; } }
private boolean maybeIngestLog( BiFunction<MetricName, MetricMatcher, Metric> metricLoader, MetricMatcher metricMatcher, LogsMessage logsMessage) { Double[] output = {null}; TimeSeries timeSeries = metricMatcher.timeSeries(logsMessage, output); if (timeSeries == null) return false; MetricName metricName = TimeSeriesUtils.toMetricName(timeSeries); Metric metric = metricLoader.apply(metricName, metricMatcher); try { metric.processWith(readProcessor, metricName, new ReadProcessorContext(output[0])); } catch (Exception e) { logger.log(Level.SEVERE, "Could not process metric " + metricName.toString(), e); } return true; } }
@Override public void run() { final Set<Map.Entry<MetricName, Metric>> metrics = getMetricsRegistry().allMetrics().entrySet(); try { List<DataObject> dataObjectList = new ArrayList<DataObject>(); for (Map.Entry<MetricName, Metric> entry : metrics) { final MetricName metricName = entry.getKey(); final Metric metric = entry.getValue(); if (predicate.matches(metricName, metric)) { metric.processWith(this, entry.getKey(), dataObjectList); } } SenderResult senderResult = sender.send(dataObjectList); if (!senderResult.success()) { log.warn("metrics reporting to zabbix {} unsuccessful: {}", sender.getHost(), sender.getPort(), senderResult); } else if (log.isDebugEnabled()) { log.debug("metrics reported to zabbix {} {}: {}", sender.getHost(), sender.getPort(), senderResult); } } catch (Exception e) { log.error("failed to report metrics to " + sender.getHost() + ':' + sender.getPort(), e); } } }