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 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); } }
Timer timer = Metrics.newTimer( BcryptCommandTest.class, "hashtimer" ); ConsoleReporter reporter = new ConsoleReporter( Metrics.defaultRegistry(), System.out, MetricPredicate.ALL );
/** * Create metrics for given ThreadPoolExecutor. * * @param executor Thread pool * @param path Type of thread pool * @param poolName Name of thread pool to identify metrics */ public ThreadPoolMetrics(final ThreadPoolExecutor executor, String path, String poolName) { this.factory = new ThreadPoolMetricNameFactory("ThreadPools", path, poolName); activeTasks = Metrics.newGauge(factory.createMetricName("ActiveTasks"), new Gauge<Integer>() { public Integer value() { return executor.getActiveCount(); } }); totalBlocked = Metrics.newCounter(factory.createMetricName("TotalBlockedTasks")); currentBlocked = Metrics.newCounter(factory.createMetricName("CurrentlyBlockedTasks")); completedTasks = Metrics.newGauge(factory.createMetricName("CompletedTasks"), new Gauge<Long>() { public Long value() { return executor.getCompletedTaskCount(); } }); pendingTasks = Metrics.newGauge(factory.createMetricName("PendingTasks"), new Gauge<Long>() { public Long value() { return executor.getTaskCount() - executor.getCompletedTaskCount(); } }); }
public CASClientRequestMetrics(String scope) { super(scope); contention = Metrics.newHistogram(factory.createMetricName("ContentionHistogram"), true); conditionNotMet = Metrics.newCounter(factory.createMetricName("ConditionNotMet")); unfinishedCommit = Metrics.newCounter(factory.createMetricName("UnfinishedCommit")); }
/** * * 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); } }
/** * * 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 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); } }
/** * Create LatencyMetrics with given group, type, prefix to append to each metric name, and scope. * * @param factory MetricName factory to use * @param namePrefix Prefix to append to each metric name */ public LatencyMetrics(MetricNameFactory factory, String namePrefix) { this.factory = factory; this.namePrefix = namePrefix; latency = Metrics.newTimer(factory.createMetricName(namePrefix + "Latency"), TimeUnit.MICROSECONDS, TimeUnit.SECONDS); totalLatency = Metrics.newCounter(factory.createMetricName(namePrefix + "TotalLatency")); }
private void runLoop(ReporterConfig config) throws Exception { Counter counter = Metrics.newCounter(getClass(), "counter"); Meter meter = Metrics.newMeter(getClass(), "meter", "foo", TimeUnit.SECONDS); config.enableConsole(); for (int i=0; i< loops; i++) { counter.inc(); meter.mark(); Thread.sleep(1000); log.debug("runLoop tick"); } log.info("Done with sample data loop"); }
public FileCacheMetrics() { hits = Metrics.newMeter(factory.createMetricName("Hits"), "hits", TimeUnit.SECONDS); requests = Metrics.newMeter(factory.createMetricName("Requests"), "requests", TimeUnit.SECONDS); hitRate = Metrics.newGauge(factory.createMetricName("HitRate"), new RatioGauge() { protected double getNumerator() { return hits.count(); } protected double getDenominator() { return requests.count(); } }); size = Metrics.newGauge(factory.createMetricName("Size"), new Gauge<Long>() { public Long value() { return FileCacheService.instance.sizeInBytes(); } }); } }
/** * * 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); } }
IndexingMetrics(int partition) { MetricName docsIndexedName = new MetricName(MetricsConstants.Domain, "meter", "docs-indexed", "indexer"); docsIndexedMetric = Metrics.newMeter(docsIndexedName, "indexing", TimeUnit.SECONDS); MetricName docsLeftoverName = new MetricName(MetricsConstants.Domain, "meter", "docs-leftover", "indexer"); docsLeftoverMetric = Metrics.newMeter(docsLeftoverName, "indexing", TimeUnit.SECONDS); MetricName flushTimeName = new MetricName(MetricsConstants.Domain, "histogram", "flush-time", "indexer"); flushTimeHistogram = Metrics.newHistogram(flushTimeName, false); } }
public FilebeatIngester(LogsIngester logsIngester, Supplier<Long> currentMillis) { this.logsIngester = logsIngester; this.received = Metrics.newCounter(new MetricName("logsharvesting", "", "filebeat-received")); this.malformed = Metrics.newCounter(new MetricName("logsharvesting", "", "filebeat-malformed")); this.drift = Metrics.newHistogram(new MetricName("logsharvesting", "", "filebeat-drift")); this.currentMillis = currentMillis; }
SHTimerMetric(TimeUnit durationUnit, TimeUnit rateUnit) { t = Metrics.newTimer(this.getClass(),"Timer",durationUnit, rateUnit); }
activeTasks = Metrics.newGauge(factory.createMetricName("ActiveTasks"), new Gauge<Integer>() { public Integer value() { return executor.getActiveCount(); pendingTasks = Metrics.newGauge(factory.createMetricName("PendingTasks"), new Gauge<Long>() { public Long value() { return executor.getPendingTasks(); totalBlocked = Metrics.newGauge(factory.createMetricName("TotalBlockedTasks"), new Gauge<Integer>() { public Integer value() { return executor.getTotalBlockedTasks(); currentBlocked = Metrics.newGauge(factory.createMetricName("CurrentlyBlockedTasks"), new Gauge<Long>() { public Long value() { return (long) executor.getCurrentlyBlockedTasks(); completedTasks = Metrics.newGauge(factory.createMetricName("CompletedTasks"), new Gauge<Long>() { public Long value() { return executor.getCompletedTasks();
/** * Create metrics for given connection pool. * * @param ip IP address to use for metrics label */ public ConnectionMetrics(NetEndpoint ip) { // ipv6 addresses will contain colons, which are invalid in a JMX ObjectName String address = ip.getHostAddress().replaceAll(":", "."); factory = new DefaultNameFactory("Connection", address); timeouts = Metrics.newMeter(factory.createMetricName("Timeouts"), "timeouts", TimeUnit.SECONDS); }
ReportingObjectQueueWrapper(ObjectQueue<T> backingQueue, String title) { this.addCounter = Metrics.newCounter(new MetricName("tape." + title, "", "add")); this.removeCounter = Metrics.newCounter(new MetricName("tape." + title, "", "remove")); this.peekCounter = Metrics.newCounter(new MetricName("tape." + title, "", "peek")); Metrics.newGauge(new MetricName("tape." + title, "", "size"), new Gauge<Integer>() { @Override public Integer value() { return backingQueue.size(); } }); this.backingQueue = backingQueue; }
/** * Constructor * * @param name String name * @param printPeriod how often to print */ public MetricsObserver(String name, int printPeriod) { TimeUnit durationUnit = TimeUnit.MICROSECONDS; TimeUnit rateUnit = TimeUnit.MILLISECONDS; this.printPeriod = printPeriod; readTimer = Metrics.newTimer(new MetricName(name, "", "reads"), durationUnit, rateUnit); readSuccessRatio = new CounterRatioGauge(Metrics.newCounter(new MetricName(name, "", "successes")), Metrics.newCounter(new MetricName(name, "", "-reads"))); parseTimer = Metrics.newTimer(new MetricName(name, "", "parses"), durationUnit, rateUnit); }