@VisibleForTesting public MmapMemoryManager(String dirPathName, String segmentName) { this(dirPathName, segmentName, new ServerMetrics(new MetricsRegistry())); }
/** * * Return an existing gauge if * (a) A gauge already exist with the same metric name. * Otherwise, creates a new meter and registers * * @param registry MetricsRegistry * @param name metric name * @param gauge Underlying gauge to be tracked * @return gauge */ public static <T> Gauge<T> newGauge(MetricsRegistry registry, MetricName name, Gauge<T> gauge) { if (registry != null) { return registry.newGauge(name, gauge); } else { return Metrics.newGauge(name, gauge); } }
/** * * Return an existing timer if * (a) A timer already exist with the same metric name. * Otherwise, creates a new timer and registers * * @param registry MetricsRegistry * @param name metric name * @param durationUnit TimeUnit for duration * @param rateUnit TimeUnit for rate determination * @return Timer */ public static Timer newTimer(MetricsRegistry registry, MetricName name, TimeUnit durationUnit, TimeUnit rateUnit) { if (registry != null) { return registry.newTimer(name, durationUnit, rateUnit); } else { return Metrics.newTimer(name, durationUnit, rateUnit); } }
@OnScheduled public void onConfigure(final ConfigurationContext config) throws InitializationException { metricsRegistry = new MetricsRegistry(); metricsRegistry.newGauge(new MetricName(METRICS_GROUP, "int32", "FlowFiles Received Last 5 mins"), new Gauge<Integer>() { @Override public Integer value() { metricsRegistry.newGauge(new MetricName(METRICS_GROUP, "int64", "Bytes Received Last 5 mins"), new Gauge<Long>() { @Override public Long value() { metricsRegistry.newGauge(new MetricName(METRICS_GROUP, "int32", "FlowFiles Sent Last 5 mins"), new Gauge<Integer>() { @Override public Integer value() { metricsRegistry.newGauge(new MetricName(METRICS_GROUP, "int64", "Bytes Sent Last 5 mins"), new Gauge<Long>() { @Override public Long value() { metricsRegistry.newGauge(new MetricName(METRICS_GROUP, "int32", "FlowFiles Queued"), new Gauge<Integer>() { @Override public Integer value() { metricsRegistry.newGauge(new MetricName(METRICS_GROUP, "int64", "Bytes Queued"), new Gauge<Long>() { @Override public Long value() { metricsRegistry.newGauge(new MetricName(METRICS_GROUP, "int64", "Bytes Read (5 mins)"), new Gauge<Long>() { @Override
public MetricsConnection(final ConnectionManager.HConnectionImplementation conn) { this.scope = conn.toString(); this.registry = new MetricsRegistry(); final ThreadPoolExecutor batchPool = (ThreadPoolExecutor) conn.getCurrentBatchPool(); final ThreadPoolExecutor metaPool = (ThreadPoolExecutor) conn.getCurrentMetaLookupPool(); this.registry.newGauge(this.getClass(), "executorPoolActiveThreads", scope, new RatioGauge() { @Override protected double getNumerator() { this.registry.newGauge(this.getClass(), "metaPoolActiveThreads", scope, new RatioGauge() { @Override protected double getNumerator() { this.metaCacheHits = registry.newCounter(this.getClass(), "metaCacheHits", scope); this.metaCacheMisses = registry.newCounter(this.getClass(), "metaCacheMisses", scope); this.getTracker = new CallTracker(this.registry, "Get", scope); this.scanTracker = new CallTracker(this.registry, "Scan", scope);
/** * Returns a grouped and sorted map of all registered metrics. * * @return all registered metrics, grouped by name and sorted */ public SortedMap<String, SortedMap<MetricName, Metric>> groupedMetrics() { return groupedMetrics(MetricPredicate.ALL); }
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."); }
/** * * Return an existing meter if * (a) A meter already exist with the same metric name. * Otherwise, creates a new meter and registers * * @param registry MetricsRegistry * @param name metric name * @param eventType Event Type * @param unit TimeUnit for rate determination * @return Meter */ public static Meter newMeter(MetricsRegistry registry, MetricName name, String eventType, TimeUnit unit) { if (registry != null) { return registry.newMeter(name, eventType, unit); } else { return Metrics.newMeter(name, eventType, unit); } }
public static void main(String[] args) throws IOException, InterruptedException { // Parse inputs. System.out.println("Args: " + Joiner.on(", ").join(args)); if (args.length != 2) { System.out.println("Usage: java -jar this.jar <metricsPort> <histogramsPort>"); return; } int port = Integer.parseInt(args[0]); int histoPort = Integer.parseInt(args[1]); // Set up periodic reporting. MetricsRegistry metricsRegistry = new MetricsRegistry(); WavefrontYammerMetricsReporter wavefrontYammerMetricsReporter = new WavefrontYammerMetricsReporter(metricsRegistry, "wavefrontYammerMetrics", "localhost", port, histoPort, System::currentTimeMillis); wavefrontYammerMetricsReporter.start(5, TimeUnit.SECONDS); // Populate test metrics. Counter counter = metricsRegistry.newCounter(new TaggedMetricName("group", "mycounter", "tag1", "value1")); Histogram histogram = metricsRegistry.newHistogram(new TaggedMetricName("group2", "myhisto"), false); WavefrontHistogram wavefrontHistogram = WavefrontHistogram.get(metricsRegistry, new TaggedMetricName("group", "mywavefronthisto", "tag2", "value2")); while (true) { counter.inc(); histogram.update(counter.count()); wavefrontHistogram.update(counter.count()); Thread.sleep(1000); } }
@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()); }
public static void shutdownMetrics(String indexerName) { SortedMap<String, SortedMap<MetricName, Metric>> groupedMetrics = Metrics.defaultRegistry().groupedMetrics( new IndexerMetricPredicate(indexerName)); for (SortedMap<MetricName, Metric> metricMap : groupedMetrics.values()) { for (MetricName metricName : metricMap.keySet()) { Metrics.defaultRegistry().removeMetric(metricName); } } }
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()); } } }
/** * Removes an existing metric */ public static void removeMetric(MetricsRegistry registry, MetricName name) { if (registry != null) { registry.removeMetric(name); } else { Metrics.defaultRegistry().removeMetric(name); } }
private CallTracker(MetricsRegistry registry, String name, String subName, String scope) { StringBuilder sb = new StringBuilder(CLIENT_SVC).append("_").append(name); if (subName != null) { sb.append("(").append(subName).append(")"); } this.name = sb.toString(); this.callTimer = registry.newTimer(MetricsConnection.class, DRTN_BASE + this.name, scope); this.reqHist = registry.newHistogram(MetricsConnection.class, REQ_BASE + this.name, scope); this.respHist = registry.newHistogram(MetricsConnection.class, RESP_BASE + this.name, scope); }
/** * * Return an existing histogram if * (a) A histogram already exist with the same metric name. * Otherwise, creates a new meter and registers * * @param registry MetricsRegistry * @param name metric name * @param biased (true if uniform distribution, otherwise exponential weighted) * @return histogram */ public static Histogram newHistogram(MetricsRegistry registry, MetricName name, boolean biased) { if (registry != null) { return registry.newHistogram(name, biased); } else { return Metrics.newHistogram(name, biased); } }
/** * * Return an existing counter if * (a) A counter already exist with the same metric name. * Otherwise, creates a new meter and registers * * @param registry MetricsRegistry * @param name metric name * @return Counter */ public static Counter newCounter(MetricsRegistry registry, MetricName name) { if (registry != null) { return registry.newCounter(name); } else { return Metrics.newCounter(name); } }
public RunnerStats(MetricsRegistry registry) { this.normalRunners = registry.newCounter(MetricsConnection.class, "normalRunnersCount"); this.delayRunners = registry.newCounter(MetricsConnection.class, "delayRunnersCount"); this.delayIntevalHist = registry.newHistogram(MetricsConnection.class, "delayIntervalHist"); }
/** * Removes the metric for the given class with the given name and scope. * * @param klass the klass the metric is associated with * @param name the name of the metric * @param scope the scope of the metric */ public void removeMetric(Class<?> klass, String name, String scope) { removeMetric(createName(klass, name, scope)); }
/** * Creates a new {@link Counter} and registers it under the given class and name. * * @param klass the class which owns the metric * @param name the name of the metric * @param scope the scope of the metric * @return a new {@link Counter} */ public Counter newCounter(Class<?> klass, String name, String scope) { return newCounter(createName(klass, name, scope)); }
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); } } } } }