Upgrade metrics library and remove depricated metrics

Patch by tjake; reviewed by aleksey for CASSANDRA-5657
This commit is contained in:
T Jake Luciani 2015-01-05 09:34:08 -05:00
parent bbb1592e84
commit 8896a70b01
82 changed files with 1534 additions and 1748 deletions

View File

@ -1,4 +1,5 @@
3.0
* Upgrade Metrics library and remove depricated metrics (CASSANDRA-5657)
* Serializing Row cache alternative, fully off heap (CASSANDRA-7438)
* Duplicate rows returned when in clause has repeated values (CASSANDRA-6707)
* Make CassandraException unchecked, extend RuntimeException (CASSANDRA-8560)

View File

@ -368,7 +368,7 @@
<dependency groupId="org.apache.cassandra" artifactId="cassandra-all" version="${version}" />
<dependency groupId="org.apache.cassandra" artifactId="cassandra-thrift" version="${version}" />
<dependency groupId="com.yammer.metrics" artifactId="metrics-core" version="2.2.0" />
<dependency groupId="io.dropwizard.metrics" artifactId="metrics-core" version="3.1.0" />
<dependency groupId="com.addthis.metrics" artifactId="reporter-config" version="2.1.0" />
<dependency groupId="org.mindrot" artifactId="jbcrypt" version="0.3m" />
<dependency groupId="io.airlift" artifactId="airline" version="0.6" />
@ -483,7 +483,7 @@
<dependency groupId="com.boundary" artifactId="high-scale-lib"/>
<dependency groupId="org.yaml" artifactId="snakeyaml"/>
<dependency groupId="org.mindrot" artifactId="jbcrypt"/>
<dependency groupId="com.yammer.metrics" artifactId="metrics-core"/>
<dependency groupId="io.dropwizard.metrics" artifactId="metrics-core"/>
<dependency groupId="com.addthis.metrics" artifactId="reporter-config"/>
<dependency groupId="com.thinkaurelius.thrift" artifactId="thrift-server" version="0.3.5"/>
<dependency groupId="com.clearspring.analytics" artifactId="stream" version="2.5.2" />

Binary file not shown.

BIN
lib/metrics-core-3.1.0.jar Normal file

Binary file not shown.

View File

@ -107,12 +107,12 @@ public class JMXEnabledScheduledThreadPoolExecutor extends DebuggableScheduledTh
public int getTotalBlockedTasks()
{
return (int) metrics.totalBlocked.count();
return (int) metrics.totalBlocked.getCount();
}
public int getCurrentlyBlockedTasks()
{
return (int) metrics.currentBlocked.count();
return (int) metrics.currentBlocked.getCount();
}
public int getCoreThreads()

View File

