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."); }
/** * Get map of all metrics. * * @return Map of all metrics held. */ public Map<MetricName, Metric> getAll() { return registry.allMetrics(); }
/** * Get a Gauge that is already present in the MetricsRegistry * * @param name String name of Gauge * @param <T> value type Gauge returns * @return Gauge<T> from MetricsRegistry */ public <T> Gauge<T> getExistingGauge(String name) { Metric metric = registry.allMetrics().get(makeMetricName(name)); return metric instanceof Gauge ? (Gauge<T>) metric : null; }
private static void expireOldTimers(MetricsRegistry registry) { long expireOlderThan = System.currentTimeMillis() - EXPIRE_REGION_TIMERS_MS; for(Map.Entry<MetricName,Metric> e: registry.allMetrics().entrySet()) { if(!(e.getValue() instanceof SHTimerMetric)) { continue; } SHTimerMetric metric = (SHTimerMetric)e.getValue(); if(metric.getLastUpdateMillis() < expireOlderThan) { registry.removeMetric(e.getKey()); } } }
@Override public void run() { metricsGeneratedLastPass.set(0); try { if (includeJvmMetrics) upsertJavaMetrics(); // non-histograms go first getMetricsRegistry().allMetrics().entrySet().stream().filter(m -> !(m.getValue() instanceof WavefrontHistogram)). forEach(this::processEntry); // histograms go last getMetricsRegistry().allMetrics().entrySet().stream().filter(m -> m.getValue() instanceof WavefrontHistogram). forEach(this::processEntry); socketMetricProcessor.flush(); } catch (Exception e) { logger.log(Level.SEVERE, "Cannot report point to Wavefront! Trying again next iteration.", e); } }
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 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(); } }
@ManagedAttribute public Map<String, Object> getStats() { Map<String, Object> stats = new HashMap<String, Object>(); MetricsRegistry registry = Metrics.defaultRegistry(); for (Entry<MetricName, Metric> e : registry.allMetrics().entrySet()) { MetricName name = e.getKey(); Metric metric = e.getValue(); if (metric instanceof Meter) { Meter m = (Meter) metric; stats.put(name.toString(), new MeterPOJO(m)); } else if (metric instanceof Gauge) { Gauge<?> g = (Gauge<?>) metric; stats.put(name.toString(), g.value()); } } return stats; } }
final Set<Map.Entry<MetricName, Metric>> metrics = getMetricsRegistry().allMetrics().entrySet(); try { for (Map.Entry<MetricName, Metric> entry : metrics) {
@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); } } }
if (brokerId == controllerId) { final Map<TopicPartition, Long> logEndOffsets = new HashMap<>(); final Set<Map.Entry<MetricName, Metric>> metrics = getMetricsRegistry().allMetrics().entrySet(); try { for (Map.Entry<MetricName, Metric> entry : metrics) {
@Test public void testCreateMetric_ShortName() { String name = "test" + Math.random(); jsonMetric.setName(name); Metric metric = metricCatcher.createMetric(jsonMetric); Map<MetricName, Metric> allMetrics = Metrics.defaultRegistry().allMetrics(); MetricName metricName = new MetricName(name, "", ""); assertTrue(allMetrics.containsKey(metricName)); Metric actual = allMetrics.get(metricName); assertEquals(metric, actual); }
/** * Release all associated metrics. */ public void release() { for(String name : all) { allColumnFamilyMetrics.get(name).remove(Metrics.defaultRegistry().allMetrics().get(factory.createMetricName(name))); Metrics.defaultRegistry().removeMetric(factory.createMetricName(name)); } readLatency.release(); writeLatency.release(); rangeLatency.release(); Metrics.defaultRegistry().removeMetric(factory.createMetricName("EstimatedRowSizeHistogram")); Metrics.defaultRegistry().removeMetric(factory.createMetricName("EstimatedRowCount")); Metrics.defaultRegistry().removeMetric(factory.createMetricName("EstimatedColumnCountHistogram")); Metrics.defaultRegistry().removeMetric(factory.createMetricName("KeyCacheHitRate")); Metrics.defaultRegistry().removeMetric(factory.createMetricName("CoordinatorReadLatency")); Metrics.defaultRegistry().removeMetric(factory.createMetricName("CoordinatorScanLatency")); Metrics.defaultRegistry().removeMetric(factory.createMetricName("WaitingOnFreeMemtableSpace")); }