Java Code Examples for com.yammer.metrics.Metrics#newGauge()
The following examples show how to use
com.yammer.metrics.Metrics#newGauge() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FilterMetricPredicateTest.java From kafka-graphite with Apache License 2.0 | 6 votes |
@Test public void keepGaugesIfTheyThrowRuntimeExceptions() throws Exception { MetricPredicate predicate = new FilterMetricPredicate(); MetricName metricName = new MetricName("test", "test", "delete", "scope", "mBeanName"); Metric gauge = Metrics.newGauge(metricName, new Gauge<Long>() { @Override public Long value() { throw new RuntimeException("catch me if you can"); } }); assertTrue(predicate.matches(metricName, gauge)); assertTrue("The gauge should be there", Metrics.defaultRegistry().allMetrics().containsKey(metricName)); assertEquals(Metrics.defaultRegistry().allMetrics().get(metricName), gauge); }
Example 2
Source File: AbstractDistributedIndexServer.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
public AbstractDistributedIndexServer(ClusterStatus clusterStatus, Configuration configuration, String nodeName, String cluster) { _clusterStatus = clusterStatus; _configuration = configuration; _nodeName = nodeName; _cluster = cluster; MetricName tableCount = new MetricName(ORG_APACHE_BLUR, BLUR, TABLE_COUNT, _cluster); MetricName indexCount = new MetricName(ORG_APACHE_BLUR, BLUR, INDEX_COUNT, _cluster); MetricName segmentCount = new MetricName(ORG_APACHE_BLUR, BLUR, SEGMENT_COUNT, _cluster); MetricName indexMemoryUsage = new MetricName(ORG_APACHE_BLUR, BLUR, INDEX_MEMORY_USAGE, _cluster); MetricName recordCount = new MetricName(ORG_APACHE_BLUR, BLUR, RECORD_COUNT, _cluster); Metrics.newGauge(tableCount, new AtomicLongGauge(_tableCount)); Metrics.newGauge(indexCount, new AtomicLongGauge(_indexCount)); Metrics.newGauge(segmentCount, new AtomicLongGauge(_segmentCount)); Metrics.newGauge(indexMemoryUsage, new AtomicLongGauge(_indexMemoryUsage)); Metrics.newGauge(recordCount, new AtomicLongGauge(_recordCount)); }
Example 3
Source File: CQLMetrics.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public CQLMetrics() { regularStatementsExecuted = Metrics.newCounter(factory.createMetricName("RegularStatementsExecuted")); preparedStatementsExecuted = Metrics.newCounter(factory.createMetricName("PreparedStatementsExecuted")); preparedStatementsEvicted = Metrics.newCounter(factory.createMetricName("PreparedStatementsEvicted")); preparedStatementsCount = Metrics.newGauge(factory.createMetricName("PreparedStatementsCount"), new Gauge<Integer>() { public Integer value() { return QueryProcessor.preparedStatementsCount(); } }); preparedStatementsRatio = Metrics.newGauge(factory.createMetricName("PreparedStatementsRatio"), new RatioGauge() { public double getNumerator() { return preparedStatementsExecuted.count(); } public double getDenominator() { return regularStatementsExecuted.count() + preparedStatementsExecuted.count(); } }); }
Example 4
Source File: KeyspaceMetrics.java From stratio-cassandra with Apache License 2.0 | 6 votes |
/** * Creates a gauge that will sum the current value of a metric for all column families in this keyspace * @param name * @param MetricValue * @return Gauge>Long> that computes sum of MetricValue.getValue() */ private <T extends Number> Gauge<Long> createKeyspaceGauge(String name, final MetricValue extractor) { allMetrics.add(name); return Metrics.newGauge(factory.createMetricName(name), new Gauge<Long>() { public Long value() { long sum = 0; for (ColumnFamilyStore cf : keyspace.getColumnFamilyStores()) { sum += extractor.getValue(cf.metric); } return sum; } }); }
Example 5
Source File: FileCacheMetrics.java From stratio-cassandra with Apache License 2.0 | 6 votes |
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(); } }); }
Example 6
Source File: DeepPagingCache.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
public DeepPagingCache(long maxEntriesForDeepPaging) { _hits = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, DEEP_PAGING_CACHE, HIT), HIT, TimeUnit.SECONDS); _misses = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, DEEP_PAGING_CACHE, MISS), MISS, TimeUnit.SECONDS); _evictions = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, DEEP_PAGING_CACHE, EVICTION), EVICTION, TimeUnit.SECONDS); _lruCache = new ConcurrentLinkedHashMap.Builder<DeepPageKeyPlusPosition, DeepPageContainer>() .maximumWeightedCapacity(maxEntriesForDeepPaging) .listener(new EvictionListener<DeepPageKeyPlusPosition, DeepPageContainer>() { @Override public void onEviction(DeepPageKeyPlusPosition key, DeepPageContainer value) { _positionCache.remove(key); _evictions.mark(); } }).build(); Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, DEEP_PAGING_CACHE, SIZE), new Gauge<Long>() { @Override public Long value() { return _lruCache.weightedSize(); } }); _positionCache = new ConcurrentSkipListMap<DeepPageKeyPlusPosition, DeepPageContainer>(); }
Example 7
Source File: ClientMetrics.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public void addCounter(String name, final Callable<Integer> provider) { Metrics.newGauge(factory.createMetricName(name), new Gauge<Integer>() { public Integer value() { try { return provider.call(); } catch (Exception e) { throw new RuntimeException(e); } } }); }
Example 8
Source File: ColumnFamilyMetrics.java From stratio-cassandra with Apache License 2.0 | 6 votes |
/** * Creates a counter that will also have a global counter thats the sum of all counters across * different column families */ protected Counter createColumnFamilyCounter(final String name) { Counter cfCounter = Metrics.newCounter(factory.createMetricName(name)); if (register(name, cfCounter)) { Metrics.newGauge(globalNameFactory.createMetricName(name), new Gauge<Long>() { public Long value() { long total = 0; for (Metric cfGauge : allColumnFamilyMetrics.get(name)) { total += ((Counter) cfGauge).count(); } return total; } }); } return cfCounter; }
Example 9
Source File: ColumnFamilyMetrics.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * Create a gauge that will be part of a merged version of all column families. The global gauge * is defined as the globalGauge parameter */ protected <G,T> Gauge<T> createColumnFamilyGauge(String name, Gauge<T> gauge, Gauge<G> globalGauge) { Gauge<T> cfGauge = Metrics.newGauge(factory.createMetricName(name), gauge); if (register(name, cfGauge)) { Metrics.newGauge(globalNameFactory.createMetricName(name), globalGauge); } return cfGauge; }
Example 10
Source File: SharedMergeScheduler.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
public SharedMergeScheduler(int threads, long smallMergeThreshold) { MetricName mergeSmallQueueDepth = new MetricName(ORG_APACHE_BLUR, LUCENE, SMALL_QUEUE_DEPTH); MetricName mergeSmallQueueDepthInBytes = new MetricName(ORG_APACHE_BLUR, LUCENE, SMALL_QUEUE_DEPTH_IN_BYTES); MetricName mergeLargeQueueDepth = new MetricName(ORG_APACHE_BLUR, LUCENE, LARGE_QUEUE_DEPTH); MetricName mergeLargeQueueDepthInBytes = new MetricName(ORG_APACHE_BLUR, LUCENE, LARGE_QUEUE_DEPTH_IN_BYTES); _smallMergeThreshold = smallMergeThreshold; _smallMergeService = Executors.newThreadPool(SHARED_MERGE_SCHEDULER_PREFIX + "-small", threads, false); _largeMergeService = Executors.newThreadPool(SHARED_MERGE_SCHEDULER_PREFIX + "-large", threads, false); for (int i = 0; i < threads; i++) { _smallMergeService.submit(getMergerRunnable(_smallMergeQueue)); _largeMergeService.submit(getMergerRunnable(_largeMergeQueue)); } Metrics.newGauge(mergeSmallQueueDepth, new Gauge<Long>() { @Override public Long value() { return (long) _smallMergeQueue.size(); } }); Metrics.newGauge(mergeSmallQueueDepthInBytes, new Gauge<Long>() { @Override public Long value() { return getSizeInBytes(_smallMergeQueue); } }); Metrics.newGauge(mergeLargeQueueDepth, new Gauge<Long>() { @Override public Long value() { return (long) _largeMergeQueue.size(); } }); Metrics.newGauge(mergeLargeQueueDepthInBytes, new Gauge<Long>() { @Override public Long value() { return getSizeInBytes(_largeMergeQueue); } }); }
Example 11
Source File: FilterMetricPredicateTest.java From kafka-graphite with Apache License 2.0 | 5 votes |
@Test public void deleteGaugesIfTheyThrowNoSuchElementException() throws Exception { MetricPredicate predicate = new FilterMetricPredicate(); MetricName metricNameToBeDeleted = new MetricName("test", "test", "delete", "scope", "mBeanName"); Metric gaugeToBeDeleted = Metrics.newGauge(metricNameToBeDeleted, new Gauge<Long>() { @Override public Long value() { throw new NoSuchElementException("catch me if you can - i'm the the same as in KAFKA-1866"); } }); MetricName metricNameToStay = new MetricName("stay", "stay", "stay", "scope", "stay:mBeanName"); Metric gaugeToStay = Metrics.newGauge(metricNameToStay, new Gauge<Long>() { @Override public Long value() { return 42L; } }); assertFalse(predicate.matches(metricNameToBeDeleted, gaugeToBeDeleted)); assertTrue(predicate.matches(metricNameToStay, gaugeToStay)); assertFalse("The gauge should be deleted", Metrics.defaultRegistry().allMetrics().containsKey(metricNameToBeDeleted)); assertTrue("The gauge should be there", Metrics.defaultRegistry().allMetrics().containsKey(metricNameToStay)); assertEquals(Metrics.defaultRegistry().allMetrics().get(metricNameToStay), gaugeToStay); }
Example 12
Source File: ShardServerEventHandler.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
public ShardServerEventHandler() { Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, BLUR, "Connections"), new Gauge<Long>() { @Override public Long value() { return null; } }); _connectionMeter = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, BLUR, "Connections/s"), "Connections/s", TimeUnit.SECONDS); }
Example 13
Source File: ByteArrayPrimitiveFactory.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
public ByteArrayPrimitiveFactory(BlurConfiguration configuration) { super(configuration); Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, FST, SIZE), new Gauge<Long>() { @Override public Long value() { return _size.get(); } }); }
Example 14
Source File: CacheMetrics.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** * Create metrics for given cache. * * @param type Type of Cache to identify metrics. * @param cache Cache to measure metrics */ public CacheMetrics(String type, final ICache cache) { MetricNameFactory factory = new DefaultNameFactory("Cache", type); capacity = Metrics.newGauge(factory.createMetricName("Capacity"), new Gauge<Long>() { public Long value() { return cache.capacity(); } }); 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 cache.weightedSize(); } }); entries = Metrics.newGauge(factory.createMetricName("Entries"), new Gauge<Integer>() { public Integer value() { return cache.size(); } }); }
Example 15
Source File: BaseCache.java From incubator-retired-blur with Apache License 2.0 | 4 votes |
public BaseCache(long totalNumberOfBytes, Size fileBufferSize, Size cacheBlockSize, Size directLocalCacheRefLimit, FileNameFilter readFilter, FileNameFilter writeFilter, Quiet quiet, BaseCacheValueBufferPool cacheValueBufferPool) { _cacheMap = new ConcurrentLinkedHashMap.Builder<CacheKey, CacheValue>().weigher(new BaseCacheWeigher()) .maximumWeightedCapacity(totalNumberOfBytes).listener(new BaseCacheEvictionListener()).build(); _fileBufferSize = fileBufferSize; _readFilter = readFilter; _writeFilter = writeFilter; _cacheBlockSize = cacheBlockSize; _directLocalCacheRefLimit = directLocalCacheRefLimit; _quiet = quiet; _hits = MeterWrapper.wrap(Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, CACHE, HIT), HIT, TimeUnit.SECONDS)); _misses = MeterWrapper.wrap(Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, CACHE, MISS), MISS, TimeUnit.SECONDS)); _evictions = MeterWrapper.wrap(Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, CACHE, EVICTION), EVICTION, TimeUnit.SECONDS)); _removals = MeterWrapper.wrap(Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, CACHE, REMOVAL), REMOVAL, TimeUnit.SECONDS)); _cacheValueBufferPool = cacheValueBufferPool; Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, CACHE, ENTRIES), new Gauge<Long>() { @Override public Long value() { return (long) getEntryCount(); } }); Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, CACHE, SIZE), new Gauge<Long>() { @Override public Long value() { return getWeightedSize(); } }); _oldFileDaemonThread = new Thread(new Runnable() { @Override public void run() { while (_running.get()) { cleanupOldFiles(); try { Thread.sleep(_1_MINUTE); } catch (InterruptedException e) { return; } } } }); _oldFileDaemonThread.setDaemon(true); _oldFileDaemonThread.setName("BaseCacheOldFileCleanup"); _oldFileDaemonThread.setPriority(Thread.MIN_PRIORITY); _oldFileDaemonThread.start(); }
Example 16
Source File: ConnectionMetrics.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** * Create metrics for given connection pool. * * @param ip IP address to use for metrics label * @param connectionPool Connection pool */ public ConnectionMetrics(InetAddress ip, final OutboundTcpConnectionPool connectionPool) { // ipv6 addresses will contain colons, which are invalid in a JMX ObjectName address = ip.getHostAddress().replace(':', '.'); factory = new DefaultNameFactory("Connection", address); commandPendingTasks = Metrics.newGauge(factory.createMetricName("CommandPendingTasks"), new Gauge<Integer>() { public Integer value() { return connectionPool.cmdCon.getPendingMessages(); } }); commandCompletedTasks = Metrics.newGauge(factory.createMetricName("CommandCompletedTasks"), new Gauge<Long>() { public Long value() { return connectionPool.cmdCon.getCompletedMesssages(); } }); commandDroppedTasks = Metrics.newGauge(factory.createMetricName("CommandDroppedTasks"), new Gauge<Long>() { public Long value() { return connectionPool.cmdCon.getDroppedMessages(); } }); responsePendingTasks = Metrics.newGauge(factory.createMetricName("ResponsePendingTasks"), new Gauge<Integer>() { public Integer value() { return connectionPool.ackCon.getPendingMessages(); } }); responseCompletedTasks = Metrics.newGauge(factory.createMetricName("ResponseCompletedTasks"), new Gauge<Long>() { public Long value() { return connectionPool.ackCon.getCompletedMesssages(); } }); timeouts = Metrics.newMeter(factory.createMetricName("Timeouts"), "timeouts", TimeUnit.SECONDS); }
Example 17
Source File: SEPMetrics.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** * Create metrics for the given LowSignalExecutor. * * @param executor Thread pool * @param path Type of thread pool * @param poolName Name of thread pool to identify metrics */ public SEPMetrics(final SEPExecutor 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(); } }); 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(); } }); maxPoolSize = Metrics.newGauge(factory.createMetricName("MaxPoolSize"), new Gauge<Integer>() { public Integer value() { return executor.maxWorkers; } }); }
Example 18
Source File: ThriftServer.java From incubator-retired-blur with Apache License 2.0 | 4 votes |
public static void setupJvmMetrics() { final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, SYSTEM, LOAD_AVERAGE), new Gauge<Double>() { @Override public Double value() { return operatingSystemMXBean.getSystemLoadAverage(); } }); Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, JVM, HEAP_USED), new Gauge<Long>() { @Override public Long value() { MemoryUsage usage = memoryMXBean.getHeapMemoryUsage(); return usage.getUsed(); } }); Method processCpuTimeMethod = null; for (Method method : operatingSystemMXBean.getClass().getDeclaredMethods()) { if (method.getName().equals("getProcessCpuTime")) { method.setAccessible(true); processCpuTimeMethod = method; } } final double availableProcessors = operatingSystemMXBean.getAvailableProcessors(); if (processCpuTimeMethod != null) { final Method pctm = processCpuTimeMethod; Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, JVM, CPU_USED), new Gauge<Double>() { private long start = System.nanoTime(); private long lastCpuTime = getProcessCputTime(pctm, operatingSystemMXBean); @Override public Double value() { long now = System.nanoTime(); long cpuTime = getProcessCputTime(pctm, operatingSystemMXBean); long time = now - start; long processTime = cpuTime - lastCpuTime; try { return ((processTime / (double) time) / availableProcessors) * 100.0; } finally { lastCpuTime = cpuTime; start = System.nanoTime(); } } }); } }
Example 19
Source File: BlockCache.java From incubator-retired-blur with Apache License 2.0 | 4 votes |
public BlockCache(boolean directAllocation, long totalMemory, int slabSize) { _numberOfBlocksPerSlab = slabSize / _blockSize; _numberOfSlabs = (int) (totalMemory / slabSize); _directAllocation = directAllocation; _slabs = new ByteBuffer[_numberOfSlabs]; _locks = new BlockLocks[_numberOfSlabs]; _lockCounters = new AtomicInteger[_numberOfSlabs]; _maxEntries = (_numberOfBlocksPerSlab * _numberOfSlabs) - 1; for (int i = 0; i < _numberOfSlabs; i++) { if (!lazy) { if (_directAllocation) { _slabs[i] = ByteBuffer.allocateDirect(_numberOfBlocksPerSlab * _blockSize); } else { _slabs[i] = ByteBuffer.allocate(_numberOfBlocksPerSlab * _blockSize); } } _locks[i] = new BlockLocks(_numberOfBlocksPerSlab); _lockCounters[i] = new AtomicInteger(); } evictions = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, CACHE, EVICTION), EVICTION, TimeUnit.SECONDS); Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, CACHE, ENTRIES), new Gauge<Long>() { @Override public Long value() { return (long) getSize(); } }); Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, CACHE, SIZE), new Gauge<Long>() { @Override public Long value() { return ((long) getSize()) * (long) _8K; } }); EvictionListener<BlockCacheKey, BlockCacheLocation> listener = new EvictionListener<BlockCacheKey, BlockCacheLocation>() { @Override public void onEviction(BlockCacheKey key, BlockCacheLocation location) { releaseLocation(location); evictions.mark(); } }; _cache = new ConcurrentLinkedHashMap.Builder<BlockCacheKey, BlockCacheLocation>() .maximumWeightedCapacity(_maxEntries).listener(listener).build(); }
Example 20
Source File: MetricsHelper.java From incubator-pinot with Apache License 2.0 | 3 votes |
/** * * 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); } }