@ -1,113 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.concurrent;
import java.lang.management.ManagementFactory;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.apache.cassandra.metrics.SEPMetrics;
public class JMXEnabledSharedExecutorPool extends SharedExecutorPool
{
public static final JMXEnabledSharedExecutorPool SHARED = new JMXEnabledSharedExecutorPool("SharedPool");
public JMXEnabledSharedExecutorPool(String poolName)
{
super(poolName);
}
public interface JMXEnabledSEPExecutorMBean extends JMXEnabledThreadPoolExecutorMBean
{
}
public class JMXEnabledSEPExecutor extends SEPExecutor implements JMXEnabledSEPExecutorMBean
{
private final SEPMetrics metrics;
private final String mbeanName;
public JMXEnabledSEPExecutor(int poolSize, int maxQueuedLength, String name, String jmxPath)
{
super(JMXEnabledSharedExecutorPool.this, poolSize, maxQueuedLength);
metrics = new SEPMetrics(this, jmxPath, name);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbeanName = "org.apache.cassandra." + jmxPath + ":type=" + name;
try
{
mbs.registerMBean(this, new ObjectName(mbeanName));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
private void unregisterMBean()
{
try
{
ManagementFactory.getPlatformMBeanServer().unregisterMBean(new ObjectName(mbeanName));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
// release metrics
metrics.release();
}
@Override
public synchronized void shutdown()
{
// synchronized, because there is no way to access super.mainLock, which would be
// the preferred way to make this threadsafe
if (!isShutdown())
{
unregisterMBean();
}
super.shutdown();
}
public int getCoreThreads()
{
return 0;
}
public void setCoreThreads(int number)
{
throw new UnsupportedOperationException();
}
public void setMaximumThreads(int number)
{
throw new UnsupportedOperationException();
}
}
public TracingAwareExecutorService newExecutor(int maxConcurrency, int maxQueuedTasks, String name, String jmxPath)
{
JMXEnabledSEPExecutor executor = new JMXEnabledSEPExecutor(maxConcurrency, maxQueuedTasks, name, jmxPath);
executors.add(executor);
return executor;
}
}

View File

@ -36,7 +36,7 @@ import org.apache.cassandra.metrics.ThreadPoolMetrics;
public class JMXEnabledThreadPoolExecutor extends DebuggableThreadPoolExecutor implements JMXEnabledThreadPoolExecutorMBean
{
private final String mbeanName;
private final ThreadPoolMetrics metrics;
public final ThreadPoolMetrics metrics;
public JMXEnabledThreadPoolExecutor(String threadPoolName)
{
@ -132,30 +132,17 @@ public class JMXEnabledThreadPoolExecutor extends DebuggableThreadPoolExecutor i
return super.shutdownNow();
}
/**
* Get the number of completed tasks
*/
public long getCompletedTasks()
{
return getCompletedTaskCount();
}
/**
* Get the number of tasks waiting to be executed
*/
public long getPendingTasks()
{
return getTaskCount() - getCompletedTaskCount();
}
public int getTotalBlockedTasks()
{
return (int) metrics.totalBlocked.count();
return (int) metrics.totalBlocked.getCount();
}
public int getCurrentlyBlockedTasks()
{
return (int) metrics.currentBlocked.count();
return (int) metrics.currentBlocked.getCount();
}
public int getCoreThreads()

View File

@ -17,24 +17,9 @@
*/
package org.apache.cassandra.concurrent;
/**
* @see org.apache.cassandra.metrics.ThreadPoolMetrics
*/
@Deprecated
public interface JMXEnabledThreadPoolExecutorMBean extends IExecutorMBean
public interface JMXEnabledThreadPoolExecutorMBean
{
/**
* Get the number of tasks that had blocked before being accepted (or
* rejected).
*/
public int getTotalBlockedTasks();
/**
* Get the number of tasks currently blocked, waiting to be accepted by
* the executor (because all threads are busy and the backing queue is full).
*/
public int getCurrentlyBlockedTasks();
/**
* Returns core pool size of thread pool.
*/

View File

@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.cassandra.metrics.SEPMetrics;
import org.apache.cassandra.utils.concurrent.SimpleCondition;
import org.apache.cassandra.utils.concurrent.WaitQueue;
@ -35,6 +36,7 @@ public class SEPExecutor extends AbstractTracingAwareExecutorService
public final int maxWorkers;
private final int maxTasksQueued;
private final SEPMetrics metrics;
// stores both a set of work permits and task permits:
// bottom 32 bits are number of queued tasks, in the range [0..maxTasksQueued] (initially 0)
@ -43,8 +45,6 @@ public class SEPExecutor extends AbstractTracingAwareExecutorService
// producers wait on this when there is no room on the queue
private final WaitQueue hasRoom = new WaitQueue();
private final AtomicLong totalBlocked = new AtomicLong();
private final AtomicInteger currentlyBlocked = new AtomicInteger();
private final AtomicLong completedTasks = new AtomicLong();
volatile boolean shuttingDown = false;
@ -53,12 +53,13 @@ public class SEPExecutor extends AbstractTracingAwareExecutorService
// TODO: see if other queue implementations might improve throughput
protected final ConcurrentLinkedQueue<FutureTask<?>> tasks = new ConcurrentLinkedQueue<>();
SEPExecutor(SharedExecutorPool pool, int maxWorkers, int maxTasksQueued)
SEPExecutor(SharedExecutorPool pool, int maxWorkers, int maxTasksQueued, String jmxPath, String name)
{
this.pool = pool;
this.maxWorkers = maxWorkers;
this.maxTasksQueued = maxTasksQueued;
this.permits.set(combine(0, maxWorkers));
this.metrics = new SEPMetrics(this, jmxPath, name);
}
protected void onCompletion()
@ -116,10 +117,11 @@ public class SEPExecutor extends AbstractTracingAwareExecutorService
// if we're blocking, we might as well directly schedule a worker if we aren't already at max
if (takeWorkPermit(true))
pool.schedule(new Work(this));
totalBlocked.incrementAndGet();
currentlyBlocked.incrementAndGet();
metrics.totalBlocked.inc();
metrics.currentBlocked.inc();
s.awaitUninterruptibly();
currentlyBlocked.decrementAndGet();
metrics.currentBlocked.dec();
}
else // don't propagate our signal when we cancel, just cancel
s.cancel();
@ -207,6 +209,9 @@ public class SEPExecutor extends AbstractTracingAwareExecutorService
pool.executors.remove(this);
if (getActiveCount() == 0)
shutdown.signalAll();
// release metrics
metrics.release();
}
public synchronized List<Runnable> shutdownNow()
@ -249,21 +254,6 @@ public class SEPExecutor extends AbstractTracingAwareExecutorService
return maxWorkers - workPermits(permits.get());
}
public int getTotalBlockedTasks()
{
return (int) totalBlocked.get();
}
public int getMaximumThreads()
{
return maxWorkers;
}
public int getCurrentlyBlockedTasks()
{
return currentlyBlocked.get();
}
private static int taskPermits(long both)
{
return (int) both;

View File

@ -54,6 +54,8 @@ import static org.apache.cassandra.concurrent.SEPWorker.Work;
public class SharedExecutorPool
{
public static final SharedExecutorPool SHARED = new SharedExecutorPool("SharedPool");
// the name assigned to workers in the pool, and the id suffix
final String poolName;
final AtomicLong workerId = new AtomicLong();
@ -100,4 +102,11 @@ public class SharedExecutorPool
if (current == 0 && spinningCount.compareAndSet(0, 1))
schedule(Work.SPINNING);
}
public TracingAwareExecutorService newExecutor(int maxConcurrency, int maxQueuedTasks, String jmxPath, String name)
{
SEPExecutor executor = new SEPExecutor(this, maxConcurrency, maxQueuedTasks, jmxPath, name);
executors.add(executor);
return executor;
}
}

View File

@ -17,6 +17,11 @@
*/
package org.apache.cassandra.concurrent;
import java.util.Arrays;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
public enum Stage
{
READ,
@ -31,6 +36,17 @@ public enum Stage
INTERNAL_RESPONSE,
READ_REPAIR;
public static Iterable<Stage> jmxEnabledStages()
{
return Iterables.filter(Arrays.asList(values()), new Predicate<Stage>()
{
public boolean apply(Stage stage)
{
return stage != TRACING;
}
});
}
public String getJmxType()
{
switch (this)

View File

@ -89,7 +89,7 @@ public class StageManager
private static TracingAwareExecutorService multiThreadedLowSignalStage(Stage stage, int numThreads)
{
return JMXEnabledSharedExecutorPool.SHARED.newExecutor(numThreads, Integer.MAX_VALUE, stage.getJmxName(), stage.getJmxType());
return SharedExecutorPool.SHARED.newExecutor(numThreads, Integer.MAX_VALUE, stage.getJmxType(), stage.getJmxName());
}
/**

View File

@ -365,7 +365,6 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
{
case PERCENTILE:
// get percentile in nanos
assert metric.coordinatorReadLatency.durationUnit() == TimeUnit.MICROSECONDS;
sampleLatencyNanos = (long) (metric.coordinatorReadLatency.getSnapshot().getValue(retryPolicy.value) * 1000d);
break;
case CUSTOM:
@ -425,25 +424,6 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
metric.release();
}
public long getMinRowSize()
{
return metric.minRowSize.value();
}
public long getMaxRowSize()
{
return metric.maxRowSize.value();
}
public long getMeanRowSize()
{
return metric.meanRowSize.value();
}
public int getMeanColumns()
{
return data.getMeanColumns();
}
public static ColumnFamilyStore createColumnFamilyStore(Keyspace keyspace, String columnFamily, boolean loadSSTables)
{
@ -1426,20 +1406,8 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
return valid;
}
public long getMemtableColumnsCount()
{
return metric.memtableColumnsCount.value();
}
public long getMemtableDataSize()
{
return metric.memtableOnHeapSize.value();
}
public int getMemtableSwitchCount()
{
return (int) metric.memtableSwitchCount.count();
}
/**
* Package protected for access from the CompactionManager.
@ -1459,71 +1427,6 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
return data.getUncompactingSSTables();
}
public long[] getRecentSSTablesPerReadHistogram()
{
return metric.recentSSTablesPerRead.getBuckets(true);
}
public long[] getSSTablesPerReadHistogram()
{
return metric.sstablesPerRead.getBuckets(false);
}
public long getReadCount()
{
return metric.readLatency.latency.count();
}
public double getRecentReadLatencyMicros()
{
return metric.readLatency.getRecentLatency();
}
public long[] getLifetimeReadLatencyHistogramMicros()
{
return metric.readLatency.totalLatencyHistogram.getBuckets(false);
}
public long[] getRecentReadLatencyHistogramMicros()
{
return metric.readLatency.recentLatencyHistogram.getBuckets(true);
}
public long getTotalReadLatencyMicros()
{
return metric.readLatency.totalLatency.count();
}
public int getPendingTasks()
{
return (int) metric.pendingFlushes.count();
}
public long getWriteCount()
{
return metric.writeLatency.latency.count();
}
public long getTotalWriteLatencyMicros()
{
return metric.writeLatency.totalLatency.count();
}
public double getRecentWriteLatencyMicros()
{
return metric.writeLatency.getRecentLatency();
}
public long[] getLifetimeWriteLatencyHistogramMicros()
{
return metric.writeLatency.totalLatencyHistogram.getBuckets(false);
}
public long[] getRecentWriteLatencyHistogramMicros()
{
return metric.writeLatency.recentLatencyHistogram.getBuckets(true);
}
public ColumnFamily getColumnFamily(DecoratedKey key,
Composite start,
Composite finish,
@ -2328,19 +2231,9 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
return directories.getSnapshotDetails();
}
public long getTotalDiskSpaceUsed()
public boolean hasUnreclaimedSpace()
{
return metric.totalDiskSpaceUsed.count();
}
public long getLiveDiskSpaceUsed()
{
return metric.liveDiskSpaceUsed.count();
}
public int getLiveSSTableCount()
{
return metric.liveSSTableCount.value();
return metric.liveDiskSpaceUsed.getCount() < metric.totalDiskSpaceUsed.getCount();
}
/**
@ -2613,45 +2506,6 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
return runWithCompactionsDisabled(callable, false);
}
public long getBloomFilterFalsePositives()
{
return metric.bloomFilterFalsePositives.value();
}
public long getRecentBloomFilterFalsePositives()
{
return metric.recentBloomFilterFalsePositives.value();
}
public double getBloomFilterFalseRatio()
{
return metric.bloomFilterFalseRatio.value();
}
public double getRecentBloomFilterFalseRatio()
{
return metric.recentBloomFilterFalseRatio.value();
}
public long getBloomFilterDiskSpaceUsed()
{
return metric.bloomFilterDiskSpaceUsed.value();
}
public long getBloomFilterOffHeapMemoryUsed()
{
return metric.bloomFilterOffHeapMemoryUsed.value();
}
public long getIndexSummaryOffHeapMemoryUsed()
{
return metric.indexSummaryOffHeapMemoryUsed.value();
}
public long getCompressionMetadataOffHeapMemoryUsed()
{
return metric.compressionMetadataOffHeapMemoryUsed.value();
}
@Override
public String toString()
@ -2748,38 +2602,18 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
"is deprecated, set the compaction strategy option 'enabled' to 'false' instead or use the nodetool command 'disableautocompaction'.");
}
public double getTombstonesPerSlice()
{
return metric.tombstoneScannedHistogram.cf.getSnapshot().getMedian();
}
public double getLiveCellsPerSlice()
{
return metric.liveScannedHistogram.cf.getSnapshot().getMedian();
}
// End JMX get/set.
public int getMeanColumns()
{
return data.getMeanColumns();
}
public long estimateKeys()
{
return data.estimatedKeys();
}
public long[] getEstimatedRowSizeHistogram()
{
return metric.estimatedRowSizeHistogram.value();
}
public long[] getEstimatedColumnCountHistogram()
{
return metric.estimatedColumnCountHistogram.value();
}
public double getCompressionRatio()
{
return metric.compressionRatio.value();
}
/** true if this CFS contains secondary index data */
public boolean isIndex()
{

View File

@ -34,222 +34,11 @@ public interface ColumnFamilyStoreMBean
*/
public String getColumnFamilyName();
/**
* Returns the total amount of data stored in the memtable, including
* column related overhead.
*
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#memtableOnHeapSize
* @return The size in bytes.
* @deprecated
*/
@Deprecated
public long getMemtableDataSize();
/**
* Returns the total number of columns present in the memtable.
*
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#memtableColumnsCount
* @return The number of columns.
*/
@Deprecated
public long getMemtableColumnsCount();
/**
* Returns the number of times that a flush has resulted in the
* memtable being switched out.
*
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#memtableSwitchCount
* @return the number of memtable switches
*/
@Deprecated
public int getMemtableSwitchCount();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#recentSSTablesPerRead
* @return a histogram of the number of sstable data files accessed per read: reading this property resets it
*/
@Deprecated
public long[] getRecentSSTablesPerReadHistogram();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#sstablesPerReadHistogram
* @return a histogram of the number of sstable data files accessed per read
*/
@Deprecated
public long[] getSSTablesPerReadHistogram();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#readLatency
* @return the number of read operations on this column family
*/
@Deprecated
public long getReadCount();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#readLatency
* @return total read latency (divide by getReadCount() for average)
*/
@Deprecated
public long getTotalReadLatencyMicros();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#readLatency
* @return an array representing the latency histogram
*/
@Deprecated
public long[] getLifetimeReadLatencyHistogramMicros();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#readLatency
* @return an array representing the latency histogram
*/
@Deprecated
public long[] getRecentReadLatencyHistogramMicros();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#readLatency
* @return average latency per read operation since the last call
*/
@Deprecated
public double getRecentReadLatencyMicros();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#writeLatency
* @return the number of write operations on this column family
*/
@Deprecated
public long getWriteCount();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#writeLatency
* @return total write latency (divide by getReadCount() for average)
*/
@Deprecated
public long getTotalWriteLatencyMicros();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#writeLatency
* @return an array representing the latency histogram
*/
@Deprecated
public long[] getLifetimeWriteLatencyHistogramMicros();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#writeLatency
* @return an array representing the latency histogram
*/
@Deprecated
public long[] getRecentWriteLatencyHistogramMicros();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#writeLatency
* @return average latency per write operation since the last call
*/
@Deprecated
public double getRecentWriteLatencyMicros();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#pendingFlushes
* @return the estimated number of tasks pending for this column family
*/
@Deprecated
public int getPendingTasks();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#liveSSTableCount
* @return the number of SSTables on disk for this CF
*/
@Deprecated
public int getLiveSSTableCount();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#liveDiskSpaceUsed
* @return disk space used by SSTables belonging to this CF
*/
@Deprecated
public long getLiveDiskSpaceUsed();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#totalDiskSpaceUsed
* @return total disk space used by SSTables belonging to this CF, including obsolete ones waiting to be GC'd
*/
@Deprecated
public long getTotalDiskSpaceUsed();
/**
* force a major compaction of this column family
*/
public void forceMajorCompaction() throws ExecutionException, InterruptedException;
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#minRowSize
* @return the size of the smallest compacted row
*/
@Deprecated
public long getMinRowSize();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#maxRowSize
* @return the size of the largest compacted row
*/
@Deprecated
public long getMaxRowSize();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#meanRowSize
* @return the average row size across all the sstables
*/
@Deprecated
public long getMeanRowSize();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#bloomFilterFalsePositives
*/
@Deprecated
public long getBloomFilterFalsePositives();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#recentBloomFilterFalsePositives
*/
@Deprecated
public long getRecentBloomFilterFalsePositives();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#bloomFilterFalseRatio
*/
@Deprecated
public double getBloomFilterFalseRatio();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#recentBloomFilterFalseRatio
*/
@Deprecated
public double getRecentBloomFilterFalseRatio();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#bloomFilterDiskSpaceUsed
*/
@Deprecated
public long getBloomFilterDiskSpaceUsed();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#bloomFilterOffHeapMemoryUsed
*/
@Deprecated
public long getBloomFilterOffHeapMemoryUsed();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#indexSummaryOffHeapMemoryUsed
*/
@Deprecated
public long getIndexSummaryOffHeapMemoryUsed();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#compressionMetadataOffHeapMemoryUsed
*/
@Deprecated
public long getCompressionMetadataOffHeapMemoryUsed();
/**
* Gets the minimum number of sstables in queue before compaction kicks off
*/
@ -304,31 +93,8 @@ public interface ColumnFamilyStoreMBean
public boolean isAutoCompactionDisabled();
/** Number of tombstoned cells retreived during the last slicequery */
@Deprecated
public double getTombstonesPerSlice();
/** Number of live cells retreived during the last slicequery */
@Deprecated
public double getLiveCellsPerSlice();
public long estimateKeys();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#estimatedRowSizeHistogram
*/
@Deprecated
public long[] getEstimatedRowSizeHistogram();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#estimatedColumnCountHistogram
*/
@Deprecated
public long[] getEstimatedColumnCountHistogram();
/**
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#compressionRatio
*/
@Deprecated
public double getCompressionRatio();
/**
* Returns a list of the names of the built column indexes for current store

View File

@ -482,7 +482,7 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean
if (meanColumnCount <= 0)
return PAGE_SIZE;
int averageColumnSize = (int) (hintStore.getMeanRowSize() / meanColumnCount);
int averageColumnSize = (int) (hintStore.metric.meanRowSize.getValue() / meanColumnCount);
if (averageColumnSize <= 0)
return PAGE_SIZE;

View File

@ -291,26 +291,6 @@ public class CommitLog implements CommitLogMBean
}
}
@Override
public long getCompletedTasks()
{
return metrics.completedTasks.value();
}
@Override
public long getPendingTasks()
{
return metrics.pendingTasks.value();
}
/**
* @return the total size occupied by commitlog segments expressed in bytes. (used by MBean)
*/
public long getTotalCommitlogSize()
{
return metrics.totalCommitLogSize.value();
}
public List<String> getActiveSegmentNames()
{
List<String> segmentNames = new ArrayList<>();

View File

@ -23,27 +23,6 @@ import java.util.List;
public interface CommitLogMBean
{
/**
* Get the number of completed tasks
* @see org.apache.cassandra.metrics.CommitLogMetrics#completedTasks
*/
@Deprecated
public long getCompletedTasks();
/**
* Get the number of tasks waiting to be executed
* @see org.apache.cassandra.metrics.CommitLogMetrics#pendingTasks
*/
@Deprecated
public long getPendingTasks();
/**
* Get the current size used by all the commitlog segments.
* @see org.apache.cassandra.metrics.CommitLogMetrics#totalCommitLogSize
*/
@Deprecated
public long getTotalCommitlogSize();
/**
* Recover a single file.
*/

View File

@ -23,6 +23,7 @@ import java.util.Map;
import java.util.UUID;
import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.metrics.StorageMetrics;
import org.apache.cassandra.service.StorageService;
/** Implements serializable to allow structured info to be returned via JMX. */
@ -121,7 +122,7 @@ public final class CompactionInfo implements Serializable
{
private volatile boolean stopRequested = false;
public abstract CompactionInfo getCompactionInfo();
double load = StorageService.instance.getLoad();
double load = StorageMetrics.load.getCount();
double reportedSeverity = 0d;
public void stop()

View File

@ -1369,22 +1369,22 @@ public class CompactionManager implements CompactionManagerMBean
public long getTotalBytesCompacted()
{
return metrics.bytesCompacted.count();
return metrics.bytesCompacted.getCount();
}
public long getTotalCompactionsCompleted()
{
return metrics.totalCompactionsCompleted.count();
return metrics.totalCompactionsCompleted.getCount();
}
public int getPendingTasks()
{
return metrics.pendingTasks.value();
return metrics.pendingTasks.getValue();
}
public long getCompletedTasks()
{
return metrics.completedTasks.value();
return metrics.completedTasks.getValue();
}
private static class CleanupInfo extends CompactionInfo.Holder

View File

@ -32,34 +32,6 @@ public interface CompactionManagerMBean
/** compaction history **/
public TabularData getCompactionHistory();
/**
* @see org.apache.cassandra.metrics.CompactionMetrics#pendingTasks
* @return estimated number of compactions remaining to perform
*/
@Deprecated
public int getPendingTasks();
/**
* @see org.apache.cassandra.metrics.CompactionMetrics#completedTasks
* @return number of completed compactions since server [re]start
*/
@Deprecated
public long getCompletedTasks();
/**
* @see org.apache.cassandra.metrics.CompactionMetrics#bytesCompacted
* @return total number of bytes compacted since server [re]start
*/
@Deprecated
public long getTotalBytesCompacted();
/**
* @see org.apache.cassandra.metrics.CompactionMetrics#totalCompactionsCompleted
* @return total number of compactions since server [re]start
*/
@Deprecated
public long getTotalCompactionsCompleted();
/**
* Triggers the compaction of user specified sstables.
* You can specify files from various keyspaces and columnfamilies.

View File

@ -214,7 +214,7 @@ public abstract class ExtendedFilter
{
// if we have a high chance of getting all the columns in a single index slice (and it's not too costly), do that.
// otherwise, the extraFilter (lazily created) will fetch by name the columns referenced by the additional expressions.
if (cfs.getMaxRowSize() < DatabaseDescriptor.getColumnIndexSize())
if (cfs.metric.maxRowSize.getValue() < DatabaseDescriptor.getColumnIndexSize())
{
logger.trace("Expanding slice filter to entire row to cover additional expressions");
return new SliceQueryFilter(ColumnSlice.ALL_COLUMNS_ARRAY, ((SliceQueryFilter)filter).reversed, Integer.MAX_VALUE);

View File

@ -673,7 +673,7 @@ public class Gossiper implements IFailureDetectionEventListener, GossiperMBean
long now = System.currentTimeMillis();
long nowNano = System.nanoTime();
long pending = ((JMXEnabledThreadPoolExecutor) StageManager.getStage(Stage.GOSSIP)).getPendingTasks();
long pending = ((JMXEnabledThreadPoolExecutor) StageManager.getStage(Stage.GOSSIP)).metrics.pendingTasks.getValue();
if (pending > 0 && lastProcessedMessageAt < now - 1000)
{
// if some new messages just arrived, give the executor some time to work on them

View File

@ -24,6 +24,8 @@ import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import com.codahale.metrics.ExponentiallyDecayingReservoir;
import javax.management.MBeanServer;
import javax.management.ObjectName;
@ -33,7 +35,6 @@ import org.apache.cassandra.net.MessagingService;
import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.utils.FBUtilities;
import com.yammer.metrics.stats.ExponentiallyDecayingSample;
/**
* A dynamic snitch that sorts endpoints by latency with an adapted phi failure detector
@ -55,7 +56,7 @@ public class DynamicEndpointSnitch extends AbstractEndpointSnitch implements ILa
private boolean registered = false;
private final ConcurrentHashMap<InetAddress, Double> scores = new ConcurrentHashMap<InetAddress, Double>();
private final ConcurrentHashMap<InetAddress, ExponentiallyDecayingSample> samples = new ConcurrentHashMap<InetAddress, ExponentiallyDecayingSample>();
private final ConcurrentHashMap<InetAddress, ExponentiallyDecayingReservoir> samples = new ConcurrentHashMap<>();
public final IEndpointSnitch subsnitch;
@ -217,10 +218,10 @@ public class DynamicEndpointSnitch extends AbstractEndpointSnitch implements ILa
public void receiveTiming(InetAddress host, long latency) // this is cheap
{
ExponentiallyDecayingSample sample = samples.get(host);
ExponentiallyDecayingReservoir sample = samples.get(host);
if (sample == null)
{
ExponentiallyDecayingSample maybeNewSample = new ExponentiallyDecayingSample(WINDOW_SIZE, ALPHA);
ExponentiallyDecayingReservoir maybeNewSample = new ExponentiallyDecayingReservoir(WINDOW_SIZE, ALPHA);
sample = samples.putIfAbsent(host, maybeNewSample);
if (sample == null)
sample = maybeNewSample;
@ -244,14 +245,14 @@ public class DynamicEndpointSnitch extends AbstractEndpointSnitch implements ILa
double maxLatency = 1;
// We're going to weight the latency for each host against the worst one we see, to
// arrive at sort of a 'badness percentage' for them. First, find the worst for each:
for (Map.Entry<InetAddress, ExponentiallyDecayingSample> entry : samples.entrySet())
for (Map.Entry<InetAddress, ExponentiallyDecayingReservoir> entry : samples.entrySet())
{
double mean = entry.getValue().getSnapshot().getMedian();
if (mean > maxLatency)
maxLatency = mean;
}
// now make another pass to do the weighting based on the maximums we found before
for (Map.Entry<InetAddress, ExponentiallyDecayingSample> entry: samples.entrySet())
for (Map.Entry<InetAddress, ExponentiallyDecayingReservoir> entry: samples.entrySet())
{
double score = entry.getValue().getSnapshot().getMedian() / maxLatency;
// finally, add the severity without any weighting, since hosts scale this relative to their own load and the size of the task causing the severity.
@ -265,8 +266,7 @@ public class DynamicEndpointSnitch extends AbstractEndpointSnitch implements ILa
private void reset()
{
for (ExponentiallyDecayingSample sample : samples.values())
sample.clear();
samples.clear();
}
public Map<InetAddress, Double> getScores()
@ -295,7 +295,7 @@ public class DynamicEndpointSnitch extends AbstractEndpointSnitch implements ILa
{
InetAddress host = InetAddress.getByName(hostname);
ArrayList<Double> timings = new ArrayList<Double>();
ExponentiallyDecayingSample sample = samples.get(host);
ExponentiallyDecayingReservoir sample = samples.get(host);
if (sample != null)
{
for (double time: sample.getSnapshot().getValues())

View File

@ -18,12 +18,14 @@
*/
package org.apache.cassandra.metrics;
import com.yammer.metrics.*;
import com.yammer.metrics.core.*;
import com.codahale.metrics.Counter;
import com.codahale.metrics.Histogram;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
public class CASClientRequestMetrics extends ClientRequestMetrics
{
public final Histogram contention;
/* Used only for write */
public final Counter conditionNotMet;
@ -32,16 +34,16 @@ public class CASClientRequestMetrics extends ClientRequestMetrics
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"));
contention = Metrics.histogram(factory.createMetricName("ContentionHistogram"));
conditionNotMet = Metrics.counter(factory.createMetricName("ConditionNotMet"));
unfinishedCommit = Metrics.counter(factory.createMetricName("UnfinishedCommit"));
}
public void release()
{
super.release();
Metrics.defaultRegistry().removeMetric(factory.createMetricName("ContentionHistogram"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("ConditionNotMet"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("UnfinishedCommit"));
Metrics.remove(factory.createMetricName("ContentionHistogram"));
Metrics.remove(factory.createMetricName("ConditionNotMet"));
Metrics.remove(factory.createMetricName("UnfinishedCommit"));
}
}

View File

@ -17,11 +17,12 @@
*/
package org.apache.cassandra.metrics;
import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.RatioGauge;
import org.apache.cassandra.cql3.QueryProcessor;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Counter;
import com.yammer.metrics.core.Gauge;
import com.yammer.metrics.util.RatioGauge;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
public class CQLMetrics
{
@ -36,27 +37,32 @@ public class CQLMetrics
public CQLMetrics()
{
regularStatementsExecuted = Metrics.newCounter(factory.createMetricName("RegularStatementsExecuted"));
preparedStatementsExecuted = Metrics.newCounter(factory.createMetricName("PreparedStatementsExecuted"));
preparedStatementsEvicted = Metrics.newCounter(factory.createMetricName("PreparedStatementsEvicted"));
regularStatementsExecuted = Metrics.counter(factory.createMetricName("RegularStatementsExecuted"));
preparedStatementsExecuted = Metrics.counter(factory.createMetricName("PreparedStatementsExecuted"));
preparedStatementsEvicted = Metrics.counter(factory.createMetricName("PreparedStatementsEvicted"));
preparedStatementsCount = Metrics.newGauge(factory.createMetricName("PreparedStatementsCount"), new Gauge<Integer>()
preparedStatementsCount = Metrics.register(factory.createMetricName("PreparedStatementsCount"), new Gauge<Integer>()
{
public Integer value()
public Integer getValue()
{
return QueryProcessor.preparedStatementsCount();
}
});
preparedStatementsRatio = Metrics.newGauge(factory.createMetricName("PreparedStatementsRatio"), new RatioGauge()
preparedStatementsRatio = Metrics.register(factory.createMetricName("PreparedStatementsRatio"), new RatioGauge()
{
public Ratio getRatio()
{
return Ratio.of(getNumerator(), getDenominator());
}
public double getNumerator()
{
return preparedStatementsExecuted.count();
return preparedStatementsExecuted.getCount();
}
public double getDenominator()
{
return regularStatementsExecuted.count() + preparedStatementsExecuted.count();
return regularStatementsExecuted.getCount() + preparedStatementsExecuted.getCount();
}
});
}

View File

@ -17,16 +17,15 @@
*/
package org.apache.cassandra.metrics;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Gauge;
import com.yammer.metrics.core.Meter;
import com.yammer.metrics.util.RatioGauge;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Meter;
import com.codahale.metrics.RatioGauge;
import org.apache.cassandra.cache.ICache;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
/**
* Metrics for {@code ICache}.
*/
@ -45,9 +44,6 @@ public class CacheMetrics
/** Total number of cache entries */
public final Gauge<Integer> entries;
private final AtomicLong lastRequests = new AtomicLong(0);
private final AtomicLong lastHits = new AtomicLong(0);
/**
* Create metrics for given cache.
*
@ -58,57 +54,36 @@ public class CacheMetrics
{
MetricNameFactory factory = new DefaultNameFactory("Cache", type);
capacity = Metrics.newGauge(factory.createMetricName("Capacity"), new Gauge<Long>()
capacity = Metrics.register(factory.createMetricName("Capacity"), new Gauge<Long>()
{
public Long value()
public Long getValue()
{
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()
hits = Metrics.meter(factory.createMetricName("Hits"));
requests = Metrics.meter(factory.createMetricName("Requests"));
hitRate = Metrics.register(factory.createMetricName("HitRate"), new RatioGauge()
{
protected double getNumerator()
@Override
public Ratio getRatio()
{
return hits.count();
}
protected double getDenominator()
{
return requests.count();
return Ratio.of(hits.getCount(), requests.getCount());
}
});
size = Metrics.newGauge(factory.createMetricName("Size"), new Gauge<Long>()
size = Metrics.register(factory.createMetricName("Size"), new Gauge<Long>()
{
public Long value()
public Long getValue()
{
return cache.weightedSize();
}
});
entries = Metrics.newGauge(factory.createMetricName("Entries"), new Gauge<Integer>()
entries = Metrics.register(factory.createMetricName("Entries"), new Gauge<Integer>()
{
public Integer value()
public Integer getValue()
{
return cache.size();
}
});
}
// for backward compatibility
@Deprecated
public double getRecentHitRate()
{
long r = requests.count();
long h = hits.count();
try
{
return ((double)(h - lastHits.get())) / (r - lastRequests.get());
}
finally
{
lastRequests.set(r);
lastHits.set(h);
}
}
}

View File

@ -0,0 +1,791 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.metrics;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Method;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.codahale.metrics.*;
import javax.management.*;
/**
* Makes integrating 3.0 metrics API with 2.0.
* <p/>
* The 3.0 API comes with poor JMX integration
*/
public class CassandraMetricsRegistry extends MetricRegistry
{
protected static final Logger logger = LoggerFactory.getLogger(CassandraMetricsRegistry.class);
public static final CassandraMetricsRegistry Metrics = new CassandraMetricsRegistry();
private MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
private CassandraMetricsRegistry()
{
super();
}
public Counter counter(MetricName name)
{
Counter counter = counter(name.getMetricName());
registerMBean(counter, name.getMBeanName());
return counter;
}
public Meter meter(MetricName name)
{
Meter meter = meter(name.getMetricName());
registerMBean(meter, name.getMBeanName());
return meter;
}
public Histogram histogram(MetricName name)
{
Histogram histogram = register(name, new ClearableHistogram(new EstimatedHistogramReservoir()));
registerMBean(histogram, name.getMBeanName());
return histogram;
}
public Timer timer(MetricName name)
{
Timer timer = register(name, new Timer(new EstimatedHistogramReservoir()));
registerMBean(timer, name.getMBeanName());
return timer;
}
public <T extends Metric> T register(MetricName name, T metric)
{
try
{
register(name.getMetricName(), metric);
registerMBean(metric, name.getMBeanName());
return metric;
}
catch (IllegalArgumentException e)
{
Metric existing = Metrics.getMetrics().get(name.getMetricName());
return (T)existing;
}
}
public boolean remove(MetricName name)
{
boolean removed = remove(name.getMetricName());
try
{
mBeanServer.unregisterMBean(name.getMBeanName());
} catch (InstanceNotFoundException | MBeanRegistrationException e)
{
logger.debug("Unable to remove mbean");
}
return removed;
}
private void registerMBean(Metric metric, ObjectName name)
{
AbstractBean mbean;
if (metric instanceof Gauge)
{
mbean = new JmxGauge((Gauge<?>) metric, name);
} else if (metric instanceof Counter)
{
mbean = new JmxCounter((Counter) metric, name);
} else if (metric instanceof Histogram)
{
mbean = new JmxHistogram((Histogram) metric, name);
} else if (metric instanceof Meter)
{
mbean = new JmxMeter((Meter) metric, name, TimeUnit.SECONDS);
} else if (metric instanceof Timer)
{
mbean = new JmxTimer((Timer) metric, name, TimeUnit.SECONDS, TimeUnit.MICROSECONDS);
} else
{
throw new IllegalArgumentException("Unknown metric type: " + metric.getClass());
}
try
{
mBeanServer.registerMBean(mbean, name);
} catch (InstanceAlreadyExistsException e)
{
logger.debug("Metric bean already exists", e);
} catch (MBeanRegistrationException e)
{
logger.debug("Unable to register metric bean", e);
} catch (NotCompliantMBeanException e)
{
logger.warn("Unable to register metric bean", e);
}
}
public interface MetricMBean
{
ObjectName objectName();
}
private abstract static class AbstractBean implements MetricMBean
{
private final ObjectName objectName;
AbstractBean(ObjectName objectName)
{
this.objectName = objectName;
}
@Override
public ObjectName objectName()
{
return objectName;
}
}
public interface JmxGaugeMBean extends MetricMBean
{
Object getValue();
}
private static class JmxGauge extends AbstractBean implements JmxGaugeMBean
{
private final Gauge<?> metric;
private JmxGauge(Gauge<?> metric, ObjectName objectName)
{
super(objectName);
this.metric = metric;
}
@Override
public Object getValue()
{
return metric.getValue();
}
}
public interface JmxHistogramMBean extends MetricMBean
{
long getCount();
long getMin();
long getMax();
double getMean();
double getStdDev();
double get50thPercentile();
double get75thPercentile();
double get95thPercentile();
double get98thPercentile();
double get99thPercentile();
double get999thPercentile();
long[] values();
}
private static class JmxHistogram extends AbstractBean implements JmxHistogramMBean
{
private final Histogram metric;
private JmxHistogram(Histogram metric, ObjectName objectName)
{
super(objectName);
this.metric = metric;
}
@Override
public double get50thPercentile()
{
return metric.getSnapshot().getMedian();
}
@Override
public long getCount()
{
return metric.getCount();
}
@Override
public long getMin()
{
return metric.getSnapshot().getMin();
}
@Override
public long getMax()
{
return metric.getSnapshot().getMax();
}
@Override
public double getMean()
{
return metric.getSnapshot().getMean();
}
@Override
public double getStdDev()
{
return metric.getSnapshot().getStdDev();
}
@Override
public double get75thPercentile()
{
return metric.getSnapshot().get75thPercentile();
}
@Override
public double get95thPercentile()
{
return metric.getSnapshot().get95thPercentile();
}
@Override
public double get98thPercentile()
{
return metric.getSnapshot().get98thPercentile();
}
@Override
public double get99thPercentile()
{
return metric.getSnapshot().get99thPercentile();
}
@Override
public double get999thPercentile()
{
return metric.getSnapshot().get999thPercentile();
}
@Override
public long[] values()
{
return metric.getSnapshot().getValues();
}
}
public interface JmxCounterMBean extends MetricMBean
{
long getCount();
}
private static class JmxCounter extends AbstractBean implements JmxCounterMBean
{
private final Counter metric;
private JmxCounter(Counter metric, ObjectName objectName)
{
super(objectName);
this.metric = metric;
}
@Override
public long getCount()
{
return metric.getCount();
}
}
public interface JmxMeterMBean extends MetricMBean
{
long getCount();
double getMeanRate();
double getOneMinuteRate();
double getFiveMinuteRate();
double getFifteenMinuteRate();
String getRateUnit();
}
private static class JmxMeter extends AbstractBean implements JmxMeterMBean
{
private final Metered metric;
private final double rateFactor;
private final String rateUnit;
private JmxMeter(Metered metric, ObjectName objectName, TimeUnit rateUnit)
{
super(objectName);
this.metric = metric;
this.rateFactor = rateUnit.toSeconds(1);
this.rateUnit = "events/" + calculateRateUnit(rateUnit);
}
@Override
public long getCount()
{
return metric.getCount();
}
@Override
public double getMeanRate()
{
return metric.getMeanRate() * rateFactor;
}
@Override
public double getOneMinuteRate()
{
return metric.getOneMinuteRate() * rateFactor;
}
@Override
public double getFiveMinuteRate()
{
return metric.getFiveMinuteRate() * rateFactor;
}
@Override
public double getFifteenMinuteRate()
{
return metric.getFifteenMinuteRate() * rateFactor;
}
@Override
public String getRateUnit()
{
return rateUnit;
}
private String calculateRateUnit(TimeUnit unit)
{
final String s = unit.toString().toLowerCase(Locale.US);
return s.substring(0, s.length() - 1);
}
}
public interface JmxTimerMBean extends JmxMeterMBean
{
double getMin();
double getMax();
double getMean();
double getStdDev();
double get50thPercentile();
double get75thPercentile();
double get95thPercentile();
double get98thPercentile();
double get99thPercentile();
double get999thPercentile();
long[] values();
String getDurationUnit();
}
static class JmxTimer extends JmxMeter implements JmxTimerMBean
{
private final Timer metric;
private final double durationFactor;
private final String durationUnit;
private JmxTimer(Timer metric,
ObjectName objectName,
TimeUnit rateUnit,
TimeUnit durationUnit)
{
super(metric, objectName, rateUnit);
this.metric = metric;
this.durationFactor = 1.0 / durationUnit.toNanos(1);
this.durationUnit = durationUnit.toString().toLowerCase(Locale.US);
}
@Override
public double get50thPercentile()
{
return metric.getSnapshot().getMedian() * durationFactor;
}
@Override
public double getMin()
{
return metric.getSnapshot().getMin() * durationFactor;
}
@Override
public double getMax()
{
return metric.getSnapshot().getMax() * durationFactor;
}
@Override
public double getMean()
{
return metric.getSnapshot().getMean() * durationFactor;
}
@Override
public double getStdDev()
{
return metric.getSnapshot().getStdDev() * durationFactor;
}
@Override
public double get75thPercentile()
{
return metric.getSnapshot().get75thPercentile() * durationFactor;
}
@Override
public double get95thPercentile()
{
return metric.getSnapshot().get95thPercentile() * durationFactor;
}
@Override
public double get98thPercentile()
{
return metric.getSnapshot().get98thPercentile() * durationFactor;
}
@Override
public double get99thPercentile()
{
return metric.getSnapshot().get99thPercentile() * durationFactor;
}
@Override
public double get999thPercentile()
{
return metric.getSnapshot().get999thPercentile() * durationFactor;
}
@Override
public long[] values()
{
return metric.getSnapshot().getValues();
}
@Override
public String getDurationUnit()
{
return durationUnit;
}
}
/**
* A value class encapsulating a metric's owning class and name.
*/
public static class MetricName implements Comparable<MetricName>
{
private final String group;
private final String type;
private final String name;
private final String scope;
private final String mBeanName;
/**
* Creates a new {@link MetricName} without a scope.
*
* @param klass the {@link Class} to which the {@link Metric} belongs
* @param name the name of the {@link Metric}
*/
public MetricName(Class<?> klass, String name)
{
this(klass, name, null);
}
/**
* Creates a new {@link MetricName} without a scope.
*
* @param group the group to which the {@link Metric} belongs
* @param type the type to which the {@link Metric} belongs
* @param name the name of the {@link Metric}
*/
public MetricName(String group, String type, String name)
{
this(group, type, name, null);
}
/**
* Creates a new {@link MetricName} without a scope.
*
* @param klass the {@link Class} to which the {@link Metric} belongs
* @param name the name of the {@link Metric}
* @param scope the scope of the {@link Metric}
*/
public MetricName(Class<?> klass, String name, String scope)
{
this(klass.getPackage() == null ? "" : klass.getPackage().getName(),
klass.getSimpleName().replaceAll("\\$$", ""),
name,
scope);
}
/**
* Creates a new {@link MetricName} without a scope.
*
* @param group the group to which the {@link Metric} belongs
* @param type the type to which the {@link Metric} belongs
* @param name the name of the {@link Metric}
* @param scope the scope of the {@link Metric}
*/
public MetricName(String group, String type, String name, String scope)
{
this(group, type, name, scope, createMBeanName(group, type, name, scope));
}
/**
* Creates a new {@link MetricName} without a scope.
*
* @param group the group to which the {@link Metric} belongs
* @param type the type to which the {@link Metric} belongs
* @param name the name of the {@link Metric}
* @param scope the scope of the {@link Metric}
* @param mBeanName the 'ObjectName', represented as a string, to use when registering the
* MBean.
*/
public MetricName(String group, String type, String name, String scope, String mBeanName)
{
if (group == null || type == null)
{
throw new IllegalArgumentException("Both group and type need to be specified");
}
if (name == null)
{
throw new IllegalArgumentException("Name needs to be specified");
}
this.group = group;
this.type = type;
this.name = name;
this.scope = scope;
this.mBeanName = mBeanName;
}
/**
* Returns the group to which the {@link Metric} belongs. For class-based metrics, this will be
* the package name of the {@link Class} to which the {@link Metric} belongs.
*
* @return the group to which the {@link Metric} belongs
*/
public String getGroup()
{
return group;
}
/**
* Returns the type to which the {@link Metric} belongs. For class-based metrics, this will be
* the simple class name of the {@link Class} to which the {@link Metric} belongs.
*
* @return the type to which the {@link Metric} belongs
*/
public String getType()
{
return type;
}
/**
* Returns the name of the {@link Metric}.
*
* @return the name of the {@link Metric}
*/
public String getName()
{
return name;
}
public String getMetricName()
{
return MetricRegistry.name(group, type, name, scope);
}
/**
* Returns the scope of the {@link Metric}.
*
* @return the scope of the {@link Metric}
*/
public String getScope()
{
return scope;
}
/**
* Returns {@code true} if the {@link Metric} has a scope, {@code false} otherwise.
*
* @return {@code true} if the {@link Metric} has a scope
*/
public boolean hasScope()
{
return scope != null;
}
/**
* Returns the MBean name for the {@link Metric} identified by this metric name.
*
* @return the MBean name
*/
public ObjectName getMBeanName()
{
String mname = mBeanName;
if (mname == null)
mname = getMetricName();
try
{
return new ObjectName(mname);
} catch (MalformedObjectNameException e)
{
try
{
return new ObjectName(ObjectName.quote(mname));
} catch (MalformedObjectNameException e1)
{
throw new RuntimeException(e1);
}
}
}
@Override
public boolean equals(Object o)
{
if (this == o)
{
return true;
}
if (o == null || getClass() != o.getClass())
{
return false;
}
final MetricName that = (MetricName) o;
return mBeanName.equals(that.mBeanName);
}
@Override
public int hashCode()
{
return mBeanName.hashCode();
}
@Override
public String toString()
{
return mBeanName;
}
@Override
public int compareTo(MetricName o)
{
return mBeanName.compareTo(o.mBeanName);
}
private static String createMBeanName(String group, String type, String name, String scope)
{
final StringBuilder nameBuilder = new StringBuilder();
nameBuilder.append(ObjectName.quote(group));
nameBuilder.append(":type=");
nameBuilder.append(ObjectName.quote(type));
if (scope != null)
{
nameBuilder.append(",scope=");
nameBuilder.append(ObjectName.quote(scope));
}
if (name.length() > 0)
{
nameBuilder.append(",name=");
nameBuilder.append(ObjectName.quote(name));
}
return nameBuilder.toString();
}
/**
* If the group is empty, use the package name of the given class. Otherwise use group
*
* @param group The group to use by default
* @param klass The class being tracked
* @return a group for the metric
*/
public static String chooseGroup(String group, Class<?> klass)
{
if (group == null || group.isEmpty())
{
group = klass.getPackage() == null ? "" : klass.getPackage().getName();
}
return group;
}
/**
* If the type is empty, use the simple name of the given class. Otherwise use type
*
* @param type The type to use by default
* @param klass The class being tracked
* @return a type for the metric
*/
public static String chooseType(String type, Class<?> klass)
{
if (type == null || type.isEmpty())
{
type = klass.getSimpleName().replaceAll("\\$$", "");
}
return type;
}
/**
* If name is empty, use the name of the given method. Otherwise use name
*
* @param name The name to use by default
* @param method The method being tracked
* @return a name for the metric
*/
public static String chooseName(String name, Method method)
{
if (name == null || name.isEmpty())
{
name = method.getName();
}
return name;
}
}
}

View File

@ -15,27 +15,34 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.concurrent;
package org.apache.cassandra.metrics;
import com.google.common.annotations.VisibleForTesting;
import com.codahale.metrics.Histogram;
/**
* @see org.apache.cassandra.metrics.ThreadPoolMetrics
* Adds ability to reset a histogram
*/
@Deprecated
public interface IExecutorMBean
public class ClearableHistogram extends Histogram
{
/**
* Get the current number of running tasks
*/
public int getActiveCount();
private final EstimatedHistogramReservoir reservoirRef;
/**
* Get the number of completed tasks
* Creates a new {@link com.codahale.metrics.Histogram} with the given reservoir.
*
* @param reservoir the reservoir to create a histogram from
*/
public long getCompletedTasks();
public ClearableHistogram(EstimatedHistogramReservoir reservoir)
{
super(reservoir);
/**
* Get the number of tasks waiting to be executed
*/
public long getPendingTasks();
this.reservoirRef = reservoir;
}
@VisibleForTesting
public void clear()
{
reservoirRef.clear();
}
}

View File

@ -20,8 +20,10 @@ package org.apache.cassandra.metrics;
import java.util.concurrent.Callable;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Gauge;
import com.codahale.metrics.Gauge;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
public class ClientMetrics
{
@ -35,15 +37,14 @@ public class ClientMetrics
public void addCounter(String name, final Callable<Integer> provider)
{
Metrics.newGauge(factory.createMetricName(name), new Gauge<Integer>()
Metrics.register(factory.createMetricName(name), new Gauge<Integer>()
{
public Integer value()
public Integer getValue()
{
try
{
return provider.call();
}
catch (Exception e)
} catch (Exception e)
{
throw new RuntimeException(e);
}

View File

@ -20,20 +20,14 @@
*/
package org.apache.cassandra.metrics;
import java.util.concurrent.TimeUnit;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Counter;
import com.yammer.metrics.core.Meter;
import com.codahale.metrics.Meter;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
public class ClientRequestMetrics extends LatencyMetrics
{
@Deprecated public static final Counter readTimeouts = Metrics.newCounter(DefaultNameFactory.createMetricName("ClientRequestMetrics", "ReadTimeouts", null));
@Deprecated public static final Counter writeTimeouts = Metrics.newCounter(DefaultNameFactory.createMetricName("ClientRequestMetrics", "WriteTimeouts", null));
@Deprecated public static final Counter readUnavailables = Metrics.newCounter(DefaultNameFactory.createMetricName("ClientRequestMetrics", "ReadUnavailables", null));
@Deprecated public static final Counter writeUnavailables = Metrics.newCounter(DefaultNameFactory.createMetricName("ClientRequestMetrics", "WriteUnavailables", null));
@Deprecated public static final Counter readFailures = Metrics.newCounter(DefaultNameFactory.createMetricName("ClientRequestMetrics", "ReadFailures", null));
public final Meter timeouts;
public final Meter unavailables;
public final Meter failures;
@ -42,16 +36,16 @@ public class ClientRequestMetrics extends LatencyMetrics
{
super("ClientRequest", scope);
timeouts = Metrics.newMeter(factory.createMetricName("Timeouts"), "timeouts", TimeUnit.SECONDS);
unavailables = Metrics.newMeter(factory.createMetricName("Unavailables"), "unavailables", TimeUnit.SECONDS);
failures = Metrics.newMeter(factory.createMetricName("Failures"), "failures", TimeUnit.SECONDS);
timeouts = Metrics.meter(factory.createMetricName("Timeouts"));
unavailables = Metrics.meter(factory.createMetricName("Unavailables"));
failures = Metrics.meter(factory.createMetricName("Failures"));
}
public void release()
{
super.release();
Metrics.defaultRegistry().removeMetric(factory.createMetricName("Timeouts"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("Unavailables"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("Failures"));
Metrics.remove(factory.createMetricName("Timeouts"));
Metrics.remove(factory.createMetricName("Unavailables"));
Metrics.remove(factory.createMetricName("Failures"));
}
}

View File

@ -20,8 +20,9 @@ package org.apache.cassandra.metrics;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import com.codahale.metrics.*;
import com.codahale.metrics.Timer;
import org.apache.cassandra.db.ColumnFamilyStore;
import org.apache.cassandra.db.Keyspace;
import org.apache.cassandra.io.sstable.format.SSTableReader;
@ -31,16 +32,16 @@ import org.apache.cassandra.utils.TopKSampler;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.*;
import com.yammer.metrics.core.Timer;
import com.yammer.metrics.util.RatioGauge;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
/**
* Metrics for {@link ColumnFamilyStore}.
*/
public class ColumnFamilyMetrics
{
/** Total amount of data stored in the memtable that resides on-heap, including column related overhead and overwritten rows. */
public final Gauge<Long> memtableOnHeapSize;
/** Total amount of data stored in the memtable that resides off-heap, including column related overhead and overwritten rows. */
@ -130,17 +131,13 @@ public class ColumnFamilyMetrics
public final Timer coordinatorScanLatency;
/** Time spent waiting for free memtable space, either on- or off-heap */
public final Timer waitingOnFreeMemtableSpace;
public final Histogram waitingOnFreeMemtableSpace;
private final MetricNameFactory factory;
private static final MetricNameFactory globalNameFactory = new AllColumnFamilyMetricNameFactory();;
private static final MetricNameFactory globalNameFactory = new AllColumnFamilyMetricNameFactory();
public final Counter speculativeRetries;
// for backward compatibility
@Deprecated public final EstimatedHistogram sstablesPerRead = new EstimatedHistogram(35);
@Deprecated public final EstimatedHistogram recentSSTablesPerRead = new EstimatedHistogram(35);
public final static LatencyMetrics globalReadLatency = new LatencyMetrics(globalNameFactory, "Read");
public final static LatencyMetrics globalWriteLatency = new LatencyMetrics(globalNameFactory, "Write");
public final static LatencyMetrics globalRangeLatency = new LatencyMetrics(globalNameFactory, "Range");
@ -213,35 +210,35 @@ public class ColumnFamilyMetrics
memtableColumnsCount = createColumnFamilyGauge("MemtableColumnsCount", new Gauge<Long>()
{
public Long value()
public Long getValue()
{
return cfs.getDataTracker().getView().getCurrentMemtable().getOperations();
}
});
memtableOnHeapSize = createColumnFamilyGauge("MemtableOnHeapSize", new Gauge<Long>()
{
public Long value()
public Long getValue()
{
return cfs.getDataTracker().getView().getCurrentMemtable().getAllocator().onHeap().owns();
}
});
memtableOffHeapSize = createColumnFamilyGauge("MemtableOffHeapSize", new Gauge<Long>()
{
public Long value()
public Long getValue()
{
return cfs.getDataTracker().getView().getCurrentMemtable().getAllocator().offHeap().owns();
}
});
memtableLiveDataSize = createColumnFamilyGauge("MemtableLiveDataSize", new Gauge<Long>()
{
public Long value()
public Long getValue()
{
return cfs.getDataTracker().getView().getCurrentMemtable().getLiveDataSize();
}
});
allMemtablesOnHeapSize = createColumnFamilyGauge("AllMemtablesHeapSize", new Gauge<Long>()
{
public Long value()
public Long getValue()
{
long size = 0;
for (ColumnFamilyStore cfs2 : cfs.concatWithIndexes())
@ -251,7 +248,7 @@ public class ColumnFamilyMetrics
});
allMemtablesOffHeapSize = createColumnFamilyGauge("AllMemtablesOffHeapSize", new Gauge<Long>()
{
public Long value()
public Long getValue()
{
long size = 0;
for (ColumnFamilyStore cfs2 : cfs.concatWithIndexes())
@ -261,7 +258,7 @@ public class ColumnFamilyMetrics
});
allMemtablesLiveDataSize = createColumnFamilyGauge("AllMemtablesLiveDataSize", new Gauge<Long>()
{
public Long value()
public Long getValue()
{
long size = 0;
for (ColumnFamilyStore cfs2 : cfs.concatWithIndexes())
@ -270,9 +267,9 @@ public class ColumnFamilyMetrics
}
});
memtableSwitchCount = createColumnFamilyCounter("MemtableSwitchCount");
estimatedRowSizeHistogram = Metrics.newGauge(factory.createMetricName("EstimatedRowSizeHistogram"), new Gauge<long[]>()
estimatedRowSizeHistogram = Metrics.register(factory.createMetricName("EstimatedRowSizeHistogram"), new Gauge<long[]>()
{
public long[] value()
public long[] getValue()
{
return combineHistograms(cfs.getSSTables(), new GetHistogram()
{
@ -283,9 +280,9 @@ public class ColumnFamilyMetrics
});
}
});
estimatedColumnCountHistogram = Metrics.newGauge(factory.createMetricName("EstimatedColumnCountHistogram"), new Gauge<long[]>()
estimatedColumnCountHistogram = Metrics.register(factory.createMetricName("EstimatedColumnCountHistogram"), new Gauge<long[]>()
{
public long[] value()
public long[] getValue()
{
return combineHistograms(cfs.getSSTables(), new GetHistogram()
{
@ -299,7 +296,7 @@ public class ColumnFamilyMetrics
sstablesPerReadHistogram = createColumnFamilyHistogram("SSTablesPerReadHistogram", cfs.keyspace.metric.sstablesPerReadHistogram);
compressionRatio = createColumnFamilyGauge("CompressionRatio", new Gauge<Double>()
{
public Double value()
public Double getValue()
{
double sum = 0;
int total = 0;
@ -315,7 +312,7 @@ public class ColumnFamilyMetrics
}
}, new Gauge<Double>() // global gauge
{
public Double value()
public Double getValue()
{
double sum = 0;
int total = 0;
@ -339,14 +336,14 @@ public class ColumnFamilyMetrics
pendingFlushes = createColumnFamilyCounter("PendingFlushes");
pendingCompactions = createColumnFamilyGauge("PendingCompactions", new Gauge<Integer>()
{
public Integer value()
public Integer getValue()
{
return cfs.getCompactionStrategy().getEstimatedRemainingTasks();
}
});
liveSSTableCount = createColumnFamilyGauge("LiveSSTableCount", new Gauge<Integer>()
{
public Integer value()
public Integer getValue()
{
return cfs.getDataTracker().getSSTables().size();
}
@ -355,7 +352,7 @@ public class ColumnFamilyMetrics
totalDiskSpaceUsed = createColumnFamilyCounter("TotalDiskSpaceUsed");
minRowSize = createColumnFamilyGauge("MinRowSize", new Gauge<Long>()
{
public Long value()
public Long getValue()
{
long min = 0;
for (SSTableReader sstable : cfs.getSSTables())
@ -367,19 +364,19 @@ public class ColumnFamilyMetrics
}
}, new Gauge<Long>() // global gauge
{
public Long value()
public Long getValue()
{
long min = Long.MAX_VALUE;
for (Metric cfGauge : allColumnFamilyMetrics.get("MinRowSize"))
{
min = Math.min(min, ((Gauge<? extends Number>) cfGauge).value().longValue());
min = Math.min(min, ((Gauge<? extends Number>) cfGauge).getValue().longValue());
}
return min;
}
});
maxRowSize = createColumnFamilyGauge("MaxRowSize", new Gauge<Long>()
{
public Long value()
public Long getValue()
{
long max = 0;
for (SSTableReader sstable : cfs.getSSTables())
@ -391,19 +388,19 @@ public class ColumnFamilyMetrics
}
}, new Gauge<Long>() // global gauge
{
public Long value()
public Long getValue()
{
long max = 0;
for (Metric cfGauge : allColumnFamilyMetrics.get("MaxRowSize"))
{
max = Math.max(max, ((Gauge<? extends Number>) cfGauge).value().longValue());
max = Math.max(max, ((Gauge<? extends Number>) cfGauge).getValue().longValue());
}
return max;
}
});
meanRowSize = createColumnFamilyGauge("MeanRowSize", new Gauge<Long>()
{
public Long value()
public Long getValue()
{
long sum = 0;
long count = 0;
@ -417,7 +414,7 @@ public class ColumnFamilyMetrics
}
}, new Gauge<Long>() // global gauge
{
public Long value()
public Long getValue()
{
long sum = 0;
long count = 0;
@ -435,7 +432,7 @@ public class ColumnFamilyMetrics
});
bloomFilterFalsePositives = createColumnFamilyGauge("BloomFilterFalsePositives", new Gauge<Long>()
{
public Long value()
public Long getValue()
{
long count = 0L;
for (SSTableReader sstable: cfs.getSSTables())
@ -445,7 +442,7 @@ public class ColumnFamilyMetrics
});
recentBloomFilterFalsePositives = createColumnFamilyGauge("RecentBloomFilterFalsePositives", new Gauge<Long>()
{
public Long value()
public Long getValue()
{
long count = 0L;
for (SSTableReader sstable : cfs.getSSTables())
@ -455,7 +452,7 @@ public class ColumnFamilyMetrics
});
bloomFilterFalseRatio = createColumnFamilyGauge("BloomFilterFalseRatio", new Gauge<Double>()
{
public Double value()
public Double getValue()
{
long falseCount = 0L;
long trueCount = 0L;
@ -470,7 +467,7 @@ public class ColumnFamilyMetrics
}
}, new Gauge<Double>() // global gauge
{
public Double value()
public Double getValue()
{
long falseCount = 0L;
long trueCount = 0L;
@ -489,7 +486,7 @@ public class ColumnFamilyMetrics
});
recentBloomFilterFalseRatio = createColumnFamilyGauge("RecentBloomFilterFalseRatio", new Gauge<Double>()
{
public Double value()
public Double getValue()
{
long falseCount = 0L;
long trueCount = 0L;
@ -504,7 +501,7 @@ public class ColumnFamilyMetrics
}
}, new Gauge<Double>() // global gauge
{
public Double value()
public Double getValue()
{
long falseCount = 0L;
long trueCount = 0L;
@ -523,7 +520,7 @@ public class ColumnFamilyMetrics
});
bloomFilterDiskSpaceUsed = createColumnFamilyGauge("BloomFilterDiskSpaceUsed", new Gauge<Long>()
{
public Long value()
public Long getValue()
{
long total = 0;
for (SSTableReader sst : cfs.getSSTables())
@ -533,7 +530,7 @@ public class ColumnFamilyMetrics
});
bloomFilterOffHeapMemoryUsed = createColumnFamilyGauge("BloomFilterOffHeapMemoryUsed", new Gauge<Long>()
{
public Long value()
public Long getValue()
{
long total = 0;
for (SSTableReader sst : cfs.getSSTables())
@ -543,7 +540,7 @@ public class ColumnFamilyMetrics
});
indexSummaryOffHeapMemoryUsed = createColumnFamilyGauge("IndexSummaryOffHeapMemoryUsed", new Gauge<Long>()
{
public Long value()
public Long getValue()
{
long total = 0;
for (SSTableReader sst : cfs.getSSTables())
@ -553,7 +550,7 @@ public class ColumnFamilyMetrics
});
compressionMetadataOffHeapMemoryUsed = createColumnFamilyGauge("CompressionMetadataOffHeapMemoryUsed", new Gauge<Long>()
{
public Long value()
public Long getValue()
{
long total = 0;
for (SSTableReader sst : cfs.getSSTables())
@ -562,8 +559,14 @@ public class ColumnFamilyMetrics
}
});
speculativeRetries = createColumnFamilyCounter("SpeculativeRetries");
keyCacheHitRate = Metrics.newGauge(factory.createMetricName("KeyCacheHitRate"), new RatioGauge()
keyCacheHitRate = Metrics.register(factory.createMetricName("KeyCacheHitRate"), new RatioGauge()
{
@Override
public Ratio getRatio()
{
return Ratio.of(getNumerator(), getDenominator());
}
protected double getNumerator()
{
long hits = 0L;
@ -583,13 +586,13 @@ public class ColumnFamilyMetrics
tombstoneScannedHistogram = createColumnFamilyHistogram("TombstoneScannedHistogram", cfs.keyspace.metric.tombstoneScannedHistogram);
liveScannedHistogram = createColumnFamilyHistogram("LiveScannedHistogram", cfs.keyspace.metric.liveScannedHistogram);
colUpdateTimeDeltaHistogram = createColumnFamilyHistogram("ColUpdateTimeDeltaHistogram", cfs.keyspace.metric.colUpdateTimeDeltaHistogram);
coordinatorReadLatency = Metrics.newTimer(factory.createMetricName("CoordinatorReadLatency"), TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
coordinatorScanLatency = Metrics.newTimer(factory.createMetricName("CoordinatorScanLatency"), TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
waitingOnFreeMemtableSpace = Metrics.newTimer(factory.createMetricName("WaitingOnFreeMemtableSpace"), TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
coordinatorReadLatency = Metrics.timer(factory.createMetricName("CoordinatorReadLatency"));
coordinatorScanLatency = Metrics.timer(factory.createMetricName("CoordinatorScanLatency"));
waitingOnFreeMemtableSpace = Metrics.histogram(factory.createMetricName("WaitingOnFreeMemtableSpace"));
trueSnapshotsSize = createColumnFamilyGauge("SnapshotsSize", new Gauge<Long>()
{
public Long value()
public Long getValue()
{
return cfs.trueSnapshotsSize();
}
@ -606,8 +609,6 @@ public class ColumnFamilyMetrics
public void updateSSTableIterated(int count)
{
sstablesPerReadHistogram.update(count);
recentSSTablesPerRead.add(count);
sstablesPerRead.add(count);
}
/**
@ -617,18 +618,18 @@ public class ColumnFamilyMetrics
{
for(String name : all)
{
allColumnFamilyMetrics.get(name).remove(Metrics.defaultRegistry().allMetrics().get(factory.createMetricName(name)));
Metrics.defaultRegistry().removeMetric(factory.createMetricName(name));
allColumnFamilyMetrics.get(name).remove(Metrics.getMetrics().get(factory.createMetricName(name)));
Metrics.remove(factory.createMetricName(name));
}
readLatency.release();
writeLatency.release();
rangeLatency.release();
Metrics.defaultRegistry().removeMetric(factory.createMetricName("EstimatedRowSizeHistogram"));
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"));
Metrics.remove(factory.createMetricName("EstimatedRowSizeHistogram"));
Metrics.remove(factory.createMetricName("EstimatedColumnCountHistogram"));
Metrics.remove(factory.createMetricName("KeyCacheHitRate"));
Metrics.remove(factory.createMetricName("CoordinatorReadLatency"));
Metrics.remove(factory.createMetricName("CoordinatorScanLatency"));
Metrics.remove(factory.createMetricName("WaitingOnFreeMemtableSpace"));
}
@ -640,12 +641,12 @@ public class ColumnFamilyMetrics
{
return createColumnFamilyGauge(name, gauge, new Gauge<Long>()
{
public Long value()
public Long getValue()
{
long total = 0;
for (Metric cfGauge : allColumnFamilyMetrics.get(name))
{
total = total + ((Gauge<? extends Number>) cfGauge).value().longValue();
total = total + ((Gauge<? extends Number>) cfGauge).getValue().longValue();
}
return total;
}
@ -658,10 +659,10 @@ public class ColumnFamilyMetrics
*/
protected <G,T> Gauge<T> createColumnFamilyGauge(String name, Gauge<T> gauge, Gauge<G> globalGauge)
{
Gauge<T> cfGauge = Metrics.newGauge(factory.createMetricName(name), gauge);
Gauge<T> cfGauge = Metrics.register(factory.createMetricName(name), gauge);
if (register(name, cfGauge))
{
Metrics.newGauge(globalNameFactory.createMetricName(name), globalGauge);
Metrics.register(globalNameFactory.createMetricName(name), globalGauge);
}
return cfGauge;
}
@ -672,17 +673,17 @@ public class ColumnFamilyMetrics
*/
protected Counter createColumnFamilyCounter(final String name)
{
Counter cfCounter = Metrics.newCounter(factory.createMetricName(name));
Counter cfCounter = Metrics.counter(factory.createMetricName(name));
if (register(name, cfCounter))
{
Metrics.newGauge(globalNameFactory.createMetricName(name), new Gauge<Long>()
Metrics.register(globalNameFactory.createMetricName(name), new Gauge<Long>()
{
public Long value()
public Long getValue()
{
long total = 0;
for (Metric cfGauge : allColumnFamilyMetrics.get(name))
{
total += ((Counter) cfGauge).count();
total += ((Counter) cfGauge).getCount();
}
return total;
}
@ -695,13 +696,13 @@ public class ColumnFamilyMetrics
* Create a histogram-like interface that will register both a CF, keyspace and global level
* histogram and forward any updates to both
*/
protected ColumnFamilyHistogram createColumnFamilyHistogram(String name, Histogram keyspaceHistogram)
protected ColumnFamilyHistogram createColumnFamilyHistogram(String name, Histogram keyspaceHistogram)
{
Histogram cfHistogram = Metrics.newHistogram(factory.createMetricName(name), true);
Histogram cfHistogram = Metrics.histogram(factory.createMetricName(name));
register(name, cfHistogram);
return new ColumnFamilyHistogram(cfHistogram, keyspaceHistogram, Metrics.newHistogram(globalNameFactory.createMetricName(name), true));
return new ColumnFamilyHistogram(cfHistogram, keyspaceHistogram, Metrics.histogram(globalNameFactory.createMetricName(name)));
}
/**
* Registers a metric to be removed when unloading CF.
* @return true if first time metric with that name has been registered
@ -718,13 +719,13 @@ public class ColumnFamilyMetrics
{
public final Histogram[] all;
public final Histogram cf;
private ColumnFamilyHistogram(Histogram cf, Histogram keyspace, Histogram global)
private ColumnFamilyHistogram(Histogram cf, Histogram keyspace, Histogram global)
{
this.cf = cf;
this.all = new Histogram[]{cf, keyspace, global};
}
public void update(long i)
public void update(long i)
{
for(Histogram histo : all)
{
@ -746,7 +747,7 @@ public class ColumnFamilyMetrics
isIndex = cfs.isIndex();
}
public MetricName createMetricName(String metricName)
public CassandraMetricsRegistry.MetricName createMetricName(String metricName)
{
String groupName = ColumnFamilyMetrics.class.getPackage().getName();
String type = isIndex ? "IndexColumnFamily" : "ColumnFamily";
@ -758,20 +759,20 @@ public class ColumnFamilyMetrics
mbeanName.append(",scope=").append(columnFamilyName);
mbeanName.append(",name=").append(metricName);
return new MetricName(groupName, type, metricName, keyspaceName + "." + columnFamilyName, mbeanName.toString());
return new CassandraMetricsRegistry.MetricName(groupName, type, metricName, keyspaceName + "." + columnFamilyName, mbeanName.toString());
}
}
static class AllColumnFamilyMetricNameFactory implements MetricNameFactory
{
public MetricName createMetricName(String metricName)
public CassandraMetricsRegistry.MetricName createMetricName(String metricName)
{
String groupName = ColumnFamilyMetrics.class.getPackage().getName();
StringBuilder mbeanName = new StringBuilder();
mbeanName.append(groupName).append(":");
mbeanName.append("type=ColumnFamily");
mbeanName.append(",name=").append(metricName);
return new MetricName(groupName, "ColumnFamily", metricName, "all", mbeanName.toString());
return new CassandraMetricsRegistry.MetricName(groupName, "ColumnFamily", metricName, "all", mbeanName.toString());
}
}

View File

@ -17,14 +17,13 @@
*/
package org.apache.cassandra.metrics;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Gauge;
import com.yammer.metrics.core.Timer;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Timer;
import org.apache.cassandra.db.commitlog.AbstractCommitLogService;
import org.apache.cassandra.db.commitlog.CommitLogSegmentManager;
import java.util.concurrent.TimeUnit;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
/**
* Metrics for commit log
@ -46,28 +45,28 @@ public class CommitLogMetrics
public CommitLogMetrics(final AbstractCommitLogService service, final CommitLogSegmentManager allocator)
{
completedTasks = Metrics.newGauge(factory.createMetricName("CompletedTasks"), new Gauge<Long>()
completedTasks = Metrics.register(factory.createMetricName("CompletedTasks"), new Gauge<Long>()
{
public Long value()
public Long getValue()
{
return service.getCompletedTasks();
}
});
pendingTasks = Metrics.newGauge(factory.createMetricName("PendingTasks"), new Gauge<Long>()
pendingTasks = Metrics.register(factory.createMetricName("PendingTasks"), new Gauge<Long>()
{
public Long value()
public Long getValue()
{
return service.getPendingTasks();
}
});
totalCommitLogSize = Metrics.newGauge(factory.createMetricName("TotalCommitLogSize"), new Gauge<Long>()
totalCommitLogSize = Metrics.register(factory.createMetricName("TotalCommitLogSize"), new Gauge<Long>()
{
public Long value()
public Long getValue()
{
return allocator.bytesUsed();
}
});
waitingOnSegmentAllocation = Metrics.newTimer(factory.createMetricName("WaitingOnSegmentAllocation"), TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
waitingOnCommit = Metrics.newTimer(factory.createMetricName("WaitingOnCommit"), TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
waitingOnSegmentAllocation = Metrics.timer(factory.createMetricName("WaitingOnSegmentAllocation"));
waitingOnCommit = Metrics.timer(factory.createMetricName("WaitingOnCommit"));
}
}

View File

@ -19,12 +19,10 @@ package org.apache.cassandra.metrics;
import java.util.*;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Counter;
import com.yammer.metrics.core.Gauge;
import com.yammer.metrics.core.Meter;
import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Meter;
import org.apache.cassandra.config.Schema;
import org.apache.cassandra.db.ColumnFamilyStore;
@ -32,6 +30,8 @@ import org.apache.cassandra.db.Keyspace;
import org.apache.cassandra.db.compaction.CompactionInfo;
import org.apache.cassandra.db.compaction.CompactionManager;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
/**
* Metrics for compaction.
*/
@ -53,9 +53,9 @@ public class CompactionMetrics implements CompactionManager.CompactionExecutorSt
public CompactionMetrics(final ThreadPoolExecutor... collectors)
{
pendingTasks = Metrics.newGauge(factory.createMetricName("PendingTasks"), new Gauge<Integer>()
pendingTasks = Metrics.register(factory.createMetricName("PendingTasks"), new Gauge<Integer>()
{
public Integer value()
public Integer getValue()
{
int n = 0;
for (String keyspaceName : Schema.instance.getKeyspaces())
@ -68,9 +68,9 @@ public class CompactionMetrics implements CompactionManager.CompactionExecutorSt
return n;
}
});
completedTasks = Metrics.newGauge(factory.createMetricName("CompletedTasks"), new Gauge<Long>()
completedTasks = Metrics.register(factory.createMetricName("CompletedTasks"), new Gauge<Long>()
{
public Long value()
public Long getValue()
{
long completedTasks = 0;
for (ThreadPoolExecutor collector : collectors)
@ -78,8 +78,8 @@ public class CompactionMetrics implements CompactionManager.CompactionExecutorSt
return completedTasks;
}
});
totalCompactionsCompleted = Metrics.newMeter(factory.createMetricName("TotalCompactionsCompleted"), "compaction completed", TimeUnit.SECONDS);
bytesCompacted = Metrics.newCounter(factory.createMetricName("BytesCompacted"));
totalCompactionsCompleted = Metrics.meter(factory.createMetricName("TotalCompactionsCompleted"));
bytesCompacted = Metrics.counter(factory.createMetricName("BytesCompacted"));
}
public void beginCompaction(CompactionInfo.Holder ci)

View File

@ -18,11 +18,12 @@
package org.apache.cassandra.metrics;
import java.net.InetAddress;
import java.util.concurrent.TimeUnit;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Gauge;
import com.yammer.metrics.core.Meter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Meter;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
import org.apache.cassandra.net.OutboundTcpConnectionPool;
@ -34,8 +35,7 @@ public class ConnectionMetrics
public static final String TYPE_NAME = "Connection";
/** Total number of timeouts happened on this node */
public static final Meter totalTimeouts = Metrics.newMeter(DefaultNameFactory.createMetricName(TYPE_NAME, "TotalTimeouts", null), "total timeouts", TimeUnit.SECONDS);
private static long recentTimeouts;
public static final Meter totalTimeouts = Metrics.meter(DefaultNameFactory.createMetricName(TYPE_NAME, "TotalTimeouts", null));
public final String address;
/** Pending tasks for Command(Mutations, Read etc) TCP Connections */
@ -53,8 +53,6 @@ public class ConnectionMetrics
private final MetricNameFactory factory;
private long recentTimeoutCount;
/**
* Create metrics for given connection pool.
*
@ -68,69 +66,51 @@ public class ConnectionMetrics
factory = new DefaultNameFactory("Connection", address);
commandPendingTasks = Metrics.newGauge(factory.createMetricName("CommandPendingTasks"), new Gauge<Integer>()
commandPendingTasks = Metrics.register(factory.createMetricName("CommandPendingTasks"), new Gauge<Integer>()
{
public Integer value()
public Integer getValue()
{
return connectionPool.cmdCon.getPendingMessages();
}
});
commandCompletedTasks = Metrics.newGauge(factory.createMetricName("CommandCompletedTasks"), new Gauge<Long>()
commandCompletedTasks = Metrics.register(factory.createMetricName("CommandCompletedTasks"), new Gauge<Long>()
{
public Long value()
public Long getValue()
{
return connectionPool.cmdCon.getCompletedMesssages();
}
});
commandDroppedTasks = Metrics.newGauge(factory.createMetricName("CommandDroppedTasks"), new Gauge<Long>()
commandDroppedTasks = Metrics.register(factory.createMetricName("CommandDroppedTasks"), new Gauge<Long>()
{
public Long value()
public Long getValue()
{
return connectionPool.cmdCon.getDroppedMessages();
}
});
responsePendingTasks = Metrics.newGauge(factory.createMetricName("ResponsePendingTasks"), new Gauge<Integer>()
responsePendingTasks = Metrics.register(factory.createMetricName("ResponsePendingTasks"), new Gauge<Integer>()
{
public Integer value()
public Integer getValue()
{
return connectionPool.ackCon.getPendingMessages();
}
});
responseCompletedTasks = Metrics.newGauge(factory.createMetricName("ResponseCompletedTasks"), new Gauge<Long>()
responseCompletedTasks = Metrics.register(factory.createMetricName("ResponseCompletedTasks"), new Gauge<Long>()
{
public Long value()
public Long getValue()
{
return connectionPool.ackCon.getCompletedMesssages();
}
});
timeouts = Metrics.newMeter(factory.createMetricName("Timeouts"), "timeouts", TimeUnit.SECONDS);
timeouts = Metrics.meter(factory.createMetricName("Timeouts"));
}
public void release()
{
Metrics.defaultRegistry().removeMetric(factory.createMetricName("CommandPendingTasks"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("CommandCompletedTasks"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("CommandDroppedTasks"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("ResponsePendingTasks"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("ResponseCompletedTasks"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("Timeouts"));
}
@Deprecated
public static long getRecentTotalTimeout()
{
long total = totalTimeouts.count();
long recent = total - recentTimeouts;
recentTimeouts = total;
return recent;
}
@Deprecated
public long getRecentTimeout()
{
long timeoutCount = timeouts.count();
long recent = timeoutCount - recentTimeoutCount;
recentTimeoutCount = timeoutCount;
return recent;
Metrics.remove(factory.createMetricName("CommandPendingTasks"));
Metrics.remove(factory.createMetricName("CommandCompletedTasks"));
Metrics.remove(factory.createMetricName("CommandDroppedTasks"));
Metrics.remove(factory.createMetricName("ResponsePendingTasks"));
Metrics.remove(factory.createMetricName("ResponseCompletedTasks"));
Metrics.remove(factory.createMetricName("Timeouts"));
}
}

View File

@ -17,7 +17,6 @@
*/
package org.apache.cassandra.metrics;
import com.yammer.metrics.core.MetricName;
/**
* MetricNameFactory that generates default MetricName of metrics.
@ -40,14 +39,14 @@ public class DefaultNameFactory implements MetricNameFactory
this.scope = scope;
}
public MetricName createMetricName(String metricName)
public CassandraMetricsRegistry.MetricName createMetricName(String metricName)
{
return createMetricName(type, metricName, scope);
}
public static MetricName createMetricName(String type, String metricName, String scope)
public static CassandraMetricsRegistry.MetricName createMetricName(String type, String metricName, String scope)
{
return new MetricName(GROUP_NAME, type, metricName, scope, createDefaultMBeanName(type, metricName, scope));
return new CassandraMetricsRegistry.MetricName(GROUP_NAME, type, metricName, scope, createDefaultMBeanName(type, metricName, scope));
}
protected static String createDefaultMBeanName(String type, String name, String scope)

View File

@ -17,13 +17,11 @@
*/
package org.apache.cassandra.metrics;
import java.util.concurrent.TimeUnit;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Meter;
import com.codahale.metrics.Meter;
import org.apache.cassandra.net.MessagingService;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
/**
* Metrics for dropped messages by verb.
*/
@ -32,20 +30,9 @@ public class DroppedMessageMetrics
/** Number of dropped messages */
public final Meter dropped;
private long lastDropped = 0;
public DroppedMessageMetrics(MessagingService.Verb verb)
{
MetricNameFactory factory = new DefaultNameFactory("DroppedMessage", verb.toString());
dropped = Metrics.newMeter(factory.createMetricName("Dropped"), "dropped", TimeUnit.SECONDS);
}
@Deprecated
public int getRecentlyDropped()
{
long currentDropped = dropped.count();
long recentlyDropped = currentDropped - lastDropped;
lastDropped = currentDropped;
return (int)recentlyDropped;
dropped = Metrics.meter(factory.createMetricName("Dropped"));
}
}

View File

@ -0,0 +1,105 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.metrics;
import com.google.common.annotations.VisibleForTesting;
import com.codahale.metrics.Reservoir;
import com.codahale.metrics.Snapshot;
import com.codahale.metrics.UniformSnapshot;
import org.apache.cassandra.utils.EstimatedHistogram;
/**
* Allows our Histogram implementation to be used by the metrics library.
*
* Default buckets allows nanosecond timings.
*/
public class EstimatedHistogramReservoir implements Reservoir
{
EstimatedHistogram histogram;
public EstimatedHistogramReservoir()
{
this(128);
}
public EstimatedHistogramReservoir(int numBuckets)
{
histogram = new EstimatedHistogram(numBuckets);
}
@Override
public int size()
{
return histogram.getBucketOffsets().length + 1;
}
@Override
public void update(long value)
{
histogram.add(value);
}
@Override
public Snapshot getSnapshot()
{
return new HistogramSnapshot(histogram);
}
@VisibleForTesting
public void clear()
{
histogram.getBuckets(true);
}
class HistogramSnapshot extends UniformSnapshot
{
EstimatedHistogram histogram;
public HistogramSnapshot(EstimatedHistogram histogram)
{
super(histogram.getBuckets(false));
this.histogram = histogram;
}
@Override
public double getValue(double quantile)
{
return histogram.percentile(quantile);
}
@Override
public long getMax()
{
return histogram.max();
}
@Override
public long getMin()
{
return histogram.min();
}
@Override
public double getMean()
{
return histogram.mean();
}
}
}

View File

@ -17,14 +17,14 @@
*/
package org.apache.cassandra.metrics;
import java.util.concurrent.TimeUnit;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Gauge;
import com.yammer.metrics.core.Meter;
import com.yammer.metrics.util.RatioGauge;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Meter;
import com.codahale.metrics.RatioGauge;
import org.apache.cassandra.service.FileCacheService;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
public class FileCacheMetrics
{
private static final MetricNameFactory factory = new DefaultNameFactory("FileCache");
@ -40,23 +40,19 @@ public class FileCacheMetrics
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()
hits = Metrics.meter(factory.createMetricName("Hits"));
requests = Metrics.meter(factory.createMetricName("Requests"));
hitRate = Metrics.register(factory.createMetricName("HitRate"), new RatioGauge()
{
protected double getNumerator()
@Override
public Ratio getRatio()
{
return hits.count();
}
protected double getDenominator()
{
return requests.count();
return Ratio.of(hits.getCount(), requests.getCount());
}
});
size = Metrics.newGauge(factory.createMetricName("Size"), new Gauge<Long>()
size = Metrics.register(factory.createMetricName("Size"), new Gauge<Long>()
{
public Long value()
public Long getValue()
{
return FileCacheService.instance.sizeInBytes();
}

View File

@ -20,6 +20,7 @@ package org.apache.cassandra.metrics;
import java.net.InetAddress;
import java.util.Map.Entry;
import com.codahale.metrics.Counter;
import org.apache.cassandra.db.HintedHandOffManager;
import org.apache.cassandra.db.SystemKeyspace;
import org.apache.cassandra.utils.UUIDGen;
@ -29,8 +30,8 @@ import org.slf4j.LoggerFactory;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Counter;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
/**
* Metrics for {@link HintedHandOffManager}.
@ -39,7 +40,7 @@ public class HintedHandoffMetrics
{
private static final Logger logger = LoggerFactory.getLogger(HintedHandoffMetrics.class);
private final MetricNameFactory factory = new DefaultNameFactory("HintedHandOffManager");
private static final MetricNameFactory factory = new DefaultNameFactory("HintedHandOffManager");
/** Total number of hints which are not stored, This is not a cache. */
private final LoadingCache<InetAddress, DifferencingCounter> notStored = CacheBuilder.newBuilder().build(new CacheLoader<InetAddress, DifferencingCounter>()
@ -55,7 +56,7 @@ public class HintedHandoffMetrics
{
public Counter load(InetAddress address)
{
return Metrics.newCounter(factory.createMetricName("Hints_created-" + address.getHostAddress()));
return Metrics.counter(factory.createMetricName("Hints_created-" + address.getHostAddress()));
}
});
@ -88,12 +89,12 @@ public class HintedHandoffMetrics
public DifferencingCounter(InetAddress address)
{
this.meter = Metrics.newCounter(factory.createMetricName("Hints_not_stored-" + address.getHostAddress()));
this.meter = Metrics.counter(factory.createMetricName("Hints_not_stored-" + address.getHostAddress()));
}
public long difference()
{
long current = meter.count();
long current = meter.getCount();
long difference = current - reported;
this.reported = current;
return difference;
@ -101,7 +102,7 @@ public class HintedHandoffMetrics
public long count()
{
return meter.count();
return meter.getCount();
}
public void mark()

View File

@ -19,13 +19,17 @@ package org.apache.cassandra.metrics;
import java.util.Set;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Histogram;
import com.codahale.metrics.MetricRegistry;
import org.apache.cassandra.db.ColumnFamilyStore;
import org.apache.cassandra.db.Keyspace;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.*;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
/**
* Metrics for {@link ColumnFamilyStore}.
@ -104,112 +108,112 @@ public class KeyspaceMetrics
{
public Long getValue(ColumnFamilyMetrics metric)
{
return metric.memtableColumnsCount.value();
return metric.memtableColumnsCount.getValue();
}
});
memtableLiveDataSize = createKeyspaceGauge("MemtableLiveDataSize", new MetricValue()
{
public Long getValue(ColumnFamilyMetrics metric)
{
return metric.memtableLiveDataSize.value();
return metric.memtableLiveDataSize.getValue();
}
});
memtableOnHeapDataSize = createKeyspaceGauge("MemtableOnHeapDataSize", new MetricValue()
{
public Long getValue(ColumnFamilyMetrics metric)
{
return metric.memtableOnHeapSize.value();
return metric.memtableOnHeapSize.getValue();
}
});
memtableOffHeapDataSize = createKeyspaceGauge("MemtableOffHeapDataSize", new MetricValue()
{
public Long getValue(ColumnFamilyMetrics metric)
{
return metric.memtableOffHeapSize.value();
return metric.memtableOffHeapSize.getValue();
}
});
allMemtablesLiveDataSize = createKeyspaceGauge("AllMemtablesLiveDataSize", new MetricValue()
{
public Long getValue(ColumnFamilyMetrics metric)
{
return metric.allMemtablesLiveDataSize.value();
return metric.allMemtablesLiveDataSize.getValue();
}
});
allMemtablesOnHeapDataSize = createKeyspaceGauge("AllMemtablesOnHeapDataSize", new MetricValue()
{
public Long getValue(ColumnFamilyMetrics metric)
{
return metric.allMemtablesOnHeapSize.value();
return metric.allMemtablesOnHeapSize.getValue();
}
});
allMemtablesOffHeapDataSize = createKeyspaceGauge("AllMemtablesOffHeapDataSize", new MetricValue()
{
public Long getValue(ColumnFamilyMetrics metric)
{
return metric.allMemtablesOffHeapSize.value();
return metric.allMemtablesOffHeapSize.getValue();
}
});
memtableSwitchCount = createKeyspaceGauge("MemtableSwitchCount", new MetricValue()
{
public Long getValue(ColumnFamilyMetrics metric)
{
return metric.memtableSwitchCount.count();
return metric.memtableSwitchCount.getCount();
}
});
pendingCompactions = createKeyspaceGauge("PendingCompactions", new MetricValue()
{
public Long getValue(ColumnFamilyMetrics metric)
{
return (long) metric.pendingCompactions.value();
return (long) metric.pendingCompactions.getValue();
}
});
pendingFlushes = createKeyspaceGauge("PendingFlushes", new MetricValue()
{
public Long getValue(ColumnFamilyMetrics metric)
{
return (long) metric.pendingFlushes.count();
return (long) metric.pendingFlushes.getCount();
}
});
liveDiskSpaceUsed = createKeyspaceGauge("LiveDiskSpaceUsed", new MetricValue()
{
public Long getValue(ColumnFamilyMetrics metric)
{
return metric.liveDiskSpaceUsed.count();
return metric.liveDiskSpaceUsed.getCount();
}
});
totalDiskSpaceUsed = createKeyspaceGauge("TotalDiskSpaceUsed", new MetricValue()
{
public Long getValue(ColumnFamilyMetrics metric)
{
return metric.totalDiskSpaceUsed.count();
return metric.totalDiskSpaceUsed.getCount();
}
});
bloomFilterDiskSpaceUsed = createKeyspaceGauge("BloomFilterDiskSpaceUsed", new MetricValue()
{
public Long getValue(ColumnFamilyMetrics metric)
{
return metric.bloomFilterDiskSpaceUsed.value();
return metric.bloomFilterDiskSpaceUsed.getValue();
}
});
bloomFilterOffHeapMemoryUsed = createKeyspaceGauge("BloomFilterOffHeapMemoryUsed", new MetricValue()
{
public Long getValue(ColumnFamilyMetrics metric)
{
return metric.bloomFilterOffHeapMemoryUsed.value();
return metric.bloomFilterOffHeapMemoryUsed.getValue();
}
});
indexSummaryOffHeapMemoryUsed = createKeyspaceGauge("IndexSummaryOffHeapMemoryUsed", new MetricValue()
{
public Long getValue(ColumnFamilyMetrics metric)
{
return metric.indexSummaryOffHeapMemoryUsed.value();
return metric.indexSummaryOffHeapMemoryUsed.getValue();
}
});
compressionMetadataOffHeapMemoryUsed = createKeyspaceGauge("CompressionMetadataOffHeapMemoryUsed", new MetricValue()
{
public Long getValue(ColumnFamilyMetrics metric)
{
return metric.compressionMetadataOffHeapMemoryUsed.value();
return metric.compressionMetadataOffHeapMemoryUsed.getValue();
}
});
// latency metrics for ColumnFamilyMetrics to update
@ -217,10 +221,10 @@ public class KeyspaceMetrics
writeLatency = new LatencyMetrics(factory, "Write");
rangeLatency = new LatencyMetrics(factory, "Range");
// create histograms for ColumnFamilyMetrics to replicate updates to
sstablesPerReadHistogram = Metrics.newHistogram(factory.createMetricName("SSTablesPerReadHistogram"), true);
tombstoneScannedHistogram = Metrics.newHistogram(factory.createMetricName("TombstoneScannedHistogram"), true);
liveScannedHistogram = Metrics.newHistogram(factory.createMetricName("LiveScannedHistogram"), true);
colUpdateTimeDeltaHistogram = Metrics.newHistogram(factory.createMetricName("ColUpdateTimeDeltaHistogram"), true);
sstablesPerReadHistogram = Metrics.histogram(factory.createMetricName("SSTablesPerReadHistogram"));
tombstoneScannedHistogram = Metrics.histogram(factory.createMetricName("TombstoneScannedHistogram"));
liveScannedHistogram = Metrics.histogram(factory.createMetricName("LiveScannedHistogram"));
colUpdateTimeDeltaHistogram = Metrics.histogram(factory.createMetricName("ColUpdateTimeDeltaHistogram"));
// add manually since histograms do not use createKeyspaceGauge method
allMetrics.addAll(Lists.newArrayList("SSTablesPerReadHistogram", "TombstoneScannedHistogram", "LiveScannedHistogram"));
@ -236,7 +240,7 @@ public class KeyspaceMetrics
{
for(String name : allMetrics)
{
Metrics.defaultRegistry().removeMetric(factory.createMetricName(name));
Metrics.remove(factory.createMetricName(name));
}
// latency metrics contain multiple metrics internally and need to be released manually
readLatency.release();
@ -251,7 +255,7 @@ public class KeyspaceMetrics
{
/**
* get value of a metric
* @param columnfamilymetrics of a column family in this keyspace
* @param metric of a column family in this keyspace
* @return current value of a metric
*/
public Long getValue(ColumnFamilyMetrics metric);
@ -260,15 +264,15 @@ public class KeyspaceMetrics
/**
* Creates a gauge that will sum the current value of a metric for all column families in this keyspace
* @param name
* @param MetricValue
* @param extractor
* @return Gauge&gt;Long> that computes sum of MetricValue.getValue()
*/
private Gauge<Long> createKeyspaceGauge(String name, final MetricValue extractor)
{
allMetrics.add(name);
return Metrics.newGauge(factory.createMetricName(name), new Gauge<Long>()
return Metrics.register(factory.createMetricName(name), new Gauge<Long>()
{
public Long value()
public Long getValue()
{
long sum = 0;
for (ColumnFamilyStore cf : keyspace.getColumnFamilyStores())
@ -289,7 +293,7 @@ public class KeyspaceMetrics
this.keyspaceName = ks.getName();
}
public MetricName createMetricName(String metricName)
public CassandraMetricsRegistry.MetricName createMetricName(String metricName)
{
String groupName = ColumnFamilyMetrics.class.getPackage().getName();
@ -299,7 +303,7 @@ public class KeyspaceMetrics
mbeanName.append(",keyspace=").append(keyspaceName);
mbeanName.append(",name=").append(metricName);
return new MetricName(groupName, "keyspace", metricName, keyspaceName, mbeanName.toString());
return new CassandraMetricsRegistry.MetricName(groupName, "keyspace", metricName, keyspaceName, mbeanName.toString());
}
}
}

View File

@ -20,13 +20,14 @@ package org.apache.cassandra.metrics;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.cassandra.utils.EstimatedHistogram;
import com.codahale.metrics.Counter;
import com.codahale.metrics.Timer;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Counter;
import com.yammer.metrics.core.Timer;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
/**
* Metrics about latencies
@ -44,11 +45,6 @@ public class LatencyMetrics
protected final MetricNameFactory factory;
protected final String namePrefix;
@Deprecated public final EstimatedHistogram totalLatencyHistogram = new EstimatedHistogram();
@Deprecated public final EstimatedHistogram recentLatencyHistogram = new EstimatedHistogram();
protected long lastLatency;
protected long lastOpCount;
/**
* Create LatencyMetrics with given group, type, and scope. Name prefix for each metric will be empty.
*
@ -83,8 +79,8 @@ public class LatencyMetrics
this.factory = factory;
this.namePrefix = namePrefix;
latency = Metrics.newTimer(factory.createMetricName(namePrefix + "Latency"), TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
totalLatency = Metrics.newCounter(factory.createMetricName(namePrefix + "TotalLatency"));
latency = Metrics.timer(factory.createMetricName(namePrefix + "Latency"));
totalLatency = Metrics.counter(factory.createMetricName(namePrefix + "TotalLatency"));
}
/**
@ -106,9 +102,7 @@ public class LatencyMetrics
{
// convert to microseconds. 1 millionth
latency.update(nanos, TimeUnit.NANOSECONDS);
totalLatency.inc(nanos / 1000);
totalLatencyHistogram.add(nanos / 1000);
recentLatencyHistogram.add(nanos / 1000);
totalLatency.inc(nanos);
for(LatencyMetrics parent : parents)
{
parent.addNano(nanos);
@ -117,25 +111,7 @@ public class LatencyMetrics
public void release()
{
Metrics.defaultRegistry().removeMetric(factory.createMetricName(namePrefix + "Latency"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName(namePrefix + "TotalLatency"));
}
@Deprecated
public synchronized double getRecentLatency()
{
long ops = latency.count();
long n = totalLatency.count();
if (ops == lastOpCount)
return 0;
try
{
return ((double) n - lastLatency) / (ops - lastOpCount);
}
finally
{
lastLatency = n;
lastOpCount = ops;
}
Metrics.remove(factory.createMetricName(namePrefix + "Latency"));
Metrics.remove(factory.createMetricName(namePrefix + "TotalLatency"));
}
}

View File

@ -17,7 +17,6 @@
*/
package org.apache.cassandra.metrics;
import com.yammer.metrics.core.MetricName;
public interface MetricNameFactory
{
@ -27,5 +26,5 @@ public interface MetricNameFactory
* @param metricName part of qualified name.
* @return new String with given metric name.
*/
MetricName createMetricName(String metricName);
CassandraMetricsRegistry.MetricName createMetricName(String metricName);
}

View File

@ -17,10 +17,9 @@
*/
package org.apache.cassandra.metrics;
import java.util.concurrent.TimeUnit;
import com.codahale.metrics.Meter;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Meter;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
/**
* Metrics related to Read Repair.
@ -29,10 +28,7 @@ public class ReadRepairMetrics
{
private static final MetricNameFactory factory = new DefaultNameFactory("ReadRepair");
public static final Meter repairedBlocking =
Metrics.newMeter(factory.createMetricName("RepairedBlocking"), "RepairedBlocking", TimeUnit.SECONDS);
public static final Meter repairedBackground =
Metrics.newMeter(factory.createMetricName("RepairedBackground"), "RepairedBackground", TimeUnit.SECONDS);
public static final Meter attempted =
Metrics.newMeter(factory.createMetricName("Attempted"), "Attempted", TimeUnit.SECONDS);
public static final Meter repairedBlocking = Metrics.meter(factory.createMetricName("RepairedBlocking"));
public static final Meter repairedBackground = Metrics.meter(factory.createMetricName("RepairedBackground"));
public static final Meter attempted = Metrics.meter(factory.createMetricName("Attempted"));
}

View File

@ -18,12 +18,12 @@
*/
package org.apache.cassandra.metrics;
import com.yammer.metrics.core.Clock;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import static java.lang.Math.exp;
import com.codahale.metrics.Clock;
/**
* A meter metric which measures mean throughput as well as fifteen-minute and two-hour
@ -52,7 +52,7 @@ public class RestorableMeter
public RestorableMeter() {
this.m15Rate = new RestorableEWMA(TimeUnit.MINUTES.toSeconds(15));
this.m120Rate = new RestorableEWMA(TimeUnit.MINUTES.toSeconds(120));
this.startTime = this.clock.tick();
this.startTime = this.clock.getTick();
this.lastTick = new AtomicLong(startTime);
}
@ -64,7 +64,7 @@ public class RestorableMeter
public RestorableMeter(double lastM15Rate, double lastM120Rate) {
this.m15Rate = new RestorableEWMA(lastM15Rate, TimeUnit.MINUTES.toSeconds(15));
this.m120Rate = new RestorableEWMA(lastM120Rate, TimeUnit.MINUTES.toSeconds(120));
this.startTime = this.clock.tick();
this.startTime = this.clock.getTick();
this.lastTick = new AtomicLong(startTime);
}
@ -73,7 +73,7 @@ public class RestorableMeter
*/
private void tickIfNecessary() {
final long oldTick = lastTick.get();
final long newTick = clock.tick();
final long newTick = clock.getTick();
final long age = newTick - oldTick;
if (age > TICK_INTERVAL) {
final long newIntervalStartTick = newTick - age % TICK_INTERVAL;
@ -139,7 +139,7 @@ public class RestorableMeter
if (count() == 0) {
return 0.0;
} else {
final long elapsed = (clock.tick() - startTime);
final long elapsed = (clock.getTick() - startTime);
return (count() / (double) elapsed) * NANOS_PER_SECOND;
}
}

View File

@ -17,22 +17,24 @@
*/
package org.apache.cassandra.metrics;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Gauge;
import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import org.apache.cassandra.concurrent.SEPExecutor;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
public class SEPMetrics
{
/** Number of active tasks. */
public final Gauge<Integer> activeTasks;
/** Number of tasks that had blocked before being accepted (or rejected). */
public final Gauge<Integer> totalBlocked;
public final Counter totalBlocked;
/**
* Number of tasks currently blocked, waiting to be accepted by
* the executor (because all threads are busy and the backing queue is full).
*/
public final Gauge<Long> currentBlocked;
public final Counter currentBlocked;
/** Number of completed tasks. */
public final Gauge<Long> completedTasks;
/** Number of tasks waiting to be executed. */
@ -52,44 +54,33 @@ public class SEPMetrics
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>()
activeTasks = Metrics.register(factory.createMetricName("ActiveTasks"), new Gauge<Integer>()
{
public Integer value()
public Integer getValue()
{
return executor.getActiveCount();
}
});
pendingTasks = Metrics.newGauge(factory.createMetricName("PendingTasks"), new Gauge<Long>()
pendingTasks = Metrics.register(factory.createMetricName("PendingTasks"), new Gauge<Long>()
{
public Long value()
public Long getValue()
{
return executor.getPendingTasks();
}
});
totalBlocked = Metrics.newGauge(factory.createMetricName("TotalBlockedTasks"), new Gauge<Integer>()
totalBlocked = Metrics.counter(factory.createMetricName("TotalBlockedTasks"));
currentBlocked = Metrics.counter(factory.createMetricName("CurrentlyBlockedTasks"));
completedTasks = Metrics.register(factory.createMetricName("CompletedTasks"), new Gauge<Long>()
{
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()
public Long getValue()
{
return executor.getCompletedTasks();
}
});
maxPoolSize = Metrics.newGauge(factory.createMetricName("MaxPoolSize"), new Gauge<Integer>()
maxPoolSize = Metrics.register(factory.createMetricName("MaxPoolSize"), new Gauge<Integer>()
{
public Integer value()
public Integer getValue()
{
return executor.maxWorkers;
}
@ -98,11 +89,11 @@ public class SEPMetrics
public void release()
{
Metrics.defaultRegistry().removeMetric(factory.createMetricName("ActiveTasks"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("PendingTasks"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("CompletedTasks"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("TotalBlockedTasks"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("CurrentlyBlockedTasks"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("MaxPoolSize"));
Metrics.remove(factory.createMetricName("ActiveTasks"));
Metrics.remove(factory.createMetricName("PendingTasks"));
Metrics.remove(factory.createMetricName("CompletedTasks"));
Metrics.remove(factory.createMetricName("TotalBlockedTasks"));
Metrics.remove(factory.createMetricName("CurrentlyBlockedTasks"));
Metrics.remove(factory.createMetricName("MaxPoolSize"));
}
}

View File

@ -17,8 +17,9 @@
*/
package org.apache.cassandra.metrics;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Counter;
import com.codahale.metrics.Counter;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
/**
* Metrics related to Storage.
@ -27,8 +28,8 @@ public class StorageMetrics
{
private static final MetricNameFactory factory = new DefaultNameFactory("Storage");
public static final Counter load = Metrics.newCounter(factory.createMetricName("Load"));
public static final Counter exceptions = Metrics.newCounter(factory.createMetricName("Exceptions"));
public static final Counter totalHintsInProgress = Metrics.newCounter(factory.createMetricName("TotalHintsInProgress"));
public static final Counter totalHints = Metrics.newCounter(factory.createMetricName("TotalHints"));
public static final Counter load = Metrics.counter(factory.createMetricName("Load"));
public static final Counter exceptions = Metrics.counter(factory.createMetricName("Exceptions"));
public static final Counter totalHintsInProgress = Metrics.counter(factory.createMetricName("TotalHintsInProgress"));
public static final Counter totalHints = Metrics.counter(factory.createMetricName("TotalHints"));
}

View File

@ -20,10 +20,12 @@ package org.apache.cassandra.metrics;
import java.net.InetAddress;
import java.util.concurrent.ConcurrentMap;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Counter;
import com.codahale.metrics.Counter;
import org.cliffc.high_scale_lib.NonBlockingHashMap;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
/**
* Metrics for streaming.
*/
@ -33,9 +35,9 @@ public class StreamingMetrics
private static final ConcurrentMap<InetAddress, StreamingMetrics> instances = new NonBlockingHashMap<InetAddress, StreamingMetrics>();
public static final Counter activeStreamsOutbound = Metrics.newCounter(DefaultNameFactory.createMetricName(TYPE_NAME, "ActiveOutboundStreams", null));
public static final Counter totalIncomingBytes = Metrics.newCounter(DefaultNameFactory.createMetricName(TYPE_NAME, "TotalIncomingBytes", null));
public static final Counter totalOutgoingBytes = Metrics.newCounter(DefaultNameFactory.createMetricName(TYPE_NAME, "TotalOutgoingBytes", null));
public static final Counter activeStreamsOutbound = Metrics.counter(DefaultNameFactory.createMetricName(TYPE_NAME, "ActiveOutboundStreams", null));
public static final Counter totalIncomingBytes = Metrics.counter(DefaultNameFactory.createMetricName(TYPE_NAME, "TotalIncomingBytes", null));
public static final Counter totalOutgoingBytes = Metrics.counter(DefaultNameFactory.createMetricName(TYPE_NAME, "TotalOutgoingBytes", null));
public final Counter incomingBytes;
public final Counter outgoingBytes;
@ -53,7 +55,7 @@ public class StreamingMetrics
public StreamingMetrics(final InetAddress peer)
{
MetricNameFactory factory = new DefaultNameFactory("Streaming", peer.getHostAddress().replaceAll(":", "."));
incomingBytes = Metrics.newCounter(factory.createMetricName("IncomingBytes"));
outgoingBytes= Metrics.newCounter(factory.createMetricName("OutgoingBytes"));
incomingBytes = Metrics.counter(factory.createMetricName("IncomingBytes"));
outgoingBytes= Metrics.counter(factory.createMetricName("OutgoingBytes"));
}
}

View File

@ -17,8 +17,6 @@
*/
package org.apache.cassandra.metrics;
import com.yammer.metrics.core.MetricName;
class ThreadPoolMetricNameFactory implements MetricNameFactory
{
private final String type;
@ -32,7 +30,7 @@ class ThreadPoolMetricNameFactory implements MetricNameFactory
this.poolName = poolName;
}
public MetricName createMetricName(String metricName)
public CassandraMetricsRegistry.MetricName createMetricName(String metricName)
{
String groupName = ThreadPoolMetrics.class.getPackage().getName();
StringBuilder mbeanName = new StringBuilder();
@ -42,6 +40,6 @@ class ThreadPoolMetricNameFactory implements MetricNameFactory
mbeanName.append(",scope=").append(poolName);
mbeanName.append(",name=").append(metricName);
return new MetricName(groupName, type, metricName, path + "." + poolName, mbeanName.toString());
return new CassandraMetricsRegistry.MetricName(groupName, type, metricName, path + "." + poolName, mbeanName.toString());
}
}

View File

@ -19,8 +19,16 @@ package org.apache.cassandra.metrics;
import java.util.concurrent.ThreadPoolExecutor;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.*;
import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.JmxReporter;
import javax.management.JMX;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
/**
* Metrics for {@link ThreadPoolExecutor}.
@ -56,32 +64,32 @@ public class ThreadPoolMetrics
{
this.factory = new ThreadPoolMetricNameFactory("ThreadPools", path, poolName);
activeTasks = Metrics.newGauge(factory.createMetricName("ActiveTasks"), new Gauge<Integer>()
activeTasks = Metrics.register(factory.createMetricName("ActiveTasks"), new Gauge<Integer>()
{
public Integer value()
public Integer getValue()
{
return executor.getActiveCount();
}
});
totalBlocked = Metrics.newCounter(factory.createMetricName("TotalBlockedTasks"));
currentBlocked = Metrics.newCounter(factory.createMetricName("CurrentlyBlockedTasks"));
completedTasks = Metrics.newGauge(factory.createMetricName("CompletedTasks"), new Gauge<Long>()
totalBlocked = Metrics.counter(factory.createMetricName("TotalBlockedTasks"));
currentBlocked = Metrics.counter(factory.createMetricName("CurrentlyBlockedTasks"));
completedTasks = Metrics.register(factory.createMetricName("CompletedTasks"), new Gauge<Long>()
{
public Long value()
public Long getValue()
{
return executor.getCompletedTaskCount();
}
});
pendingTasks = Metrics.newGauge(factory.createMetricName("PendingTasks"), new Gauge<Long>()
pendingTasks = Metrics.register(factory.createMetricName("PendingTasks"), new Gauge<Long>()
{
public Long value()
public Long getValue()
{
return executor.getTaskCount() - executor.getCompletedTaskCount();
}
});
maxPoolSize = Metrics.newGauge(factory.createMetricName("MaxPoolSize"), new Gauge<Integer>()
maxPoolSize = Metrics.register(factory.createMetricName("MaxPoolSize"), new Gauge<Integer>()
{
public Integer value()
public Integer getValue()
{
return executor.getMaximumPoolSize();
}
@ -90,11 +98,41 @@ public class ThreadPoolMetrics
public void release()
{
Metrics.defaultRegistry().removeMetric(factory.createMetricName("ActiveTasks"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("PendingTasks"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("CompletedTasks"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("TotalBlockedTasks"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("CurrentlyBlockedTasks"));
Metrics.defaultRegistry().removeMetric(factory.createMetricName("MaxPoolSize"));
Metrics.remove(factory.createMetricName("ActiveTasks"));
Metrics.remove(factory.createMetricName("PendingTasks"));
Metrics.remove(factory.createMetricName("CompletedTasks"));
Metrics.remove(factory.createMetricName("TotalBlockedTasks"));
Metrics.remove(factory.createMetricName("CurrentlyBlockedTasks"));
Metrics.remove(factory.createMetricName("MaxPoolSize"));
}
public static Object getJmxMetric(MBeanServerConnection mbeanServerConn, String jmxPath, String poolName, String metricName)
{
String name = String.format("org.apache.cassandra.metrics:type=ThreadPools,path=%s,scope=%s,name=%s", jmxPath, poolName, metricName);
try
{
ObjectName oName = new ObjectName(name);
switch (metricName)
{
case "ActiveTasks":
case "PendingTasks":
case "CompletedTasks":
return JMX.newMBeanProxy(mbeanServerConn, oName, JmxReporter.JmxGaugeMBean.class).getValue();
case "TotalBlockedTasks":
case "CurrentlyBlockedTasks":
return JMX.newMBeanProxy(mbeanServerConn, oName, JmxReporter.JmxCounterMBean.class).getCount();
default:
throw new AssertionError("Unknown metric name " + metricName);
}
}
catch (Throwable e)
{
throw new RuntimeException("Error reading: " + name, e);
}
}
}

View File

@ -879,7 +879,7 @@ public final class MessagingService implements MessagingServiceMBean
boolean logTpstats = false;
for (Map.Entry<Verb, DroppedMessageMetrics> entry : droppedMessages.entrySet())
{
int dropped = (int) entry.getValue().dropped.count();
int dropped = (int) entry.getValue().dropped.getCount();
Verb verb = entry.getKey();
int recent = dropped - lastDroppedInternal.get(verb);
if (recent > 0)
@ -1018,26 +1018,14 @@ public final class MessagingService implements MessagingServiceMBean
{
Map<String, Integer> map = new HashMap<String, Integer>(droppedMessages.size());
for (Map.Entry<Verb, DroppedMessageMetrics> entry : droppedMessages.entrySet())
map.put(entry.getKey().toString(), (int) entry.getValue().dropped.count());
map.put(entry.getKey().toString(), (int) entry.getValue().dropped.getCount());
return map;
}
public Map<String, Integer> getRecentlyDroppedMessages()
{
Map<String, Integer> map = new HashMap<String, Integer>(droppedMessages.size());
for (Map.Entry<Verb, DroppedMessageMetrics> entry : droppedMessages.entrySet())
map.put(entry.getKey().toString(), entry.getValue().getRecentlyDropped());
return map;
}
public long getTotalTimeouts()
{
return ConnectionMetrics.totalTimeouts.count();
}
public long getRecentTotalTimouts()
{
return ConnectionMetrics.getRecentTotalTimeout();
return ConnectionMetrics.totalTimeouts.getCount();
}
public Map<String, Long> getTimeoutsPerHost()
@ -1051,16 +1039,4 @@ public final class MessagingService implements MessagingServiceMBean
}
return result;
}
public Map<String, Long> getRecentTimeoutsPerHost()
{
Map<String, Long> result = new HashMap<String, Long>(connectionManagers.size());
for (Map.Entry<InetAddress, OutboundTcpConnectionPool> entry: connectionManagers.entrySet())
{
String ip = entry.getKey().getHostAddress();
long recent = entry.getValue().getRecentTimeouts();
result.put(ip, recent);
}
return result;
}
}

View File

@ -58,11 +58,6 @@ public interface MessagingServiceMBean
*/
public Map<String, Integer> getDroppedMessages();
/**
* dropped message counts since last called
*/
public Map<String, Integer> getRecentlyDroppedMessages();
/**
* Total number of timeouts happened on this node
*/
@ -73,15 +68,5 @@ public interface MessagingServiceMBean
*/
public Map<String, Long> getTimeoutsPerHost();
/**
* Number of timeouts since last check.
*/
public long getRecentTotalTimouts();
/**
* Number of timeouts since last check per host.
*/
public Map<String, Long> getRecentTimeoutsPerHost();
public int getVersion(String address) throws UnknownHostException;
}

View File

@ -101,13 +101,9 @@ public class OutboundTcpConnectionPool
public long getTimeouts()
{
return metrics.timeouts.count();
return metrics.timeouts.getCount();
}
public long getRecentTimeouts()
{
return metrics.getRecentTimeout();
}
public void incrementTimeout()
{

View File

@ -145,8 +145,6 @@ public class RoundRobinScheduler implements IRequestScheduler
weightedQueue = queues.putIfAbsent(id, maybenew);
if (weightedQueue == null)
{
// created new queue: register for monitoring
maybenew.register();
return maybenew;
}

View File

@ -26,7 +26,7 @@ import javax.management.ObjectName;
import org.apache.cassandra.metrics.LatencyMetrics;
class WeightedQueue implements WeightedQueueMBean
class WeightedQueue
{
private final LatencyMetrics metric;
@ -41,20 +41,6 @@ class WeightedQueue implements WeightedQueueMBean
this.metric = new LatencyMetrics("scheduler", "WeightedQueue", key);
}
public void register()
{
// expose monitoring data
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
try
{
mbs.registerMBean(this, new ObjectName("org.apache.cassandra.scheduler:type=WeightedQueue,queue=" + key));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
public void put(Thread t, long timeoutMS) throws InterruptedException, TimeoutException
{
if (!queue.offer(new WeightedQueue.Entry(t), timeoutMS, TimeUnit.MILLISECONDS))
@ -85,31 +71,4 @@ class WeightedQueue implements WeightedQueueMBean
this.thread = thread;
}
}
/** MBean related methods */
public long getOperations()
{
return metric.latency.count();
}
public long getTotalLatencyMicros()
{
return metric.totalLatency.count();
}
public double getRecentLatencyMicros()
{
return metric.getRecentLatency();
}
public long[] getTotalLatencyHistogramMicros()
{
return metric.totalLatencyHistogram.getBuckets(false);
}
public long[] getRecentLatencyHistogramMicros()
{
return metric.recentLatencyHistogram.getBuckets(true);
}
}

View File

@ -1,32 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.scheduler;
/**
* Exposes client request scheduling metrics for a particular scheduler queue.
* @see org.apache.cassandra.metrics.LatencyMetrics
*/
@Deprecated
public interface WeightedQueueMBean
{
public long getOperations();
public long getTotalLatencyMicros();
public double getRecentLatencyMicros();
public long[] getTotalLatencyHistogramMicros();
public long[] getRecentLatencyHistogramMicros();
}

View File

@ -180,35 +180,6 @@ public class CacheService implements CacheServiceMBean
return cache;
}
public long getKeyCacheHits()
{
return keyCache.getMetrics().hits.count();
}
public long getRowCacheHits()
{
return rowCache.getMetrics().hits.count();
}
public long getKeyCacheRequests()
{
return keyCache.getMetrics().requests.count();
}
public long getRowCacheRequests()
{
return rowCache.getMetrics().requests.count();
}
public double getKeyCacheRecentHitRate()
{
return keyCache.getMetrics().getRecentHitRate();
}
public double getRowCacheRecentHitRate()
{
return rowCache.getMetrics().getRecentHitRate();
}
public int getRowCacheSavePeriodInSeconds()
{
@ -339,15 +310,8 @@ public class CacheService implements CacheServiceMBean
counterCache.clear();
}
public long getRowCacheCapacityInBytes()
{
return rowCache.getMetrics().capacity.value();
}
public long getRowCacheCapacityInMB()
{
return getRowCacheCapacityInBytes() / 1024 / 1024;
}
public void setRowCacheCapacityInMB(long capacity)
{
@ -357,15 +321,6 @@ public class CacheService implements CacheServiceMBean
rowCache.setCapacity(capacity * 1024 * 1024);
}
public long getKeyCacheCapacityInBytes()
{
return keyCache.getMetrics().capacity.value();
}
public long getKeyCacheCapacityInMB()
{
return getKeyCacheCapacityInBytes() / 1024 / 1024;
}
public void setKeyCacheCapacityInMB(long capacity)
{
@ -383,26 +338,6 @@ public class CacheService implements CacheServiceMBean
counterCache.setCapacity(capacity * 1024 * 1024);
}
public long getRowCacheSize()
{
return rowCache.getMetrics().size.value();
}
public long getRowCacheEntries()
{
return rowCache.size();
}
public long getKeyCacheSize()
{
return keyCache.getMetrics().size.value();
}
public long getKeyCacheEntries()
{
return keyCache.size();
}
public void saveCaches() throws ExecutionException, InterruptedException
{
List<Future<?>> futures = new ArrayList<>(3);

View File

@ -64,90 +64,4 @@ public interface CacheServiceMBean
* @throws InterruptedException when a thread is waiting, sleeping, or otherwise occupied, and the thread is interrupted, either before or during the activity.
*/
public void saveCaches() throws ExecutionException, InterruptedException;
//
// remaining methods are provided for backwards compatibility; modern clients should use CacheMetrics instead
//
/**
* @see org.apache.cassandra.metrics.CacheMetrics#hits
*/
@Deprecated
public long getKeyCacheHits();
/**
* @see org.apache.cassandra.metrics.CacheMetrics#hits
*/
@Deprecated
public long getRowCacheHits();
/**
* @see org.apache.cassandra.metrics.CacheMetrics#requests
*/
@Deprecated
public long getKeyCacheRequests();
/**
* @see org.apache.cassandra.metrics.CacheMetrics#requests
*/
@Deprecated
public long getRowCacheRequests();
/**
* @see org.apache.cassandra.metrics.CacheMetrics#hitRate
*/
@Deprecated
public double getKeyCacheRecentHitRate();
/**
* @see org.apache.cassandra.metrics.CacheMetrics#hitRate
*/
@Deprecated
public double getRowCacheRecentHitRate();
/**
* @see org.apache.cassandra.metrics.CacheMetrics#capacity
*/
@Deprecated
public long getRowCacheCapacityInMB();
/**
* @see org.apache.cassandra.metrics.CacheMetrics#capacity
*/
@Deprecated
public long getRowCacheCapacityInBytes();
/**
* @see org.apache.cassandra.metrics.CacheMetrics#capacity
*/
@Deprecated
public long getKeyCacheCapacityInMB();
/**
* @see org.apache.cassandra.metrics.CacheMetrics#capacity
*/
@Deprecated
public long getKeyCacheCapacityInBytes();
/**
* @see org.apache.cassandra.metrics.CacheMetrics#size
*/
@Deprecated
public long getRowCacheSize();
/**
* @see org.apache.cassandra.metrics.CacheMetrics#entries
*/
@Deprecated
public long getRowCacheEntries();
/**
* @see org.apache.cassandra.metrics.CacheMetrics#size
*/
@Deprecated
public long getKeyCacheSize();
/**
* @see org.apache.cassandra.metrics.CacheMetrics#entries
*/
@Deprecated
public long getKeyCacheEntries();
}

View File

@ -58,6 +58,7 @@ import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.io.FSError;
import org.apache.cassandra.io.sstable.CorruptSSTableException;
import org.apache.cassandra.io.util.FileUtils;
import org.apache.cassandra.metrics.CassandraMetricsRegistry;
import org.apache.cassandra.metrics.StorageMetrics;
import org.apache.cassandra.thrift.ThriftServer;
import org.apache.cassandra.tracing.Tracing;
@ -558,9 +559,9 @@ public class CassandraDaemon
while (numOkay < GOSSIP_SETTLE_POLL_SUCCESSES_REQUIRED)
{
Uninterruptibles.sleepUninterruptibly(GOSSIP_SETTLE_POLL_INTERVAL_MS, TimeUnit.MILLISECONDS);
long completed = gossipStage.getCompletedTasks();
long active = gossipStage.getActiveCount();
long pending = gossipStage.getPendingTasks();
long completed = gossipStage.metrics.completedTasks.getValue();
long active = gossipStage.metrics.activeTasks.getValue();
long pending = gossipStage.metrics.pendingTasks.getValue();
totalPolls++;
if (active == 0 && pending == 0)
{

View File

@ -23,6 +23,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import org.apache.cassandra.metrics.StorageMetrics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -89,7 +90,7 @@ public class LoadBroadcaster implements IEndpointStateChangeSubscriber
if (logger.isDebugEnabled())
logger.debug("Disseminating load info ...");
Gossiper.instance.addLocalApplicationState(ApplicationState.LOAD,
StorageService.instance.valueFactory.load(StorageService.instance.getLoad()));
StorageService.instance.valueFactory.load(StorageMetrics.load.getCount()));
}
};
ScheduledExecutors.scheduledTasks.scheduleWithFixedDelay(runnable, 2 * Gossiper.intervalInMillis, BROADCAST_INTERVAL, TimeUnit.MILLISECONDS);

View File

@ -568,7 +568,6 @@ public class StorageProxy implements StorageProxyMBean
else
{
writeMetrics.timeouts.mark();
ClientRequestMetrics.writeTimeouts.inc();
Tracing.trace("Write timeout; received {} of {} required replies", ex.received, ex.blockFor);
throw ex;
}
@ -576,13 +575,12 @@ public class StorageProxy implements StorageProxyMBean
catch (UnavailableException e)
{
writeMetrics.unavailables.mark();
ClientRequestMetrics.writeUnavailables.inc();
Tracing.trace("Unavailable");
throw e;
}
catch (OverloadedException e)
{
ClientRequestMetrics.writeUnavailables.inc();
writeMetrics.unavailables.mark();
Tracing.trace("Overloaded");
throw e;
}
@ -651,14 +649,12 @@ public class StorageProxy implements StorageProxyMBean
catch (UnavailableException e)
{
writeMetrics.unavailables.mark();
ClientRequestMetrics.writeUnavailables.inc();
Tracing.trace("Unavailable");
throw e;
}
catch (WriteTimeoutException e)
{
writeMetrics.timeouts.mark();
ClientRequestMetrics.writeTimeouts.inc();
Tracing.trace("Write timeout; received {} of {} required replies", e.received, e.blockFor);
throw e;
}
@ -864,10 +860,10 @@ public class StorageProxy implements StorageProxyMBean
// The idea is that if we have over maxHintsInProgress hints in flight, this is probably due to
// a small number of nodes causing problems, so we should avoid shutting down writes completely to
// healthy nodes. Any node with no hintsInProgress is considered healthy.
if (StorageMetrics.totalHintsInProgress.count() > maxHintsInProgress
if (StorageMetrics.totalHintsInProgress.getCount() > maxHintsInProgress
&& (getHintsInProgressFor(destination).get() > 0 && shouldHint(destination)))
{
throw new OverloadedException("Too many in flight hints: " + StorageMetrics.totalHintsInProgress.count());
throw new OverloadedException("Too many in flight hints: " + StorageMetrics.totalHintsInProgress.getCount());
}
if (FailureDetector.instance.isAlive(destination))
@ -1184,7 +1180,6 @@ public class StorageProxy implements StorageProxyMBean
if (StorageService.instance.isBootstrapMode() && !systemKeyspaceQuery(commands))
{
readMetrics.unavailables.mark();
ClientRequestMetrics.readUnavailables.inc();
throw new IsBootstrappingException();
}
@ -1233,21 +1228,18 @@ public class StorageProxy implements StorageProxyMBean
catch (UnavailableException e)
{
readMetrics.unavailables.mark();
ClientRequestMetrics.readUnavailables.inc();
casReadMetrics.unavailables.mark();
throw e;
}
catch (ReadTimeoutException e)
{
readMetrics.timeouts.mark();
ClientRequestMetrics.readTimeouts.inc();
casReadMetrics.timeouts.mark();
throw e;
}
catch (ReadFailureException e)
{
readMetrics.failures.mark();
ClientRequestMetrics.readFailures.inc();
casReadMetrics.failures.mark();
throw e;
}
@ -1277,19 +1269,16 @@ public class StorageProxy implements StorageProxyMBean
catch (UnavailableException e)
{
readMetrics.unavailables.mark();
ClientRequestMetrics.readUnavailables.inc();
throw e;
}
catch (ReadTimeoutException e)
{
readMetrics.timeouts.mark();
ClientRequestMetrics.readTimeouts.inc();
throw e;
}
catch (ReadFailureException e)
{
readMetrics.failures.mark();
ClientRequestMetrics.readFailures.inc();
throw e;
}
finally
@ -1989,81 +1978,6 @@ public class StorageProxy implements StorageProxyMBean
return ranges;
}
public long getReadOperations()
{
return readMetrics.latency.count();
}
public long getTotalReadLatencyMicros()
{
return readMetrics.totalLatency.count();
}
public double getRecentReadLatencyMicros()
{
return readMetrics.getRecentLatency();
}
public long[] getTotalReadLatencyHistogramMicros()
{
return readMetrics.totalLatencyHistogram.getBuckets(false);
}
public long[] getRecentReadLatencyHistogramMicros()
{
return readMetrics.recentLatencyHistogram.getBuckets(true);
}
public long getRangeOperations()
{
return rangeMetrics.latency.count();
}
public long getTotalRangeLatencyMicros()
{
return rangeMetrics.totalLatency.count();
}
public double getRecentRangeLatencyMicros()
{
return rangeMetrics.getRecentLatency();
}
public long[] getTotalRangeLatencyHistogramMicros()
{
return rangeMetrics.totalLatencyHistogram.getBuckets(false);
}
public long[] getRecentRangeLatencyHistogramMicros()
{
return rangeMetrics.recentLatencyHistogram.getBuckets(true);
}
public long getWriteOperations()
{
return writeMetrics.latency.count();
}
public long getTotalWriteLatencyMicros()
{
return writeMetrics.totalLatency.count();
}
public double getRecentWriteLatencyMicros()
{
return writeMetrics.getRecentLatency();
}
public long[] getTotalWriteLatencyHistogramMicros()
{
return writeMetrics.totalLatencyHistogram.getBuckets(false);
}
public long[] getRecentWriteLatencyHistogramMicros()
{
return writeMetrics.recentLatencyHistogram.getBuckets(true);
}
public boolean getHintedHandoffEnabled()
{
return DatabaseDescriptor.hintedHandoffEnabled();
@ -2291,7 +2205,7 @@ public class StorageProxy implements StorageProxyMBean
public long getTotalHints()
{
return StorageMetrics.totalHints.count();
return StorageMetrics.totalHints.getCount();
}
public int getMaxHintsInProgress()
@ -2306,7 +2220,7 @@ public class StorageProxy implements StorageProxyMBean
public int getHintsInProgress()
{
return (int) StorageMetrics.totalHintsInProgress.count();
return (int) StorageMetrics.totalHintsInProgress.getCount();
}
public void verifyNoHintsInProgress()
@ -2339,14 +2253,14 @@ public class StorageProxy implements StorageProxyMBean
public long getReadRepairAttempted() {
return ReadRepairMetrics.attempted.count();
return ReadRepairMetrics.attempted.getCount();
}
public long getReadRepairRepairedBlocking() {
return ReadRepairMetrics.repairedBlocking.count();
return ReadRepairMetrics.repairedBlocking.getCount();
}
public long getReadRepairRepairedBackground() {
return ReadRepairMetrics.repairedBackground.count();
return ReadRepairMetrics.repairedBackground.getCount();
}
}

View File

@ -23,54 +23,6 @@ import java.util.Set;
public interface StorageProxyMBean
{
/**
* @see org.apache.cassandra.metrics.LatencyMetrics#lastOpCount
*/
@Deprecated
public long getReadOperations();
/**
* @see org.apache.cassandra.metrics.LatencyMetrics#totalLatencyHistogram
*/
@Deprecated
public long getTotalReadLatencyMicros();
/**
* @see org.apache.cassandra.metrics.LatencyMetrics#recentLatencyHistogram
*/
@Deprecated
public double getRecentReadLatencyMicros();
/**
* @see org.apache.cassandra.metrics.LatencyMetrics#totalLatencyHistogram
*/
@Deprecated
public long[] getTotalReadLatencyHistogramMicros();
/**
* @see org.apache.cassandra.metrics.LatencyMetrics#recentLatencyHistogram
*/
@Deprecated
public long[] getRecentReadLatencyHistogramMicros();
@Deprecated
public long getRangeOperations();
@Deprecated
public long getTotalRangeLatencyMicros();
@Deprecated
public double getRecentRangeLatencyMicros();
@Deprecated
public long[] getTotalRangeLatencyHistogramMicros();
@Deprecated
public long[] getRecentRangeLatencyHistogramMicros();
@Deprecated
public long getWriteOperations();
@Deprecated
public long getTotalWriteLatencyMicros();
@Deprecated
public double getRecentWriteLatencyMicros();
@Deprecated
public long[] getTotalWriteLatencyHistogramMicros();
@Deprecated
public long[] getRecentWriteLatencyHistogramMicros();
public long getTotalHints();
public boolean getHintedHandoffEnabled();
public Set<String> getHintedHandoffEnabledByDC();

View File

@ -2009,24 +2009,10 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
onDead(endpoint, state);
}
/** raw load value */
public double getLoad()
{
double bytes = 0;
for (String keyspaceName : Schema.instance.getKeyspaces())
{
Keyspace keyspace = Schema.instance.getKeyspaceInstance(keyspaceName);
if (keyspace == null)
continue;
for (ColumnFamilyStore cfs : keyspace.getColumnFamilyStores())
bytes += cfs.getLiveDiskSpaceUsed();
}
return bytes;
}
public String getLoadString()
{
return FileUtils.stringifyFileSize(getLoad());
return FileUtils.stringifyFileSize(StorageMetrics.load.getCount());
}
public Map<String, String> getLoadMap()
@ -4113,11 +4099,6 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
return loader.stream();
}
public int getExceptionCount()
{
return (int)StorageMetrics.exceptions.count();
}
public void rescheduleFailedDeletions()
{
SSTableDeletingTask.rescheduleFailedTasks();

View File

@ -161,13 +161,6 @@ public interface StorageServiceMBean extends NotificationEmitter
/** Retrieve the mapping of endpoint to host ID */
public Map<String, String> getHostIdMap();
/**
* Numeric load value.
* @see org.apache.cassandra.metrics.StorageMetrics#load
*/
@Deprecated
public double getLoad();
/** Human-readable load value */
public String getLoadString();
@ -441,9 +434,6 @@ public interface StorageServiceMBean extends NotificationEmitter
public void joinRing() throws IOException;
public boolean isJoined();
@Deprecated
public int getExceptionCount();
public void setStreamThroughputMbPerSec(int value);
public int getStreamThroughputMbPerSec();

View File

@ -538,7 +538,7 @@ public class CassandraServer implements Cassandra.Iface
// request by page if this is a large row
if (cfs.getMeanColumns() > 0)
{
int averageColumnSize = (int) (cfs.getMeanRowSize() / cfs.getMeanColumns());
int averageColumnSize = (int) (cfs.metric.meanRowSize.getValue() / cfs.getMeanColumns());
pageSize = Math.min(COUNT_PAGE_SIZE, 4 * 1024 * 1024 / averageColumnSize);
pageSize = Math.max(2, pageSize);
logger.debug("average row column size is {}; using pageSize of {}", averageColumnSize, pageSize);

View File

@ -27,7 +27,10 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.management.*;
import javax.management.openmbean.CompositeData;
import javax.management.remote.JMXConnector;
@ -39,8 +42,7 @@ import com.google.common.base.Function;
import com.google.common.collect.*;
import com.google.common.util.concurrent.Uninterruptibles;
import com.yammer.metrics.reporting.JmxReporter;
import org.apache.cassandra.concurrent.JMXEnabledThreadPoolExecutorMBean;
import org.apache.cassandra.concurrent.Stage;
import org.apache.cassandra.db.ColumnFamilyStoreMBean;
import org.apache.cassandra.db.HintedHandOffManager;
import org.apache.cassandra.db.HintedHandOffManagerMBean;
@ -51,7 +53,9 @@ import org.apache.cassandra.gms.FailureDetectorMBean;
import org.apache.cassandra.gms.Gossiper;
import org.apache.cassandra.gms.GossiperMBean;
import org.apache.cassandra.locator.EndpointSnitchInfoMBean;
import org.apache.cassandra.metrics.ColumnFamilyMetrics.Sampler;
import org.apache.cassandra.metrics.CassandraMetricsRegistry;
import org.apache.cassandra.metrics.StorageMetrics;
import org.apache.cassandra.metrics.ThreadPoolMetrics;
import org.apache.cassandra.net.MessagingService;
import org.apache.cassandra.net.MessagingServiceMBean;
import org.apache.cassandra.service.*;
@ -59,6 +63,8 @@ import org.apache.cassandra.streaming.StreamState;
import org.apache.cassandra.streaming.StreamManagerMBean;
import org.apache.cassandra.streaming.management.StreamStateCompositeData;
import org.apache.cassandra.metrics.ColumnFamilyMetrics.Sampler;
/**
* JMX client operations for Cassandra.
*/
@ -525,22 +531,6 @@ public class NodeProbe implements AutoCloseable
gossProxy.assassinateEndpoint(address);
}
public Iterator<Map.Entry<String, JMXEnabledThreadPoolExecutorMBean>> getThreadPoolMBeanProxies()
{
try
{
return new ThreadPoolProxyMBeanIterator(mbeanServerConn);
}
catch (MalformedObjectNameException e)
{
throw new RuntimeException("Invalid ObjectName? Please report this as a bug.", e);
}
catch (IOException e)
{
throw new RuntimeException("Could not retrieve list of stat mbeans.", e);
}
}
/**
* Set the compaction threshold
*
@ -879,7 +869,7 @@ public class NodeProbe implements AutoCloseable
public int getExceptionCount()
{
return ssProxy.getExceptionCount();
return (int)StorageMetrics.exceptions.getCount();
}
public Map<String, Integer> getDroppedMessages()
@ -980,12 +970,12 @@ public class NodeProbe implements AutoCloseable
case "Size":
return JMX.newMBeanProxy(mbeanServerConn,
new ObjectName("org.apache.cassandra.metrics:type=Cache,scope=" + cacheType + ",name=" + metricName),
JmxReporter.GaugeMBean.class).getValue();
CassandraMetricsRegistry.JmxGaugeMBean.class).getValue();
case "Requests":
case "Hits":
return JMX.newMBeanProxy(mbeanServerConn,
new ObjectName("org.apache.cassandra.metrics:type=Cache,scope=" + cacheType + ",name=" + metricName),
JmxReporter.MeterMBean.class).getCount();
CassandraMetricsRegistry.JmxMeterMBean.class).getCount();
default:
throw new RuntimeException("Unknown cache metric name.");
@ -997,6 +987,11 @@ public class NodeProbe implements AutoCloseable
}
}
public Object getThreadPoolMetric(Stage stage, String metricName)
{
return ThreadPoolMetrics.getJmxMetric(mbeanServerConn, stage.getJmxType(), stage.getJmxName(), metricName);
}
/**
* Retrieve ColumnFamily metrics
* @param ks Keyspace for which stats are to be displayed.
@ -1031,7 +1026,7 @@ public class NodeProbe implements AutoCloseable
case "RecentBloomFilterFalsePositives":
case "RecentBloomFilterFalseRatio":
case "SnapshotsSize":
return JMX.newMBeanProxy(mbeanServerConn, oName, JmxReporter.GaugeMBean.class).getValue();
return JMX.newMBeanProxy(mbeanServerConn, oName, CassandraMetricsRegistry.JmxGaugeMBean.class).getValue();
case "LiveDiskSpaceUsed":
case "MemtableSwitchCount":
case "SpeculativeRetries":
@ -1039,16 +1034,16 @@ public class NodeProbe implements AutoCloseable
case "WriteTotalLatency":
case "ReadTotalLatency":
case "PendingFlushes":
return JMX.newMBeanProxy(mbeanServerConn, oName, JmxReporter.CounterMBean.class).getCount();
case "ReadLatency":
return JMX.newMBeanProxy(mbeanServerConn, oName, CassandraMetricsRegistry.JmxCounterMBean.class).getCount();
case "CoordinatorReadLatency":
case "CoordinatorScanLatency":
case "ReadLatency":
case "WriteLatency":
return JMX.newMBeanProxy(mbeanServerConn, oName, JmxReporter.TimerMBean.class);
return JMX.newMBeanProxy(mbeanServerConn, oName, CassandraMetricsRegistry.JmxTimerMBean.class);
case "LiveScannedHistogram":
case "SSTablesPerReadHistogram":
case "TombstoneScannedHistogram":
return JMX.newMBeanProxy(mbeanServerConn, oName, JmxReporter.HistogramMBean.class);
return JMX.newMBeanProxy(mbeanServerConn, oName, CassandraMetricsRegistry.JmxHistogramMBean.class);
default:
throw new RuntimeException("Unknown table metric.");
}
@ -1063,13 +1058,13 @@ public class NodeProbe implements AutoCloseable
* Retrieve Proxy metrics
* @param scope RangeSlice, Read or Write
*/
public JmxReporter.TimerMBean getProxyMetric(String scope)
public CassandraMetricsRegistry.JmxTimerMBean getProxyMetric(String scope)
{
try
{
return JMX.newMBeanProxy(mbeanServerConn,
new ObjectName("org.apache.cassandra.metrics:type=ClientRequest,scope=" + scope + ",name=Latency"),
JmxReporter.TimerMBean.class);
CassandraMetricsRegistry.JmxTimerMBean.class);
}
catch (MalformedObjectNameException e)
{
@ -1090,16 +1085,16 @@ public class NodeProbe implements AutoCloseable
case "BytesCompacted":
return JMX.newMBeanProxy(mbeanServerConn,
new ObjectName("org.apache.cassandra.metrics:type=Compaction,name=" + metricName),
JmxReporter.CounterMBean.class);
CassandraMetricsRegistry.JmxCounterMBean.class);
case "CompletedTasks":
case "PendingTasks":
return JMX.newMBeanProxy(mbeanServerConn,
new ObjectName("org.apache.cassandra.metrics:type=Compaction,name=" + metricName),
JmxReporter.GaugeMBean.class).getValue();
CassandraMetricsRegistry.JmxGaugeMBean.class).getValue();
case "TotalCompactionsCompleted":
return JMX.newMBeanProxy(mbeanServerConn,
new ObjectName("org.apache.cassandra.metrics:type=Compaction,name=" + metricName),
JmxReporter.MeterMBean.class);
CassandraMetricsRegistry.JmxMeterMBean.class);
default:
throw new RuntimeException("Unknown compaction metric.");
}
@ -1120,7 +1115,7 @@ public class NodeProbe implements AutoCloseable
{
return JMX.newMBeanProxy(mbeanServerConn,
new ObjectName("org.apache.cassandra.metrics:type=Storage,name=" + metricName),
JmxReporter.CounterMBean.class).getCount();
CassandraMetricsRegistry.JmxCounterMBean.class).getCount();
}
catch (MalformedObjectNameException e)
{
@ -1128,7 +1123,18 @@ public class NodeProbe implements AutoCloseable
}
}
public double[] metricPercentilesAsArray(JmxReporter.HistogramMBean metric)
public double[] metricPercentilesAsArray(CassandraMetricsRegistry.JmxHistogramMBean metric)
{
return new double[]{ metric.get50thPercentile(),
metric.get75thPercentile(),
metric.get95thPercentile(),
metric.get98thPercentile(),
metric.get99thPercentile(),
metric.getMin(),
metric.getMax()};
}
public double[] metricPercentilesAsArray(CassandraMetricsRegistry.JmxTimerMBean metric)
{
return new double[]{ metric.get50thPercentile(),
metric.get75thPercentile(),
@ -1242,36 +1248,3 @@ class ColumnFamilyStoreMBeanIterator implements Iterator<Map.Entry<String, Colum
throw new UnsupportedOperationException();
}
}
class ThreadPoolProxyMBeanIterator implements Iterator<Map.Entry<String, JMXEnabledThreadPoolExecutorMBean>>
{
private final Iterator<ObjectName> resIter;
private final MBeanServerConnection mbeanServerConn;
public ThreadPoolProxyMBeanIterator(MBeanServerConnection mbeanServerConn)
throws MalformedObjectNameException, NullPointerException, IOException
{
Set<ObjectName> requests = mbeanServerConn.queryNames(new ObjectName("org.apache.cassandra.request:type=*"), null);
Set<ObjectName> internal = mbeanServerConn.queryNames(new ObjectName("org.apache.cassandra.internal:type=*"), null);
resIter = Iterables.concat(requests, internal).iterator();
this.mbeanServerConn = mbeanServerConn;
}
public boolean hasNext()
{
return resIter.hasNext();
}
public Map.Entry<String, JMXEnabledThreadPoolExecutorMBean> next()
{
ObjectName objectName = resIter.next();
String poolName = objectName.getKeyProperty("type");
JMXEnabledThreadPoolExecutorMBean threadPoolProxy = JMX.newMBeanProxy(mbeanServerConn, objectName, JMXEnabledThreadPoolExecutorMBean.class);
return new AbstractMap.SimpleImmutableEntry<String, JMXEnabledThreadPoolExecutorMBean>(poolName, threadPoolProxy);
}
public void remove()
{
throw new UnsupportedOperationException();
}
}

View File

@ -31,24 +31,22 @@ import javax.management.openmbean.*;
import com.google.common.base.Joiner;
import com.google.common.base.Throwables;
import com.google.common.collect.*;
import com.yammer.metrics.reporting.JmxReporter;
import io.airlift.command.*;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.cassandra.concurrent.JMXEnabledThreadPoolExecutorMBean;
import org.apache.cassandra.concurrent.Stage;
import org.apache.cassandra.db.ColumnFamilyStoreMBean;
import org.apache.cassandra.db.SystemKeyspace;
import org.apache.cassandra.db.compaction.CompactionManagerMBean;
import org.apache.cassandra.db.compaction.OperationType;
import org.apache.cassandra.io.util.FileUtils;
import org.apache.cassandra.locator.EndpointSnitchInfoMBean;
import org.apache.cassandra.metrics.ColumnFamilyMetrics.Sampler;
import org.apache.cassandra.metrics.CassandraMetricsRegistry;
import org.apache.cassandra.metrics.ColumnFamilyMetrics;
import org.apache.cassandra.net.MessagingServiceMBean;
import org.apache.cassandra.repair.messages.RepairOption;
import org.apache.cassandra.repair.RepairParallelism;
@ -60,7 +58,7 @@ import org.apache.cassandra.utils.EstimatedHistogram;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.JVMStabilityInspector;
import org.apache.commons.lang3.ArrayUtils;
import static org.apache.cassandra.metrics.ColumnFamilyMetrics.Sampler;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Throwables.getStackTraceAsString;
@ -739,8 +737,8 @@ public class NodeTool
for (ColumnFamilyStoreMBean cfstore : columnFamilies)
{
String cfName = cfstore.getColumnFamilyName();
long writeCount = ((JmxReporter.TimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "WriteLatency")).getCount();
long readCount = ((JmxReporter.TimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "ReadLatency")).getCount();
long writeCount = ((CassandraMetricsRegistry.JmxTimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "WriteLatency")).getCount();
long readCount = ((CassandraMetricsRegistry.JmxTimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "ReadLatency")).getCount();
if (readCount > 0)
{
@ -821,12 +819,12 @@ public class NodeTool
System.out.println("\t\tMemtable data size: " + format((Long) probe.getColumnFamilyMetric(keyspaceName, cfName, "MemtableLiveDataSize"), humanReadable));
System.out.println("\t\tMemtable off heap memory used: " + format(memtableOffHeapSize, humanReadable));
System.out.println("\t\tMemtable switch count: " + probe.getColumnFamilyMetric(keyspaceName, cfName, "MemtableSwitchCount"));
System.out.println("\t\tLocal read count: " + ((JmxReporter.TimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "ReadLatency")).getCount());
double localReadLatency = ((JmxReporter.TimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "ReadLatency")).getMean() / 1000;
System.out.println("\t\tLocal read count: " + ((CassandraMetricsRegistry.JmxTimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "ReadLatency")).getCount());
double localReadLatency = ((CassandraMetricsRegistry.JmxTimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "ReadLatency")).getMean() / 1000;
double localRLatency = localReadLatency > 0 ? localReadLatency : Double.NaN;
System.out.printf("\t\tLocal read latency: %01.3f ms%n", localRLatency);
System.out.println("\t\tLocal write count: " + ((JmxReporter.TimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "WriteLatency")).getCount());
double localWriteLatency = ((JmxReporter.TimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "WriteLatency")).getMean() / 1000;
System.out.println("\t\tLocal write count: " + ((CassandraMetricsRegistry.JmxTimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "WriteLatency")).getCount());
double localWriteLatency = ((CassandraMetricsRegistry.JmxTimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "WriteLatency")).getMean() / 1000;
double localWLatency = localWriteLatency > 0 ? localWriteLatency : Double.NaN;
System.out.printf("\t\tLocal write latency: %01.3f ms%n", localWLatency);
System.out.println("\t\tPending flushes: " + probe.getColumnFamilyMetric(keyspaceName, cfName, "PendingFlushes"));
@ -840,10 +838,10 @@ public class NodeTool
System.out.println("\t\tCompacted partition minimum bytes: " + format((Long) probe.getColumnFamilyMetric(keyspaceName, cfName, "MinRowSize"), humanReadable));
System.out.println("\t\tCompacted partition maximum bytes: " + format((Long) probe.getColumnFamilyMetric(keyspaceName, cfName, "MaxRowSize"), humanReadable));
System.out.println("\t\tCompacted partition mean bytes: " + format((Long) probe.getColumnFamilyMetric(keyspaceName, cfName, "MeanRowSize"), humanReadable));
JmxReporter.HistogramMBean histogram = (JmxReporter.HistogramMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "LiveScannedHistogram");
CassandraMetricsRegistry.JmxHistogramMBean histogram = (CassandraMetricsRegistry.JmxHistogramMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "LiveScannedHistogram");
System.out.println("\t\tAverage live cells per slice (last five minutes): " + histogram.getMean());
System.out.println("\t\tMaximum live cells per slice (last five minutes): " + histogram.getMax());
histogram = (JmxReporter.HistogramMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "TombstoneScannedHistogram");
histogram = (CassandraMetricsRegistry.JmxHistogramMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "TombstoneScannedHistogram");
System.out.println("\t\tAverage tombstones per slice (last five minutes): " + histogram.getMean());
System.out.println("\t\tMaximum tombstones per slice (last five minutes): " + histogram.getMax());
@ -945,7 +943,7 @@ public class NodeTool
@Option(name = "-k", description = "Number of the top partitions to list (Default: 10)")
private int topCount = 10;
@Option(name = "-a", description = "Comma separated list of samplers to use (Default: all)")
private String samplers = join(Sampler.values(), ',');
private String samplers = join(ColumnFamilyMetrics.Sampler.values(), ',');
@Override
public void execute(NodeProbe probe)
{
@ -1083,9 +1081,9 @@ public class NodeTool
}
String[] percentiles = new String[]{"50%", "75%", "95%", "98%", "99%", "Min", "Max"};
double[] readLatency = probe.metricPercentilesAsArray((JmxReporter.HistogramMBean) probe.getColumnFamilyMetric(keyspace, cfname, "ReadLatency"));
double[] writeLatency = probe.metricPercentilesAsArray((JmxReporter.TimerMBean) probe.getColumnFamilyMetric(keyspace, cfname, "WriteLatency"));
double[] sstablesPerRead = probe.metricPercentilesAsArray((JmxReporter.HistogramMBean) probe.getColumnFamilyMetric(keyspace, cfname, "SSTablesPerReadHistogram"));
double[] readLatency = probe.metricPercentilesAsArray((CassandraMetricsRegistry.JmxTimerMBean) probe.getColumnFamilyMetric(keyspace, cfname, "ReadLatency"));
double[] writeLatency = probe.metricPercentilesAsArray((CassandraMetricsRegistry.JmxTimerMBean) probe.getColumnFamilyMetric(keyspace, cfname, "WriteLatency"));
double[] sstablesPerRead = probe.metricPercentilesAsArray((CassandraMetricsRegistry.JmxHistogramMBean) probe.getColumnFamilyMetric(keyspace, cfname, "SSTablesPerReadHistogram"));
System.out.println(format("%s/%s histograms", keyspace, cfname));
System.out.println(format("%-10s%10s%18s%18s%18s%18s",
@ -2565,19 +2563,15 @@ public class NodeTool
{
System.out.printf("%-25s%10s%10s%15s%10s%18s%n", "Pool Name", "Active", "Pending", "Completed", "Blocked", "All time blocked");
Iterator<Map.Entry<String, JMXEnabledThreadPoolExecutorMBean>> threads = probe.getThreadPoolMBeanProxies();
while (threads.hasNext())
for (Stage stage : Stage.jmxEnabledStages())
{
Map.Entry<String, JMXEnabledThreadPoolExecutorMBean> thread = threads.next();
String poolName = thread.getKey();
JMXEnabledThreadPoolExecutorMBean threadPoolProxy = thread.getValue();
System.out.printf("%-25s%10s%10s%15s%10s%18s%n",
poolName,
threadPoolProxy.getActiveCount(),
threadPoolProxy.getPendingTasks(),
threadPoolProxy.getCompletedTasks(),
threadPoolProxy.getCurrentlyBlockedTasks(),
threadPoolProxy.getTotalBlockedTasks());
stage.getJmxName(),
probe.getThreadPoolMetric(stage, "ActiveTasks"),
probe.getThreadPoolMetric(stage, "PendingTasks"),
probe.getThreadPoolMetric(stage, "CompletedTasks"),
probe.getThreadPoolMetric(stage, "CurrentlyBlockedTasks"),
probe.getThreadPoolMetric(stage, "TotalBlockedTasks"));
}
System.out.printf("%n%-20s%10s%n", "Message type", "Dropped");

View File

@ -26,7 +26,7 @@ import io.netty.util.concurrent.Future;
import org.apache.cassandra.concurrent.TracingAwareExecutorService;
import org.apache.cassandra.config.DatabaseDescriptor;
import static org.apache.cassandra.concurrent.JMXEnabledSharedExecutorPool.SHARED;
import static org.apache.cassandra.concurrent.SharedExecutorPool.SHARED;
public class RequestThreadPoolExecutor extends AbstractEventExecutor
{
@ -34,8 +34,8 @@ public class RequestThreadPoolExecutor extends AbstractEventExecutor
private final static String THREAD_FACTORY_ID = "Native-Transport-Requests";
private final TracingAwareExecutorService wrapped = SHARED.newExecutor(DatabaseDescriptor.getNativeTransportMaxThreads(),
MAX_QUEUED_REQUESTS,
THREAD_FACTORY_ID,
"transport");
"transport",
THREAD_FACTORY_ID);
public boolean isShuttingDown()
{

View File

@ -19,15 +19,14 @@ package org.apache.cassandra.utils;
import java.lang.management.ManagementFactory;
import java.util.Set;
import javax.management.JMX;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.*;
import com.google.common.collect.Iterables;
import org.apache.cassandra.cache.*;
import org.apache.cassandra.concurrent.Stage;
import org.apache.cassandra.metrics.ThreadPoolMetrics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -43,34 +42,25 @@ public class StatusLogger
{
private static final Logger logger = LoggerFactory.getLogger(StatusLogger.class);
public static void log()
{
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
// everything from o.a.c.concurrent
logger.info(String.format("%-25s%10s%10s%15s%10s%18s", "Pool Name", "Active", "Pending", "Completed", "Blocked", "All Time Blocked"));
Set<ObjectName> request, internal;
try
for (Stage stage : Stage.jmxEnabledStages())
{
request = server.queryNames(new ObjectName("org.apache.cassandra.request:type=*"), null);
internal = server.queryNames(new ObjectName("org.apache.cassandra.internal:type=*"), null);
}
catch (MalformedObjectNameException e)
{
throw new RuntimeException(e);
}
for (ObjectName objectName : Iterables.concat(request, internal))
{
String poolName = objectName.getKeyProperty("type");
JMXEnabledThreadPoolExecutorMBean threadPoolProxy = JMX.newMBeanProxy(server, objectName, JMXEnabledThreadPoolExecutorMBean.class);
logger.info(String.format("%-25s%10s%10s%15s%10s%18s",
poolName,
threadPoolProxy.getActiveCount(),
threadPoolProxy.getPendingTasks(),
threadPoolProxy.getCompletedTasks(),
threadPoolProxy.getCurrentlyBlockedTasks(),
threadPoolProxy.getTotalBlockedTasks()));
System.out.printf("%-25s%10s%10s%15s%10s%18s%n",
stage.getJmxName(),
ThreadPoolMetrics.getJmxMetric(server, stage.getJmxType(), stage.getJmxName(), "ActiveTasks"),
ThreadPoolMetrics.getJmxMetric(server, stage.getJmxType(), stage.getJmxName(), "PendingTasks"),
ThreadPoolMetrics.getJmxMetric(server, stage.getJmxType(), stage.getJmxName(), "CompletedTasks"),
ThreadPoolMetrics.getJmxMetric(server, stage.getJmxType(), stage.getJmxName(), "CurrentlyBlockedTasks"),
ThreadPoolMetrics.getJmxMetric(server, stage.getJmxType(), stage.getJmxName(), "TotalBlockedTasks"));
}
// one offs
logger.info(String.format("%-25s%10s%10s",
"CompactionManager", CompactionManager.instance.getActiveCompactions(), CompactionManager.instance.getPendingTasks()));
@ -114,7 +104,7 @@ public class StatusLogger
{
logger.info(String.format("%-25s%20s",
cfs.keyspace.getName() + "." + cfs.name,
cfs.getMemtableColumnsCount() + "," + cfs.getMemtableDataSize()));
cfs.metric.memtableColumnsCount.getValue() + "," + cfs.metric.memtableLiveDataSize.getValue()));
}
}
}

View File

@ -18,13 +18,13 @@
*/
package org.apache.cassandra.utils.concurrent;
import com.yammer.metrics.core.TimerContext;
import java.util.Iterator;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.locks.LockSupport;
import com.codahale.metrics.Timer;
/**
* <p>A relatively easy to use utility for general purpose thread signalling.</p>
* <p>Usage on a thread awaiting a state change using a WaitQueue q is:</p>
@ -96,7 +96,7 @@ public final class WaitQueue
* or the waiting thread is interrupted.
* @return
*/
public Signal register(TimerContext context)
public Signal register(Timer.Context context)
{
assert context != null;
RegisteredSignal signal = new TimedSignal(context);
@ -389,9 +389,9 @@ public final class WaitQueue
*/
private final class TimedSignal extends RegisteredSignal
{
private final TimerContext context;
private final Timer.Context context;
private TimedSignal(TimerContext context)
private TimedSignal(Timer.Context context)
{
this.context = context;
}

View File

@ -116,7 +116,7 @@ public class LongSharedExecutorPoolTest
final ExecutorService[] executors = new ExecutorService[executorCount];
for (int i = 0 ; i < executors.length ; i++)
{
executors[i] = JMXEnabledSharedExecutorPool.SHARED.newExecutor(threadCount, maxQueued, "test" + i, "test" + i);
executors[i] = SharedExecutorPool.SHARED.newExecutor(threadCount, maxQueued, "test" + i, "test" + i);
threadCounts[i] = threadCount;
workCount[i] = new WeibullDistribution(2, maxQueued);
threadCount *= 2;

View File

@ -78,7 +78,7 @@ public class LongFlushMemtableTest
for (ColumnFamilyStore cfs : ColumnFamilyStore.all())
{
if (cfs.name.startsWith("_CF"))
flushes += cfs.getMemtableSwitchCount();
flushes += cfs.metric.memtableSwitchCount.getCount();
}
assert flushes > 0;
}

View File

@ -46,10 +46,10 @@ import com.google.common.util.concurrent.ListenableFutureTask;
import org.junit.Assert;
import org.junit.Test;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Timer;
import com.yammer.metrics.core.TimerContext;
import com.yammer.metrics.stats.Snapshot;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Snapshot;
import com.codahale.metrics.Timer;
import org.apache.cassandra.concurrent.NamedThreadFactory;
import org.apache.cassandra.utils.btree.BTree;
import org.apache.cassandra.utils.btree.BTreeSearchIterator;
@ -60,8 +60,9 @@ import org.apache.cassandra.utils.btree.UpdateFunction;
public class LongBTreeTest
{
private static final Timer BTREE_TIMER = Metrics.newTimer(BTree.class, "BTREE", TimeUnit.NANOSECONDS, TimeUnit.NANOSECONDS);
private static final Timer TREE_TIMER = Metrics.newTimer(BTree.class, "TREE", TimeUnit.NANOSECONDS, TimeUnit.NANOSECONDS);
private static final MetricRegistry metrics = new MetricRegistry();
private static final Timer BTREE_TIMER = metrics.timer(MetricRegistry.name(BTree.class, "BTREE"));
private static final Timer TREE_TIMER = metrics.timer(MetricRegistry.name(BTree.class, "TREE"));
private static final ExecutorService MODIFY = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new NamedThreadFactory("MODIFY"));
private static final ExecutorService COMPARE = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new NamedThreadFactory("COMPARE"));
private static final RandomAbort<Integer> SPORADIC_ABORT = new RandomAbort<>(new Random(), 0.0001f);
@ -236,7 +237,7 @@ public class LongBTreeTest
}
mods -= c;
}
TimerContext ctxt;
Timer.Context ctxt;
ctxt = TREE_TIMER.time();
canon.putAll(buffer);
ctxt.stop();

View File

@ -53,8 +53,8 @@ public class ColumnFamilyMetricTest
store.truncateBlocking();
assertEquals(0, store.metric.liveDiskSpaceUsed.count());
assertEquals(0, store.metric.totalDiskSpaceUsed.count());
assertEquals(0, store.metric.liveDiskSpaceUsed.getCount());
assertEquals(0, store.metric.totalDiskSpaceUsed.getCount());
for (int j = 0; j < 10; j++)
{
@ -72,14 +72,14 @@ public class ColumnFamilyMetricTest
}
// size metrics should show the sum of all SSTable sizes
assertEquals(size, store.metric.liveDiskSpaceUsed.count());
assertEquals(size, store.metric.totalDiskSpaceUsed.count());
assertEquals(size, store.metric.liveDiskSpaceUsed.getCount());
assertEquals(size, store.metric.totalDiskSpaceUsed.getCount());
store.truncateBlocking();
// after truncate, size metrics should be down to 0
assertEquals(0, store.metric.liveDiskSpaceUsed.count());
assertEquals(0, store.metric.totalDiskSpaceUsed.count());
assertEquals(0, store.metric.liveDiskSpaceUsed.getCount());
assertEquals(0, store.metric.totalDiskSpaceUsed.getCount());
store.enableAutoCompaction();
}

View File

@ -81,6 +81,7 @@ import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.io.sstable.metadata.MetadataCollector;
import org.apache.cassandra.io.util.FileUtils;
import org.apache.cassandra.locator.SimpleStrategy;
import org.apache.cassandra.metrics.ClearableHistogram;
import org.apache.cassandra.service.ActiveRepairService;
import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.thrift.SlicePredicate;
@ -178,9 +179,9 @@ public class ColumnFamilyStoreTest
rm.applyUnsafe();
cfs.forceBlockingFlush();
cfs.getRecentSSTablesPerReadHistogram(); // resets counts
((ClearableHistogram)cfs.metric.sstablesPerReadHistogram.cf).clear(); // resets counts
cfs.getColumnFamily(Util.namesQueryFilter(cfs, Util.dk("key1"), "Column1"));
assertEquals(1, cfs.getRecentSSTablesPerReadHistogram()[0]);
assertEquals(1, cfs.metric.sstablesPerReadHistogram.cf.getCount());
}
@Test

View File

@ -45,6 +45,7 @@ import org.apache.cassandra.db.marshal.CompositeType;
import org.apache.cassandra.db.marshal.IntegerType;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.locator.SimpleStrategy;
import org.apache.cassandra.metrics.ClearableHistogram;
import org.apache.cassandra.utils.WrappedRunnable;
import static org.apache.cassandra.Util.column;
import static org.apache.cassandra.Util.expiringColumn;
@ -481,18 +482,18 @@ public class KeyspaceTest
rm.applyUnsafe();
cfStore.forceBlockingFlush();
}
cfStore.metric.sstablesPerReadHistogram.cf.clear();
((ClearableHistogram)cfStore.metric.sstablesPerReadHistogram.cf).clear();
ColumnFamily cf = cfStore.getColumnFamily(key, Composites.EMPTY, cellname("col1499"), false, 1000, System.currentTimeMillis());
assertEquals(cfStore.metric.sstablesPerReadHistogram.cf.max(), 5, 0.1);
assertEquals(cfStore.metric.sstablesPerReadHistogram.cf.getSnapshot().getMax(), 5, 0.1);
int i = 0;
for (Cell c : cf.getSortedColumns())
{
assertEquals(ByteBufferUtil.string(c.name().toByteBuffer()), "col" + (1000 + i++));
}
assertEquals(i, 500);
cfStore.metric.sstablesPerReadHistogram.cf.clear();
((ClearableHistogram)cfStore.metric.sstablesPerReadHistogram.cf).clear();
cf = cfStore.getColumnFamily(key, cellname("col1500"), cellname("col2000"), false, 1000, System.currentTimeMillis());
assertEquals(cfStore.metric.sstablesPerReadHistogram.cf.max(), 5, 0.1);
assertEquals(cfStore.metric.sstablesPerReadHistogram.cf.getSnapshot().getMax(), 5, 0.1);
for (Cell c : cf.getSortedColumns())
{
@ -501,9 +502,9 @@ public class KeyspaceTest
assertEquals(i, 1000);
// reverse
cfStore.metric.sstablesPerReadHistogram.cf.clear();
((ClearableHistogram)cfStore.metric.sstablesPerReadHistogram.cf).clear();
cf = cfStore.getColumnFamily(key, cellname("col2000"), cellname("col1500"), true, 1000, System.currentTimeMillis());
assertEquals(cfStore.metric.sstablesPerReadHistogram.cf.max(), 5, 0.1);
assertEquals(cfStore.metric.sstablesPerReadHistogram.cf.getSnapshot().getMax(), 5, 0.1);
i = 500;
for (Cell c : cf.getSortedColumns())
{
@ -550,13 +551,13 @@ public class KeyspaceTest
}
Composite start = type.builder().add(ByteBufferUtil.bytes("a5")).add(ByteBufferUtil.bytes(85)).build();
Composite finish = type.builder().add(ByteBufferUtil.bytes("a5")).build().end();
cfs.metric.sstablesPerReadHistogram.cf.clear();
((ClearableHistogram)cfs.metric.sstablesPerReadHistogram.cf).clear();
ColumnFamily cf = cfs.getColumnFamily(key, start, finish, false, 1000, System.currentTimeMillis());
int colCount = 0;
for (Cell c : cf)
colCount++;
assertEquals(2, colCount);
assertEquals(2, cfs.metric.sstablesPerReadHistogram.cf.max(), 0.1);
assertEquals(2, cfs.metric.sstablesPerReadHistogram.cf.getSnapshot().getMax(), 0.1);
}
private void validateSliceLarge(ColumnFamilyStore cfStore) throws IOException

View File

@ -185,8 +185,8 @@ public class RowCacheTest
Keyspace keyspace = Keyspace.open(KEYSPACE_CACHED);
String cf = "CachedIntCF";
ColumnFamilyStore cachedStore = keyspace.getColumnFamilyStore(cf);
long startRowCacheHits = cachedStore.metric.rowCacheHit.count();
long startRowCacheOutOfRange = cachedStore.metric.rowCacheHitOutOfRange.count();
long startRowCacheHits = cachedStore.metric.rowCacheHit.getCount();
long startRowCacheOutOfRange = cachedStore.metric.rowCacheHitOutOfRange.getCount();
// empty the row cache
CacheService.instance.invalidateRowCache();
@ -206,31 +206,31 @@ public class RowCacheTest
Composites.EMPTY,
Composites.EMPTY,
false, 10, System.currentTimeMillis()));
assertEquals(startRowCacheHits, cachedStore.metric.rowCacheHit.count());
assertEquals(startRowCacheHits, cachedStore.metric.rowCacheHit.getCount());
// do another query, limit is 20, which is < 100 that we cache, we should get a hit and it should be in range
cachedStore.getColumnFamily(QueryFilter.getSliceFilter(dk, cf,
Composites.EMPTY,
Composites.EMPTY,
false, 20, System.currentTimeMillis()));
assertEquals(++startRowCacheHits, cachedStore.metric.rowCacheHit.count());
assertEquals(startRowCacheOutOfRange, cachedStore.metric.rowCacheHitOutOfRange.count());
assertEquals(++startRowCacheHits, cachedStore.metric.rowCacheHit.getCount());
assertEquals(startRowCacheOutOfRange, cachedStore.metric.rowCacheHitOutOfRange.getCount());
// get a slice from 95 to 105, 95->99 are in cache, we should not get a hit and then row cache is out of range
cachedStore.getColumnFamily(QueryFilter.getSliceFilter(dk, cf,
CellNames.simpleDense(ByteBufferUtil.bytes(95)),
CellNames.simpleDense(ByteBufferUtil.bytes(105)),
false, 10, System.currentTimeMillis()));
assertEquals(startRowCacheHits, cachedStore.metric.rowCacheHit.count());
assertEquals(++startRowCacheOutOfRange, cachedStore.metric.rowCacheHitOutOfRange.count());
assertEquals(startRowCacheHits, cachedStore.metric.rowCacheHit.getCount());
assertEquals(++startRowCacheOutOfRange, cachedStore.metric.rowCacheHitOutOfRange.getCount());
// get a slice with limit > 100, we should get a hit out of range.
cachedStore.getColumnFamily(QueryFilter.getSliceFilter(dk, cf,
Composites.EMPTY,
Composites.EMPTY,
false, 101, System.currentTimeMillis()));
assertEquals(startRowCacheHits, cachedStore.metric.rowCacheHit.count());
assertEquals(++startRowCacheOutOfRange, cachedStore.metric.rowCacheHitOutOfRange.count());
assertEquals(startRowCacheHits, cachedStore.metric.rowCacheHit.getCount());
assertEquals(++startRowCacheOutOfRange, cachedStore.metric.rowCacheHitOutOfRange.getCount());
CacheService.instance.invalidateRowCache();
@ -240,7 +240,7 @@ public class RowCacheTest
Composites.EMPTY,
Composites.EMPTY,
false, 105, System.currentTimeMillis()));
assertEquals(startRowCacheHits, cachedStore.metric.rowCacheHit.count());
assertEquals(startRowCacheHits, cachedStore.metric.rowCacheHit.getCount());
// validate the stuff in cache;
ColumnFamily cachedCf = (ColumnFamily)CacheService.instance.rowCache.get(rck);
assertEquals(cachedCf.getColumnCount(), 100);

View File

@ -143,8 +143,8 @@ public class AntiCompactionTest
long sum = 0;
for (SSTableReader x : cfs.getSSTables())
sum += x.bytesOnDisk();
assertEquals(sum, cfs.metric.liveDiskSpaceUsed.count());
assertEquals(origSize, cfs.metric.liveDiskSpaceUsed.count(), 100000);
assertEquals(sum, cfs.metric.liveDiskSpaceUsed.getCount());
assertEquals(origSize, cfs.metric.liveDiskSpaceUsed.getCount(), 100000);
}

View File

@ -200,7 +200,7 @@ public class SSTableReaderTest
store.forceBlockingFlush();
clearAndLoad(store);
assert store.getMaxRowSize() != 0;
assert store.metric.maxRowSize.getValue() != 0;
}
private void clearAndLoad(ColumnFamilyStore cfs)

View File

@ -250,7 +250,7 @@ public class SSTableRewriterTest extends SchemaLoader
SSTableReader s = writeFile(cfs, 1000);
cfs.addSSTable(s);
long startStorageMetricsLoad = StorageMetrics.load.count();
long startStorageMetricsLoad = StorageMetrics.load.getCount();
Set<SSTableReader> compacting = Sets.newHashSet(s);
SSTableRewriter.overrideOpenInterval(10000000);
SSTableRewriter rewriter = new SSTableRewriter(cfs, compacting, 1000, false);
@ -268,8 +268,8 @@ public class SSTableRewriterTest extends SchemaLoader
rewriter.switchWriter(getWriter(cfs, s.descriptor.directory));
files++;
assertEquals(cfs.getSSTables().size(), files); // we have one original file plus the ones we have switched out.
assertEquals(s.bytesOnDisk(), cfs.metric.liveDiskSpaceUsed.count());
assertEquals(s.bytesOnDisk(), cfs.metric.totalDiskSpaceUsed.count());
assertEquals(s.bytesOnDisk(), cfs.metric.liveDiskSpaceUsed.getCount());
assertEquals(s.bytesOnDisk(), cfs.metric.totalDiskSpaceUsed.getCount());
}
}
@ -279,13 +279,13 @@ public class SSTableRewriterTest extends SchemaLoader
long sum = 0;
for (SSTableReader x : cfs.getSSTables())
sum += x.bytesOnDisk();
assertEquals(sum, cfs.metric.liveDiskSpaceUsed.count());
assertEquals(startStorageMetricsLoad - s.bytesOnDisk() + sum, StorageMetrics.load.count());
assertEquals(sum, cfs.metric.liveDiskSpaceUsed.getCount());
assertEquals(startStorageMetricsLoad - s.bytesOnDisk() + sum, StorageMetrics.load.getCount());
assertEquals(files, sstables.size());
assertEquals(files, cfs.getSSTables().size());
Thread.sleep(1000);
// tmplink and tmp files should be gone:
assertEquals(sum, cfs.metric.totalDiskSpaceUsed.count());
assertEquals(sum, cfs.metric.totalDiskSpaceUsed.getCount());
assertFileCounts(s.descriptor.directory.list(), 0, 0);
validateCFS(cfs);
}
@ -340,7 +340,7 @@ public class SSTableRewriterTest extends SchemaLoader
SSTableReader s = writeFile(cfs, 1000);
cfs.addSSTable(s);
long startSize = cfs.metric.liveDiskSpaceUsed.count();
long startSize = cfs.metric.liveDiskSpaceUsed.getCount();
DecoratedKey origFirst = s.first;
DecoratedKey origLast = s.last;
Set<SSTableReader> compacting = Sets.newHashSet(s);
@ -365,7 +365,7 @@ public class SSTableRewriterTest extends SchemaLoader
}
rewriter.abort();
Thread.sleep(1000);
assertEquals(startSize, cfs.metric.liveDiskSpaceUsed.count());
assertEquals(startSize, cfs.metric.liveDiskSpaceUsed.getCount());
assertEquals(1, cfs.getSSTables().size());
assertFileCounts(s.descriptor.directory.list(), 0, 0);
assertEquals(cfs.getSSTables().iterator().next().first, origFirst);

View File

@ -64,9 +64,9 @@ public class CQLMetricsTest extends SchemaLoader
@Test
public void testPreparedStatementsCount()
{
assertEquals(0, (int) QueryProcessor.metrics.preparedStatementsCount.value());
assertEquals(0, (int) QueryProcessor.metrics.preparedStatementsCount.getValue());
metricsStatement = session.prepare("INSERT INTO junit.metricstest (id, val) VALUES (?, ?)");
assertEquals(1, (int) QueryProcessor.metrics.preparedStatementsCount.value());
assertEquals(1, (int) QueryProcessor.metrics.preparedStatementsCount.getValue());
}
@Test
@ -74,14 +74,14 @@ public class CQLMetricsTest extends SchemaLoader
{
clearMetrics();
assertEquals(0, QueryProcessor.metrics.preparedStatementsExecuted.count());
assertEquals(0, QueryProcessor.metrics.regularStatementsExecuted.count());
assertEquals(0, QueryProcessor.metrics.preparedStatementsExecuted.getCount());
assertEquals(0, QueryProcessor.metrics.regularStatementsExecuted.getCount());
for (int i = 0; i < 10; i++)
session.execute(String.format("INSERT INTO junit.metricstest (id, val) VALUES (%d, '%s')", i, "val" + i));
assertEquals(0, QueryProcessor.metrics.preparedStatementsExecuted.count());
assertEquals(10, QueryProcessor.metrics.regularStatementsExecuted.count());
assertEquals(0, QueryProcessor.metrics.preparedStatementsExecuted.getCount());
assertEquals(10, QueryProcessor.metrics.regularStatementsExecuted.getCount());
}
@Test
@ -89,14 +89,14 @@ public class CQLMetricsTest extends SchemaLoader
{
clearMetrics();
assertEquals(0, QueryProcessor.metrics.preparedStatementsExecuted.count());
assertEquals(0, QueryProcessor.metrics.regularStatementsExecuted.count());
assertEquals(0, QueryProcessor.metrics.preparedStatementsExecuted.getCount());
assertEquals(0, QueryProcessor.metrics.regularStatementsExecuted.getCount());
for (int i = 0; i < 10; i++)
session.execute(metricsStatement.bind(i, "val" + i));
assertEquals(10, QueryProcessor.metrics.preparedStatementsExecuted.count());
assertEquals(0, QueryProcessor.metrics.regularStatementsExecuted.count());
assertEquals(10, QueryProcessor.metrics.preparedStatementsExecuted.getCount());
assertEquals(0, QueryProcessor.metrics.regularStatementsExecuted.getCount());
}
@Test
@ -104,22 +104,22 @@ public class CQLMetricsTest extends SchemaLoader
{
clearMetrics();
assertEquals(Double.NaN, QueryProcessor.metrics.preparedStatementsRatio.value());
assertEquals(Double.NaN, QueryProcessor.metrics.preparedStatementsRatio.getValue());
for (int i = 0; i < 10; i++)
session.execute(metricsStatement.bind(i, "val" + i));
assertEquals(1.0, QueryProcessor.metrics.preparedStatementsRatio.value());
assertEquals(1.0, QueryProcessor.metrics.preparedStatementsRatio.getValue());
for (int i = 0; i < 10; i++)
session.execute(String.format("INSERT INTO junit.metricstest (id, val) VALUES (%d, '%s')", i, "val" + i));
assertEquals(0.5, QueryProcessor.metrics.preparedStatementsRatio.value());
assertEquals(0.5, QueryProcessor.metrics.preparedStatementsRatio.getValue());
}
private void clearMetrics()
{
QueryProcessor.metrics.preparedStatementsExecuted.clear();
QueryProcessor.metrics.regularStatementsExecuted.clear();
QueryProcessor.metrics.preparedStatementsEvicted.clear();
QueryProcessor.metrics.preparedStatementsExecuted.dec(QueryProcessor.metrics.preparedStatementsExecuted.getCount());
QueryProcessor.metrics.regularStatementsExecuted.dec(QueryProcessor.metrics.regularStatementsExecuted.getCount());
QueryProcessor.metrics.preparedStatementsEvicted.dec(QueryProcessor.metrics.preparedStatementsEvicted.getCount());
}
}

View File

@ -43,7 +43,7 @@ public class LatencyMetricsTest
for (int i = 0; i < 10000; i++)
{
Double recent = l.getRecentLatency();
Double recent = l.latency.getOneMinuteRate();
assertFalse(recent.equals(Double.POSITIVE_INFINITY));
}
}