diff --git a/build.xml b/build.xml index e58ccc3b20..b3a835db8c 100644 --- a/build.xml +++ b/build.xml @@ -375,7 +375,7 @@ - + @@ -454,7 +454,7 @@ - + diff --git a/lib/metrics-core-2.0.3.jar b/lib/metrics-core-2.0.3.jar new file mode 100644 index 0000000000..729e6e8e52 Binary files /dev/null and b/lib/metrics-core-2.0.3.jar differ diff --git a/lib/metrics-core-3.0.1.jar b/lib/metrics-core-3.0.1.jar deleted file mode 100644 index 9b50dad6d0..0000000000 Binary files a/lib/metrics-core-3.0.1.jar and /dev/null differ diff --git a/src/java/org/apache/cassandra/concurrent/JMXEnabledThreadPoolExecutor.java b/src/java/org/apache/cassandra/concurrent/JMXEnabledThreadPoolExecutor.java index db75e8fb5e..de448b5a71 100644 --- a/src/java/org/apache/cassandra/concurrent/JMXEnabledThreadPoolExecutor.java +++ b/src/java/org/apache/cassandra/concurrent/JMXEnabledThreadPoolExecutor.java @@ -151,12 +151,12 @@ public class JMXEnabledThreadPoolExecutor extends DebuggableThreadPoolExecutor i public int getTotalBlockedTasks() { - return (int) metrics.totalBlocked.getCount(); + return (int) metrics.totalBlocked.count(); } public int getCurrentlyBlockedTasks() { - return (int) metrics.currentBlocked.getCount(); + return (int) metrics.currentBlocked.count(); } public int getCoreThreads() diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java index f3c4eb8d14..1ada914d67 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java @@ -26,7 +26,6 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.regex.Pattern; - import javax.management.*; import com.google.common.annotations.VisibleForTesting; @@ -34,9 +33,9 @@ import com.google.common.base.Function; import com.google.common.collect.*; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Uninterruptibles; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.apache.cassandra.cache.IRowCacheEntry; import org.apache.cassandra.cache.RowCacheKey; import org.apache.cassandra.cache.RowCacheSentinel; @@ -67,7 +66,6 @@ import org.apache.cassandra.io.compress.CompressionParameters; import org.apache.cassandra.io.sstable.*; import org.apache.cassandra.io.sstable.Descriptor; import org.apache.cassandra.io.util.FileUtils; -import org.apache.cassandra.metrics.CassandraMetricRegistry; import org.apache.cassandra.metrics.ColumnFamilyMetrics; import org.apache.cassandra.service.CacheService; import org.apache.cassandra.service.StorageService; @@ -306,6 +304,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean { case PERCENTILE: // get percentile in nanos + assert metric.readLatency.latency.durationUnit() == TimeUnit.MICROSECONDS; sampleLatency = (long) (metric.readLatency.latency.getSnapshot().getValue(retryPolicy.value) * 1000d); break; case CUSTOM: @@ -361,17 +360,17 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public long getMinRowSize() { - return metric.minRowSize.getValue(); + return metric.minRowSize.value(); } public long getMaxRowSize() { - return metric.maxRowSize.getValue(); + return metric.maxRowSize.value(); } public long getMeanRowSize() { - return metric.meanRowSize.getValue(); + return metric.meanRowSize.value(); } public int getMeanColumns() @@ -739,8 +738,8 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean } } - if (metric.memtableSwitchCount.getCount() == Long.MAX_VALUE) - metric.resetMemTableSwitchCount(); + if (metric.memtableSwitchCount.count() == Long.MAX_VALUE) + metric.memtableSwitchCount.clear(); metric.memtableSwitchCount.inc(); // when all the memtables have been written, including for indexes, mark the flush in the commitlog header. @@ -848,7 +847,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean while (true) { long last = liveRatioComputedAt.get(); - long operations = metric.writeLatency.latency.getCount(); + long operations = metric.writeLatency.latency.count(); if (operations < 2 * last) break; if (liveRatioComputedAt.compareAndSet(last, operations)) @@ -1087,12 +1086,12 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public long getMemtableColumnsCount() { - return metric.memtableColumnsCount.getValue(); + return metric.memtableColumnsCount.value(); } public long getMemtableDataSize() { - return metric.memtableDataSize.getValue(); + return metric.memtableDataSize.value(); } public long getTotalMemtableLiveSize() @@ -1102,7 +1101,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public int getMemtableSwitchCount() { - return (int) metric.memtableSwitchCount.getCount(); + return (int) metric.memtableSwitchCount.count(); } private Memtable getMemtableThreadSafe() @@ -1140,7 +1139,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public long getReadCount() { - return metric.readLatency.latency.getCount(); + return metric.readLatency.latency.count(); } public double getRecentReadLatencyMicros() @@ -1160,22 +1159,22 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public long getTotalReadLatencyMicros() { - return metric.readLatency.totalLatency.getCount(); + return metric.readLatency.totalLatency.count(); } public int getPendingTasks() { - return metric.pendingTasks.getValue(); + return metric.pendingTasks.value(); } public long getWriteCount() { - return metric.writeLatency.latency.getCount(); + return metric.writeLatency.latency.count(); } public long getTotalWriteLatencyMicros() { - return metric.writeLatency.totalLatency.getCount(); + return metric.writeLatency.totalLatency.count(); } public double getRecentWriteLatencyMicros() @@ -1790,17 +1789,17 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public long getTotalDiskSpaceUsed() { - return metric.totalDiskSpaceUsed.getCount(); + return metric.totalDiskSpaceUsed.count(); } public long getLiveDiskSpaceUsed() { - return metric.liveDiskSpaceUsed.getCount(); + return metric.liveDiskSpaceUsed.count(); } public int getLiveSSTableCount() { - return metric.liveSSTableCount.getValue(); + return metric.liveSSTableCount.value(); } /** @@ -2052,27 +2051,27 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public long getBloomFilterFalsePositives() { - return metric.bloomFilterFalsePositives.getValue(); + return metric.bloomFilterFalsePositives.value(); } public long getRecentBloomFilterFalsePositives() { - return metric.recentBloomFilterFalsePositives.getValue(); + return metric.recentBloomFilterFalsePositives.value(); } public double getBloomFilterFalseRatio() { - return metric.bloomFilterFalseRatio.getValue(); + return metric.bloomFilterFalseRatio.value(); } public double getRecentBloomFilterFalseRatio() { - return metric.recentBloomFilterFalseRatio.getValue(); + return metric.recentBloomFilterFalseRatio.value(); } public long getBloomFilterDiskSpaceUsed() { - return metric.bloomFilterDiskSpaceUsed.getValue(); + return metric.bloomFilterDiskSpaceUsed.value(); } @Override @@ -2183,17 +2182,17 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public long[] getEstimatedRowSizeHistogram() { - return metric.estimatedRowSizeHistogram.getValue(); + return metric.estimatedRowSizeHistogram.value(); } public long[] getEstimatedColumnCountHistogram() { - return metric.estimatedColumnCountHistogram.getValue(); + return metric.estimatedColumnCountHistogram.value(); } public double getCompressionRatio() { - return metric.compressionRatio.getValue(); + return metric.compressionRatio.value(); } /** true if this CFS contains secondary index data */ diff --git a/src/java/org/apache/cassandra/db/commitlog/CommitLog.java b/src/java/org/apache/cassandra/db/commitlog/CommitLog.java index 746ad01ae8..706df37aa8 100644 --- a/src/java/org/apache/cassandra/db/commitlog/CommitLog.java +++ b/src/java/org/apache/cassandra/db/commitlog/CommitLog.java @@ -265,7 +265,7 @@ public class CommitLog implements CommitLogMBean */ public long getCompletedTasks() { - return metrics.completedTasks.getValue(); + return metrics.completedTasks.value(); } /** @@ -273,7 +273,7 @@ public class CommitLog implements CommitLogMBean */ public long getPendingTasks() { - return metrics.pendingTasks.getValue(); + return metrics.pendingTasks.value(); } /** @@ -281,7 +281,7 @@ public class CommitLog implements CommitLogMBean */ public long getTotalCommitlogSize() { - return metrics.totalCommitLogSize.getValue(); + return metrics.totalCommitLogSize.value(); } /** diff --git a/src/java/org/apache/cassandra/db/compaction/CompactionManager.java b/src/java/org/apache/cassandra/db/compaction/CompactionManager.java index 0ac513ca59..c667986c72 100644 --- a/src/java/org/apache/cassandra/db/compaction/CompactionManager.java +++ b/src/java/org/apache/cassandra/db/compaction/CompactionManager.java @@ -1010,22 +1010,22 @@ public class CompactionManager implements CompactionManagerMBean public long getTotalBytesCompacted() { - return metrics.bytesCompacted.getCount(); + return metrics.bytesCompacted.count(); } public long getTotalCompactionsCompleted() { - return metrics.totalCompactionsCompleted.getCount(); + return metrics.totalCompactionsCompleted.count(); } public int getPendingTasks() { - return metrics.pendingTasks.getValue(); + return metrics.pendingTasks.value(); } public long getCompletedTasks() { - return metrics.completedTasks.getValue(); + return metrics.completedTasks.value(); } private static class CleanupInfo extends CompactionInfo.Holder diff --git a/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java b/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java index 6b04b92063..ff8c70a82d 100644 --- a/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java +++ b/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java @@ -27,13 +27,13 @@ import java.util.concurrent.TimeUnit; import javax.management.MBeanServer; import javax.management.ObjectName; -import com.codahale.metrics.ExponentiallyDecayingReservoir; - import org.apache.cassandra.config.DatabaseDescriptor; 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 */ @@ -50,7 +50,7 @@ public class DynamicEndpointSnitch extends AbstractEndpointSnitch implements ILa private final ConcurrentHashMap scores = new ConcurrentHashMap(); private final ConcurrentHashMap lastReceived = new ConcurrentHashMap(); - private final ConcurrentHashMap samples = new ConcurrentHashMap(); + private final ConcurrentHashMap samples = new ConcurrentHashMap(); public final IEndpointSnitch subsnitch; @@ -203,10 +203,10 @@ public class DynamicEndpointSnitch extends AbstractEndpointSnitch implements ILa { lastReceived.put(host, System.nanoTime()); - ExponentiallyDecayingReservoir sample = samples.get(host); + ExponentiallyDecayingSample sample = samples.get(host); if (sample == null) { - ExponentiallyDecayingReservoir maybeNewSample = new ExponentiallyDecayingReservoir(WINDOW_SIZE, ALPHA); + ExponentiallyDecayingSample maybeNewSample = new ExponentiallyDecayingSample(WINDOW_SIZE, ALPHA); sample = samples.putIfAbsent(host, maybeNewSample); if (sample == null) sample = maybeNewSample; @@ -232,7 +232,7 @@ public class DynamicEndpointSnitch extends AbstractEndpointSnitch implements ILa HashMap penalties = new HashMap(samples.size()); // We're going to weight the latency and time since last reply for each host against the worst one we see, to arrive at sort of a 'badness percentage' for both of them. // first, find the worst for each. - for (Map.Entry entry : samples.entrySet()) + for (Map.Entry entry : samples.entrySet()) { double mean = entry.getValue().getSnapshot().getMedian(); if (mean > maxLatency) @@ -246,7 +246,7 @@ public class DynamicEndpointSnitch extends AbstractEndpointSnitch implements ILa maxPenalty = timePenalty; } // now make another pass to do the weighting based on the maximums we found before - for (Map.Entry entry: samples.entrySet()) + for (Map.Entry entry: samples.entrySet()) { double score = entry.getValue().getSnapshot().getMedian() / maxLatency; if (penalties.containsKey(entry.getKey())) @@ -265,7 +265,8 @@ public class DynamicEndpointSnitch extends AbstractEndpointSnitch implements ILa private void reset() { - samples.clear(); + for (ExponentiallyDecayingSample sample : samples.values()) + sample.clear(); } public Map getScores() @@ -294,7 +295,7 @@ public class DynamicEndpointSnitch extends AbstractEndpointSnitch implements ILa { InetAddress host = InetAddress.getByName(hostname); ArrayList timings = new ArrayList(); - ExponentiallyDecayingReservoir sample = samples.get(host); + ExponentiallyDecayingSample sample = samples.get(host); if (sample != null) { for (double time: sample.getSnapshot().getValues()) diff --git a/src/java/org/apache/cassandra/metrics/CacheMetrics.java b/src/java/org/apache/cassandra/metrics/CacheMetrics.java index ba98ab3184..31575113df 100644 --- a/src/java/org/apache/cassandra/metrics/CacheMetrics.java +++ b/src/java/org/apache/cassandra/metrics/CacheMetrics.java @@ -17,12 +17,14 @@ */ package org.apache.cassandra.metrics; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; -import com.codahale.metrics.Gauge; -import com.codahale.metrics.Meter; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.RatioGauge; +import com.yammer.metrics.Metrics; +import com.yammer.metrics.core.Gauge; +import com.yammer.metrics.core.Meter; +import com.yammer.metrics.core.MetricName; +import com.yammer.metrics.util.RatioGauge; import org.apache.cassandra.cache.ICache; @@ -58,43 +60,37 @@ public class CacheMetrics */ public CacheMetrics(String type, final ICache cache) { - capacity = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Capacity", type), new Gauge() + capacity = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "Capacity", type), new Gauge() { - public Long getValue() + public Long value() { return cache.capacity(); } }); - hits = CassandraMetricRegistry.get().meter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Hits", type)); - - requests = CassandraMetricRegistry.get().meter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Requests", type)); - hitRate = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "HitRate", type), new RatioGauge() + hits = Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "Hits", type), "hits", TimeUnit.SECONDS); + requests = Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "Requests", type), "requests", TimeUnit.SECONDS); + hitRate = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "HitRate", type), new RatioGauge() { protected double getNumerator() { - return hits.getCount(); + return hits.count(); } protected double getDenominator() { - return requests.getCount(); - } - - public Ratio getRatio() - { - return Ratio.of(getNumerator(), getDenominator()); + return requests.count(); } }); - size = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Size", type), new Gauge() + size = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "Size", type), new Gauge() { - public Long getValue() + public Long value() { return cache.weightedSize(); } }); - entries = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Entries", type), new Gauge() + entries = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "Entries", type), new Gauge() { - public Integer getValue() + public Integer value() { return cache.size(); } @@ -105,8 +101,8 @@ public class CacheMetrics @Deprecated public double getRecentHitRate() { - long r = requests.getCount(); - long h = hits.getCount(); + long r = requests.count(); + long h = hits.count(); try { return ((double)(h - lastHits.get())) / (r - lastRequests.get()); diff --git a/src/java/org/apache/cassandra/metrics/CassandraMetricRegistry.java b/src/java/org/apache/cassandra/metrics/CassandraMetricRegistry.java deleted file mode 100644 index c69e8afe4f..0000000000 --- a/src/java/org/apache/cassandra/metrics/CassandraMetricRegistry.java +++ /dev/null @@ -1,52 +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.metrics; - -import com.codahale.metrics.JmxReporter; -import com.codahale.metrics.Metric; -import com.codahale.metrics.MetricRegistry; - -public class CassandraMetricRegistry -{ - private static MetricRegistry defaultRegistry = new MetricRegistry(); - static - { - JmxReporter reporter = JmxReporter.forRegistry(defaultRegistry).build(); - reporter.start(); - } - - private CassandraMetricRegistry() - { - } - - public static MetricRegistry get() - { - return defaultRegistry; - } - - public static T register(String name, T metric) - { - defaultRegistry.remove(name); - return defaultRegistry.register(name, metric); - } - - public static void unregister(String name) - { - defaultRegistry.remove(name); - } -} diff --git a/src/java/org/apache/cassandra/metrics/ClientRequestMetrics.java b/src/java/org/apache/cassandra/metrics/ClientRequestMetrics.java index 89a5c73ceb..d6ff01bfea 100644 --- a/src/java/org/apache/cassandra/metrics/ClientRequestMetrics.java +++ b/src/java/org/apache/cassandra/metrics/ClientRequestMetrics.java @@ -20,16 +20,18 @@ */ package org.apache.cassandra.metrics; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.Counter; -import com.codahale.metrics.Meter; +import java.util.concurrent.TimeUnit; + +import com.yammer.metrics.Metrics; +import com.yammer.metrics.core.Counter; +import com.yammer.metrics.core.Meter; public class ClientRequestMetrics extends LatencyMetrics { - @Deprecated public static final Counter readTimeouts = CassandraMetricRegistry.get().counter(MetricRegistry.name(ClientRequestMetrics.class, "ReadTimeouts")); - @Deprecated public static final Counter writeTimeouts = CassandraMetricRegistry.get().counter(MetricRegistry.name(ClientRequestMetrics.class, "WriteTimeouts")); - @Deprecated public static final Counter readUnavailables = CassandraMetricRegistry.get().counter(MetricRegistry.name(ClientRequestMetrics.class, "ReadUnavailables")); - @Deprecated public static final Counter writeUnavailables = CassandraMetricRegistry.get().counter(MetricRegistry.name(ClientRequestMetrics.class, "WriteUnavailables")); + @Deprecated public static final Counter readTimeouts = Metrics.newCounter(ClientRequestMetrics.class, "ReadTimeouts"); + @Deprecated public static final Counter writeTimeouts = Metrics.newCounter(ClientRequestMetrics.class, "WriteTimeouts"); + @Deprecated public static final Counter readUnavailables = Metrics.newCounter(ClientRequestMetrics.class, "ReadUnavailables"); + @Deprecated public static final Counter writeUnavailables = Metrics.newCounter(ClientRequestMetrics.class, "WriteUnavailables"); public final Meter timeouts; public final Meter unavailables; @@ -38,14 +40,14 @@ public class ClientRequestMetrics extends LatencyMetrics { super("org.apache.cassandra.metrics", "ClientRequest", scope); - timeouts = CassandraMetricRegistry.get().meter(factory.createMetricName("Timeouts")); - unavailables = CassandraMetricRegistry.get().meter(factory.createMetricName("Unavailables")); + timeouts = Metrics.newMeter(factory.createMetricName("Timeouts"), "timeouts", TimeUnit.SECONDS); + unavailables = Metrics.newMeter(factory.createMetricName("Unavailables"), "unavailables", TimeUnit.SECONDS); } public void release() { super.release(); - CassandraMetricRegistry.unregister(factory.createMetricName("Timeouts")); - CassandraMetricRegistry.unregister(factory.createMetricName("Unavailables")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("Timeouts")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("Unavailables")); } } diff --git a/src/java/org/apache/cassandra/metrics/ColumnFamilyMetrics.java b/src/java/org/apache/cassandra/metrics/ColumnFamilyMetrics.java index ce870c78f5..0f9f87d3bb 100644 --- a/src/java/org/apache/cassandra/metrics/ColumnFamilyMetrics.java +++ b/src/java/org/apache/cassandra/metrics/ColumnFamilyMetrics.java @@ -17,21 +17,19 @@ */ package org.apache.cassandra.metrics; - -import com.codahale.metrics.Counter; -import com.codahale.metrics.Gauge; -import com.codahale.metrics.Histogram; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.RatioGauge; +import com.yammer.metrics.Metrics; +import com.yammer.metrics.core.Counter; +import com.yammer.metrics.core.Gauge; +import com.yammer.metrics.core.Histogram; +import com.yammer.metrics.core.MetricName; +import com.yammer.metrics.util.RatioGauge; import org.apache.cassandra.db.ColumnFamilyStore; import org.apache.cassandra.db.Keyspace; -import org.apache.cassandra.metrics.CassandraMetricRegistry; import org.apache.cassandra.io.sstable.SSTableMetadata; import org.apache.cassandra.io.sstable.SSTableReader; import org.apache.cassandra.utils.EstimatedHistogram; - /** * Metrics for {@link ColumnFamilyStore}. */ @@ -42,7 +40,7 @@ public class ColumnFamilyMetrics /** Total number of columns present in the memtable. */ public final Gauge memtableColumnsCount; /** Number of times flush has resulted in the memtable being switched out. */ - public Counter memtableSwitchCount; + public final Counter memtableSwitchCount; /** Current compression ratio for all SSTables */ public final Gauge compressionRatio; /** Histogram of estimated row size (in bytes). */ @@ -99,24 +97,24 @@ public class ColumnFamilyMetrics { factory = new ColumnFamilyMetricNameFactory(cfs); - memtableColumnsCount = CassandraMetricRegistry.register(factory.createMetricName("MemtableColumnsCount"), new Gauge() + memtableColumnsCount = Metrics.newGauge(factory.createMetricName("MemtableColumnsCount"), new Gauge() { - public Long getValue() + public Long value() { return cfs.getDataTracker().getMemtable().getOperations(); } }); - memtableDataSize = CassandraMetricRegistry.register(factory.createMetricName("MemtableDataSize"), new Gauge() + memtableDataSize = Metrics.newGauge(factory.createMetricName("MemtableDataSize"), new Gauge() { - public Long getValue() + public Long value() { return cfs.getDataTracker().getMemtable().getLiveSize(); } }); - memtableSwitchCount = CassandraMetricRegistry.get().counter(factory.createMetricName("MemtableSwitchCount")); - estimatedRowSizeHistogram = CassandraMetricRegistry.register(factory.createMetricName("EstimatedRowSizeHistogram"), new Gauge() + memtableSwitchCount = Metrics.newCounter(factory.createMetricName("MemtableSwitchCount")); + estimatedRowSizeHistogram = Metrics.newGauge(factory.createMetricName("EstimatedRowSizeHistogram"), new Gauge() { - public long[] getValue() + public long[] value() { long[] histogram = new long[90]; for (SSTableReader sstable : cfs.getSSTables()) @@ -128,9 +126,9 @@ public class ColumnFamilyMetrics return histogram; } }); - estimatedColumnCountHistogram = CassandraMetricRegistry.register(factory.createMetricName("EstimatedColumnCountHistogram"), new Gauge() + estimatedColumnCountHistogram = Metrics.newGauge(factory.createMetricName("EstimatedColumnCountHistogram"), new Gauge() { - public long[] getValue() + public long[] value() { long[] histogram = new long[90]; for (SSTableReader sstable : cfs.getSSTables()) @@ -142,10 +140,10 @@ public class ColumnFamilyMetrics return histogram; } }); - sstablesPerReadHistogram = CassandraMetricRegistry.get().histogram(factory.createMetricName("SSTablesPerReadHistogram")); - compressionRatio = CassandraMetricRegistry.register(factory.createMetricName("CompressionRatio"), new Gauge() + sstablesPerReadHistogram = Metrics.newHistogram(factory.createMetricName("SSTablesPerReadHistogram")); + compressionRatio = Metrics.newGauge(factory.createMetricName("CompressionRatio"), new Gauge() { - public Double getValue() + public Double value() { double sum = 0; int total = 0; @@ -162,26 +160,26 @@ public class ColumnFamilyMetrics }); readLatency = new LatencyMetrics(factory, "Read"); writeLatency = new LatencyMetrics(factory, "Write"); - pendingTasks = CassandraMetricRegistry.register(factory.createMetricName("PendingTasks"), new Gauge() + pendingTasks = Metrics.newGauge(factory.createMetricName("PendingTasks"), new Gauge() { - public Integer getValue() + public Integer value() { // TODO this actually isn't a good measure of pending tasks return Keyspace.switchLock.getQueueLength(); } }); - liveSSTableCount = CassandraMetricRegistry.register(factory.createMetricName("LiveSSTableCount"), new Gauge() + liveSSTableCount = Metrics.newGauge(factory.createMetricName("LiveSSTableCount"), new Gauge() { - public Integer getValue() + public Integer value() { return cfs.getDataTracker().getSSTables().size(); } }); - liveDiskSpaceUsed = CassandraMetricRegistry.get().counter(factory.createMetricName("LiveDiskSpaceUsed")); - totalDiskSpaceUsed = CassandraMetricRegistry.get().counter(factory.createMetricName("TotalDiskSpaceUsed")); - minRowSize = CassandraMetricRegistry.register(factory.createMetricName("MinRowSize"), new Gauge() + liveDiskSpaceUsed = Metrics.newCounter(factory.createMetricName("LiveDiskSpaceUsed")); + totalDiskSpaceUsed = Metrics.newCounter(factory.createMetricName("TotalDiskSpaceUsed")); + minRowSize = Metrics.newGauge(factory.createMetricName("MinRowSize"), new Gauge() { - public Long getValue() + public Long value() { long min = 0; for (SSTableReader sstable : cfs.getSSTables()) @@ -192,9 +190,9 @@ public class ColumnFamilyMetrics return min; } }); - maxRowSize = CassandraMetricRegistry.register(factory.createMetricName("MaxRowSize"), new Gauge() + maxRowSize = Metrics.newGauge(factory.createMetricName("MaxRowSize"), new Gauge() { - public Long getValue() + public Long value() { long max = 0; for (SSTableReader sstable : cfs.getSSTables()) @@ -205,9 +203,9 @@ public class ColumnFamilyMetrics return max; } }); - meanRowSize = CassandraMetricRegistry.register(factory.createMetricName("MeanRowSize"), new Gauge() + meanRowSize = Metrics.newGauge(factory.createMetricName("MeanRowSize"), new Gauge() { - public Long getValue() + public Long value() { long sum = 0; long count = 0; @@ -219,9 +217,9 @@ public class ColumnFamilyMetrics return count > 0 ? sum / count : 0; } }); - bloomFilterFalsePositives = CassandraMetricRegistry.register(factory.createMetricName("BloomFilterFalsePositives"), new Gauge() + bloomFilterFalsePositives = Metrics.newGauge(factory.createMetricName("BloomFilterFalsePositives"), new Gauge() { - public Long getValue() + public Long value() { long count = 0L; for (SSTableReader sstable: cfs.getSSTables()) @@ -229,9 +227,9 @@ public class ColumnFamilyMetrics return count; } }); - recentBloomFilterFalsePositives = CassandraMetricRegistry.register(factory.createMetricName("RecentBloomFilterFalsePositives"), new Gauge() + recentBloomFilterFalsePositives = Metrics.newGauge(factory.createMetricName("RecentBloomFilterFalsePositives"), new Gauge() { - public Long getValue() + public Long value() { long count = 0L; for (SSTableReader sstable: cfs.getSSTables()) @@ -239,9 +237,9 @@ public class ColumnFamilyMetrics return count; } }); - bloomFilterFalseRatio = CassandraMetricRegistry.register(factory.createMetricName("BloomFilterFalseRatio"), new Gauge() + bloomFilterFalseRatio = Metrics.newGauge(factory.createMetricName("BloomFilterFalseRatio"), new Gauge() { - public Double getValue() + public Double value() { long falseCount = 0L; long trueCount = 0L; @@ -255,9 +253,9 @@ public class ColumnFamilyMetrics return (double) falseCount / (trueCount + falseCount); } }); - recentBloomFilterFalseRatio = CassandraMetricRegistry.register(factory.createMetricName("RecentBloomFilterFalseRatio"), new Gauge() + recentBloomFilterFalseRatio = Metrics.newGauge(factory.createMetricName("RecentBloomFilterFalseRatio"), new Gauge() { - public Double getValue() + public Double value() { long falseCount = 0L; long trueCount = 0L; @@ -271,9 +269,9 @@ public class ColumnFamilyMetrics return (double) falseCount / (trueCount + falseCount); } }); - bloomFilterDiskSpaceUsed = CassandraMetricRegistry.register(factory.createMetricName("BloomFilterDiskSpaceUsed"), new Gauge() + bloomFilterDiskSpaceUsed = Metrics.newGauge(factory.createMetricName("BloomFilterDiskSpaceUsed"), new Gauge() { - public Long getValue() + public Long value() { long total = 0; for (SSTableReader sst : cfs.getSSTables()) @@ -281,9 +279,8 @@ public class ColumnFamilyMetrics return total; } }); - - speculativeRetry = CassandraMetricRegistry.get().counter(factory.createMetricName("SpeculativeRetry")); - keyCacheHitRate = CassandraMetricRegistry.register(factory.createMetricName("KeyCacheHitRate"), new RatioGauge() + speculativeRetry = Metrics.newCounter(factory.createMetricName("SpeculativeRetry")); + keyCacheHitRate = Metrics.newGauge(factory.createMetricName("KeyCacheHitRate"), new RatioGauge() { protected double getNumerator() { @@ -300,19 +297,8 @@ public class ColumnFamilyMetrics requests += sstable.getKeyCacheRequest(); return Math.max(requests, 1); // to avoid NaN. } - - @Override - protected Ratio getRatio() - { - return Ratio.of(getNumerator(), getDenominator()); - } }); } - - public void resetMemTableSwitchCount() - { - memtableSwitchCount = CassandraMetricRegistry.get().counter(factory.createMetricName("MemtableSwitchCount")); - } public void updateSSTableIterated(int count) { @@ -328,27 +314,27 @@ public class ColumnFamilyMetrics { readLatency.release(); writeLatency.release(); - CassandraMetricRegistry.unregister(factory.createMetricName("MemtableColumnsCount")); - CassandraMetricRegistry.unregister(factory.createMetricName("MemtableDataSize")); - CassandraMetricRegistry.unregister(factory.createMetricName("MemtableSwitchCount")); - CassandraMetricRegistry.unregister(factory.createMetricName("CompressionRatio")); - CassandraMetricRegistry.unregister(factory.createMetricName("EstimatedRowSizeHistogram")); - CassandraMetricRegistry.unregister(factory.createMetricName("EstimatedColumnCountHistogram")); - CassandraMetricRegistry.unregister(factory.createMetricName("SSTablesPerReadHistogram")); - CassandraMetricRegistry.unregister(factory.createMetricName("PendingTasks")); - CassandraMetricRegistry.unregister(factory.createMetricName("LiveSSTableCount")); - CassandraMetricRegistry.unregister(factory.createMetricName("LiveDiskSpaceUsed")); - CassandraMetricRegistry.unregister(factory.createMetricName("TotalDiskSpaceUsed")); - CassandraMetricRegistry.unregister(factory.createMetricName("MinRowSize")); - CassandraMetricRegistry.unregister(factory.createMetricName("MaxRowSize")); - CassandraMetricRegistry.unregister(factory.createMetricName("MeanRowSize")); - CassandraMetricRegistry.unregister(factory.createMetricName("BloomFilterFalsePositives")); - CassandraMetricRegistry.unregister(factory.createMetricName("RecentBloomFilterFalsePositives")); - CassandraMetricRegistry.unregister(factory.createMetricName("BloomFilterFalseRatio")); - CassandraMetricRegistry.unregister(factory.createMetricName("RecentBloomFilterFalseRatio")); - CassandraMetricRegistry.unregister(factory.createMetricName("BloomFilterDiskSpaceUsed")); - CassandraMetricRegistry.unregister(factory.createMetricName("KeyCacheHitRate")); - CassandraMetricRegistry.unregister(factory.createMetricName("SpeculativeRetry")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("MemtableColumnsCount")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("MemtableDataSize")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("MemtableSwitchCount")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("CompressionRatio")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("EstimatedRowSizeHistogram")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("EstimatedColumnCountHistogram")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("SSTablesPerReadHistogram")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("PendingTasks")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("LiveSSTableCount")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("LiveDiskSpaceUsed")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("TotalDiskSpaceUsed")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("MinRowSize")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("MaxRowSize")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("MeanRowSize")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("BloomFilterFalsePositives")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("RecentBloomFilterFalsePositives")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("BloomFilterFalseRatio")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("RecentBloomFilterFalseRatio")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("BloomFilterDiskSpaceUsed")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("KeyCacheHitRate")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName("SpeculativeRetry")); } class ColumnFamilyMetricNameFactory implements MetricNameFactory @@ -364,7 +350,7 @@ public class ColumnFamilyMetrics isIndex = cfs.isIndex(); } - public String createMetricName(String metricName) + public MetricName createMetricName(String metricName) { String groupName = ColumnFamilyMetrics.class.getPackage().getName(); String type = isIndex ? "IndexColumnFamily" : "ColumnFamily"; @@ -376,7 +362,7 @@ public class ColumnFamilyMetrics mbeanName.append(",scope=").append(columnFamilyName); mbeanName.append(",name=").append(metricName); - return MetricRegistry.name(groupName, type, metricName, keyspaceName + "." + columnFamilyName, mbeanName.toString()); + return new MetricName(groupName, type, metricName, keyspaceName + "." + columnFamilyName, mbeanName.toString()); } } } diff --git a/src/java/org/apache/cassandra/metrics/CommitLogMetrics.java b/src/java/org/apache/cassandra/metrics/CommitLogMetrics.java index 4b87038f2d..598d2955e3 100644 --- a/src/java/org/apache/cassandra/metrics/CommitLogMetrics.java +++ b/src/java/org/apache/cassandra/metrics/CommitLogMetrics.java @@ -17,8 +17,9 @@ */ package org.apache.cassandra.metrics; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.Gauge; +import com.yammer.metrics.Metrics; +import com.yammer.metrics.core.Gauge; +import com.yammer.metrics.core.MetricName; import org.apache.cassandra.db.commitlog.CommitLogAllocator; import org.apache.cassandra.db.commitlog.ICommitLogExecutorService; @@ -40,23 +41,23 @@ public class CommitLogMetrics public CommitLogMetrics(final ICommitLogExecutorService executor, final CommitLogAllocator allocator) { - completedTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "CompletedTasks"), new Gauge() + completedTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "CompletedTasks"), new Gauge() { - public Long getValue() + public Long value() { return executor.getCompletedTasks(); } }); - pendingTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "PendingTasks"), new Gauge() + pendingTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "PendingTasks"), new Gauge() { - public Long getValue() + public Long value() { return executor.getPendingTasks(); } }); - totalCommitLogSize = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "TotalCommitLogSize"), new Gauge() + totalCommitLogSize = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "TotalCommitLogSize"), new Gauge() { - public Long getValue() + public Long value() { return allocator.bytesUsed(); } diff --git a/src/java/org/apache/cassandra/metrics/CompactionMetrics.java b/src/java/org/apache/cassandra/metrics/CompactionMetrics.java index 267d2922f8..dd3803fca3 100644 --- a/src/java/org/apache/cassandra/metrics/CompactionMetrics.java +++ b/src/java/org/apache/cassandra/metrics/CompactionMetrics.java @@ -19,11 +19,13 @@ package org.apache.cassandra.metrics; import java.util.*; import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.Counter; -import com.codahale.metrics.Gauge; -import com.codahale.metrics.Meter; +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.yammer.metrics.core.MetricName; import org.apache.cassandra.config.Schema; import org.apache.cassandra.db.ColumnFamilyStore; @@ -53,9 +55,9 @@ public class CompactionMetrics implements CompactionManager.CompactionExecutorSt public CompactionMetrics(final ThreadPoolExecutor... collectors) { - pendingTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "PendingTasks"), new Gauge() + pendingTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "PendingTasks"), new Gauge() { - public Integer getValue() + public Integer value() { int n = 0; for (String keyspaceName : Schema.instance.getKeyspaces()) @@ -68,9 +70,9 @@ public class CompactionMetrics implements CompactionManager.CompactionExecutorSt return n; } }); - completedTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "CompletedTasks"), new Gauge() + completedTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "CompletedTasks"), new Gauge() { - public Long getValue() + public Long value() { long completedTasks = 0; for (ThreadPoolExecutor collector : collectors) @@ -78,8 +80,8 @@ public class CompactionMetrics implements CompactionManager.CompactionExecutorSt return completedTasks; } }); - totalCompactionsCompleted = CassandraMetricRegistry.get().meter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "TotalCompactionsCompleted")); - bytesCompacted = CassandraMetricRegistry.get().counter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "BytesCompacted")); + totalCompactionsCompleted = Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "TotalCompactionsCompleted"), "compaction completed", TimeUnit.SECONDS); + bytesCompacted = Metrics.newCounter(new MetricName(GROUP_NAME, TYPE_NAME, "BytesCompacted")); } public void beginCompaction(CompactionInfo.Holder ci) diff --git a/src/java/org/apache/cassandra/metrics/ConnectionMetrics.java b/src/java/org/apache/cassandra/metrics/ConnectionMetrics.java index 24d3bbd42d..5493505c95 100644 --- a/src/java/org/apache/cassandra/metrics/ConnectionMetrics.java +++ b/src/java/org/apache/cassandra/metrics/ConnectionMetrics.java @@ -18,10 +18,12 @@ package org.apache.cassandra.metrics; import java.net.InetAddress; +import java.util.concurrent.TimeUnit; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.Gauge; -import com.codahale.metrics.Meter; +import com.yammer.metrics.Metrics; +import com.yammer.metrics.core.Gauge; +import com.yammer.metrics.core.Meter; +import com.yammer.metrics.core.MetricName; import org.apache.cassandra.net.OutboundTcpConnectionPool; @@ -34,7 +36,7 @@ public class ConnectionMetrics public static final String TYPE_NAME = "Connection"; /** Total number of timeouts happened on this node */ - public static final Meter totalTimeouts = CassandraMetricRegistry.get().meter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "TotalTimeouts")); + public static final Meter totalTimeouts = Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "TotalTimeouts"), "total timeouts", TimeUnit.SECONDS); private static long recentTimeouts; public final String address; @@ -64,58 +66,58 @@ public class ConnectionMetrics // ipv6 addresses will contain colons, which are invalid in a JMX ObjectName address = ip.getHostAddress().replaceAll(":", "."); - commandPendingTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "CommandPendingTasks", address), new Gauge() + commandPendingTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "CommandPendingTasks", address), new Gauge() { - public Integer getValue() + public Integer value() { return connectionPool.cmdCon.getPendingMessages(); } }); - commandCompletedTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "CommandCompletedTasks", address), new Gauge() + commandCompletedTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "CommandCompletedTasks", address), new Gauge() { - public Long getValue() + public Long value() { return connectionPool.cmdCon.getCompletedMesssages(); } }); - commandDroppedTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "CommandDroppedTasks", address), new Gauge() + commandDroppedTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "CommandDroppedTasks", address), new Gauge() { - public Long getValue() + public Long value() { return connectionPool.cmdCon.getDroppedMessages(); } }); - responsePendingTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "ResponsePendingTasks", address), new Gauge() + responsePendingTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "ResponsePendingTasks", address), new Gauge() { - public Integer getValue() + public Integer value() { return connectionPool.ackCon.getPendingMessages(); } }); - responseCompletedTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "ResponseCompletedTasks", address), new Gauge() + responseCompletedTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "ResponseCompletedTasks", address), new Gauge() { - public Long getValue() + public Long value() { return connectionPool.ackCon.getCompletedMesssages(); } }); - timeouts = CassandraMetricRegistry.get().meter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Timeouts", address)); + timeouts = Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "Timeouts", address), "timeouts", TimeUnit.SECONDS); } public void release() { - CassandraMetricRegistry.unregister(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "CommandPendingTasks", address)); - CassandraMetricRegistry.unregister(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "CommandCompletedTasks", address)); - CassandraMetricRegistry.unregister(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "CommandDroppedTasks", address)); - CassandraMetricRegistry.unregister(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "ResponsePendingTasks", address)); - CassandraMetricRegistry.unregister(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "ResponseCompletedTasks", address)); - CassandraMetricRegistry.unregister(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Timeouts", address)); + Metrics.defaultRegistry().removeMetric(new MetricName(GROUP_NAME, TYPE_NAME, "CommandPendingTasks", address)); + Metrics.defaultRegistry().removeMetric(new MetricName(GROUP_NAME, TYPE_NAME, "CommandCompletedTasks", address)); + Metrics.defaultRegistry().removeMetric(new MetricName(GROUP_NAME, TYPE_NAME, "CommandDroppedTasks", address)); + Metrics.defaultRegistry().removeMetric(new MetricName(GROUP_NAME, TYPE_NAME, "ResponsePendingTasks", address)); + Metrics.defaultRegistry().removeMetric(new MetricName(GROUP_NAME, TYPE_NAME, "ResponseCompletedTasks", address)); + Metrics.defaultRegistry().removeMetric(new MetricName(GROUP_NAME, TYPE_NAME, "Timeouts", address)); } @Deprecated public static long getRecentTotalTimeout() { - long total = totalTimeouts.getCount(); + long total = totalTimeouts.count(); long recent = total - recentTimeouts; recentTimeouts = total; return recent; @@ -124,7 +126,7 @@ public class ConnectionMetrics @Deprecated public long getRecentTimeout() { - long timeoutCount = timeouts.getCount(); + long timeoutCount = timeouts.count(); long recent = timeoutCount - recentTimeoutCount; recentTimeoutCount = timeoutCount; return recent; diff --git a/src/java/org/apache/cassandra/metrics/DroppedMessageMetrics.java b/src/java/org/apache/cassandra/metrics/DroppedMessageMetrics.java index 9e77f24305..e0b12bb489 100644 --- a/src/java/org/apache/cassandra/metrics/DroppedMessageMetrics.java +++ b/src/java/org/apache/cassandra/metrics/DroppedMessageMetrics.java @@ -17,8 +17,11 @@ */ package org.apache.cassandra.metrics; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.Meter; +import java.util.concurrent.TimeUnit; + +import com.yammer.metrics.Metrics; +import com.yammer.metrics.core.Meter; +import com.yammer.metrics.core.MetricName; import org.apache.cassandra.net.MessagingService; @@ -37,13 +40,13 @@ public class DroppedMessageMetrics public DroppedMessageMetrics(MessagingService.Verb verb) { - dropped = CassandraMetricRegistry.get().meter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Dropped", verb.toString())); + dropped = Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "Dropped", verb.toString()), "dropped", TimeUnit.SECONDS); } @Deprecated public int getRecentlyDropped() { - long currentDropped = dropped.getCount(); + long currentDropped = dropped.count(); long recentlyDropped = currentDropped - lastDropped; lastDropped = currentDropped; return (int)recentlyDropped; diff --git a/src/java/org/apache/cassandra/metrics/HintedHandoffMetrics.java b/src/java/org/apache/cassandra/metrics/HintedHandoffMetrics.java index a4cf004617..0f3992fa23 100644 --- a/src/java/org/apache/cassandra/metrics/HintedHandoffMetrics.java +++ b/src/java/org/apache/cassandra/metrics/HintedHandoffMetrics.java @@ -29,8 +29,9 @@ import org.slf4j.LoggerFactory; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.Counter; +import com.yammer.metrics.Metrics; +import com.yammer.metrics.core.Counter; +import com.yammer.metrics.core.MetricName; /** * Metrics for {@link HintedHandOffManager}. @@ -56,7 +57,7 @@ public class HintedHandoffMetrics { public Counter load(InetAddress address) { - return CassandraMetricRegistry.get().counter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Hints_created-" + address.getHostAddress())); + return Metrics.newCounter(new MetricName(GROUP_NAME, TYPE_NAME, "Hints_created-" + address.getHostAddress())); } }); @@ -89,12 +90,12 @@ public class HintedHandoffMetrics public DifferencingCounter(InetAddress address) { - this.meter = CassandraMetricRegistry.get().counter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Hints_not_stored-" + address.getHostAddress())); + this.meter = Metrics.newCounter(new MetricName(GROUP_NAME, TYPE_NAME, "Hints_not_stored-" + address.getHostAddress())); } public long diffrence() { - long current = meter.getCount(); + long current = meter.count(); long diffrence = current - reported; this.reported = current; return diffrence; @@ -102,7 +103,7 @@ public class HintedHandoffMetrics public long count() { - return meter.getCount(); + return meter.count(); } public void mark() diff --git a/src/java/org/apache/cassandra/metrics/LatencyMetrics.java b/src/java/org/apache/cassandra/metrics/LatencyMetrics.java index 76a1f26e24..d17761324d 100644 --- a/src/java/org/apache/cassandra/metrics/LatencyMetrics.java +++ b/src/java/org/apache/cassandra/metrics/LatencyMetrics.java @@ -19,9 +19,10 @@ package org.apache.cassandra.metrics; import java.util.concurrent.TimeUnit; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.Counter; -import com.codahale.metrics.Timer; +import com.yammer.metrics.Metrics; +import com.yammer.metrics.core.Counter; +import com.yammer.metrics.core.MetricName; +import com.yammer.metrics.core.Timer; import org.apache.cassandra.utils.EstimatedHistogram; @@ -79,8 +80,8 @@ public class LatencyMetrics this.factory = factory; this.namePrefix = namePrefix; - latency = CassandraMetricRegistry.get().timer(factory.createMetricName(namePrefix + "Latency")); - totalLatency = CassandraMetricRegistry.get().counter(factory.createMetricName(namePrefix + "TotalLatency")); + latency = Metrics.newTimer(factory.createMetricName(namePrefix + "Latency"), TimeUnit.MICROSECONDS, TimeUnit.SECONDS); + totalLatency = Metrics.newCounter(factory.createMetricName(namePrefix + "TotalLatency")); } /** takes nanoseconds **/ @@ -100,15 +101,15 @@ public class LatencyMetrics public void release() { - CassandraMetricRegistry.unregister(factory.createMetricName(namePrefix + "Latency")); - CassandraMetricRegistry.unregister(factory.createMetricName(namePrefix + "TotalLatency")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName(namePrefix + "Latency")); + Metrics.defaultRegistry().removeMetric(factory.createMetricName(namePrefix + "TotalLatency")); } @Deprecated public double getRecentLatency() { - long ops = latency.getCount(); - long n = totalLatency.getCount(); + long ops = latency.count(); + long n = totalLatency.count(); try { return ((double) n - lastLatency) / (ops - lastOpCount); @@ -133,9 +134,9 @@ public class LatencyMetrics this.scope = scope; } - public String createMetricName(String metricName) + public MetricName createMetricName(String metricName) { - return MetricRegistry.name(group, type, metricName, scope); + return new MetricName(group, type, metricName, scope); } } } diff --git a/src/java/org/apache/cassandra/metrics/MetricNameFactory.java b/src/java/org/apache/cassandra/metrics/MetricNameFactory.java index 4002bcdec3..78f8b14d0e 100644 --- a/src/java/org/apache/cassandra/metrics/MetricNameFactory.java +++ b/src/java/org/apache/cassandra/metrics/MetricNameFactory.java @@ -17,6 +17,8 @@ */ package org.apache.cassandra.metrics; +import com.yammer.metrics.core.MetricName; + public interface MetricNameFactory { /** @@ -25,5 +27,5 @@ public interface MetricNameFactory * @param metricName part of qualified name. * @return new String with given metric name. */ - String createMetricName(String metricName); + MetricName createMetricName(String metricName); } diff --git a/src/java/org/apache/cassandra/metrics/ReadRepairMetrics.java b/src/java/org/apache/cassandra/metrics/ReadRepairMetrics.java index 605876c486..c67ed90288 100644 --- a/src/java/org/apache/cassandra/metrics/ReadRepairMetrics.java +++ b/src/java/org/apache/cassandra/metrics/ReadRepairMetrics.java @@ -20,8 +20,12 @@ package org.apache.cassandra.metrics; * */ -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.Meter; + +import java.util.concurrent.TimeUnit; + +import com.yammer.metrics.Metrics; +import com.yammer.metrics.core.Meter; +import com.yammer.metrics.core.MetricName; /** * Metrics related to Read Repair. @@ -31,9 +35,9 @@ public class ReadRepairMetrics { public static final String TYPE_NAME = "ReadRepair"; public static final Meter repairedBlocking = - CassandraMetricRegistry.get().meter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "RepairedBlocking")); + Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "RepairedBlocking"), "RepairedBlocking", TimeUnit.SECONDS); public static final Meter repairedBackground = - CassandraMetricRegistry.get().meter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "RepairedBackground")); + Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "RepairedBackground"), "RepairedBackground", TimeUnit.SECONDS); public static final Meter attempted = - CassandraMetricRegistry.get().meter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Attempted")); + Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "Attempted"), "Attempted", TimeUnit.SECONDS); } diff --git a/src/java/org/apache/cassandra/metrics/StorageMetrics.java b/src/java/org/apache/cassandra/metrics/StorageMetrics.java index 02e8e122b8..3cda71e61f 100644 --- a/src/java/org/apache/cassandra/metrics/StorageMetrics.java +++ b/src/java/org/apache/cassandra/metrics/StorageMetrics.java @@ -17,13 +17,14 @@ */ package org.apache.cassandra.metrics; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.Counter; +import com.yammer.metrics.Metrics; +import com.yammer.metrics.core.Counter; +import com.yammer.metrics.core.MetricName; /** * Metrics related to Storage. */ public class StorageMetrics { - public static final Counter load = CassandraMetricRegistry.get().counter(MetricRegistry.name("org.apache.cassandra.metrics", "Storage", "Load")); + public static final Counter load = Metrics.newCounter(new MetricName("org.apache.cassandra.metrics", "Storage", "Load")); } diff --git a/src/java/org/apache/cassandra/metrics/StreamingMetrics.java b/src/java/org/apache/cassandra/metrics/StreamingMetrics.java index bca50d8598..96c79c9719 100644 --- a/src/java/org/apache/cassandra/metrics/StreamingMetrics.java +++ b/src/java/org/apache/cassandra/metrics/StreamingMetrics.java @@ -20,8 +20,9 @@ package org.apache.cassandra.metrics; import java.net.InetAddress; import java.util.concurrent.ConcurrentMap; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.Counter; +import com.yammer.metrics.Metrics; +import com.yammer.metrics.core.Counter; +import com.yammer.metrics.core.MetricName; import org.cliffc.high_scale_lib.NonBlockingHashMap; /** @@ -34,9 +35,9 @@ public class StreamingMetrics private static final ConcurrentMap instances = new NonBlockingHashMap(); - public static final Counter activeStreamsOutbound = CassandraMetricRegistry.get().counter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "ActiveOutboundStreams")); - public static final Counter totalIncomingBytes = CassandraMetricRegistry.get().counter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "TotalIncomingBytes")); - public static final Counter totalOutgoingBytes = CassandraMetricRegistry.get().counter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "TotalOutgoingBytes")); + public static final Counter activeStreamsOutbound = Metrics.newCounter(new MetricName(GROUP_NAME, TYPE_NAME, "ActiveOutboundStreams")); + public static final Counter totalIncomingBytes = Metrics.newCounter(new MetricName(GROUP_NAME, TYPE_NAME, "TotalIncomingBytes")); + public static final Counter totalOutgoingBytes = Metrics.newCounter(new MetricName(GROUP_NAME, TYPE_NAME, "TotalOutgoingBytes")); public final Counter incomingBytes; public final Counter outgoingBytes; @@ -53,7 +54,7 @@ public class StreamingMetrics public StreamingMetrics(final InetAddress peer) { - incomingBytes = CassandraMetricRegistry.get().counter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "IncomingBytes", peer.getHostAddress().replaceAll(":", "."))); - outgoingBytes= CassandraMetricRegistry.get().counter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "OutgoingBytes", peer.getHostAddress().replaceAll(":", "."))); + incomingBytes = Metrics.newCounter(new MetricName(GROUP_NAME, TYPE_NAME, "IncomingBytes", peer.getHostAddress().replaceAll(":", "."))); + outgoingBytes= Metrics.newCounter(new MetricName(GROUP_NAME, TYPE_NAME, "OutgoingBytes", peer.getHostAddress().replaceAll(":", "."))); } } diff --git a/src/java/org/apache/cassandra/metrics/ThreadPoolMetrics.java b/src/java/org/apache/cassandra/metrics/ThreadPoolMetrics.java index 2a3776ed18..af54cdb835 100644 --- a/src/java/org/apache/cassandra/metrics/ThreadPoolMetrics.java +++ b/src/java/org/apache/cassandra/metrics/ThreadPoolMetrics.java @@ -19,8 +19,8 @@ package org.apache.cassandra.metrics; import java.util.concurrent.ThreadPoolExecutor; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.*; +import com.yammer.metrics.Metrics; +import com.yammer.metrics.core.*; /** * Metrics for {@link ThreadPoolExecutor}. @@ -54,25 +54,25 @@ public class ThreadPoolMetrics { this.factory = new ThreadPoolMetricNameFactory(path, poolName); - activeTasks = CassandraMetricRegistry.register(factory.createMetricName("ActiveTasks"), new Gauge() + activeTasks = Metrics.newGauge(factory.createMetricName("ActiveTasks"), new Gauge() { - public Integer getValue() + public Integer value() { return executor.getActiveCount(); } }); - totalBlocked = CassandraMetricRegistry.get().counter(factory.createMetricName("TotalBlockedTasks")); - currentBlocked = CassandraMetricRegistry.get().counter(factory.createMetricName("CurrentlyBlockedTasks")); - completedTasks = CassandraMetricRegistry.register(factory.createMetricName("CompletedTasks"), new Gauge() + totalBlocked = Metrics.newCounter(factory.createMetricName("TotalBlockedTasks")); + currentBlocked = Metrics.newCounter(factory.createMetricName("CurrentlyBlockedTasks")); + completedTasks = Metrics.newGauge(factory.createMetricName("CompletedTasks"), new Gauge() { - public Long getValue() + public Long value() { return executor.getCompletedTaskCount(); } }); - pendingTasks = CassandraMetricRegistry.register(factory.createMetricName("PendingTasks"), new Gauge() + pendingTasks = Metrics.newGauge(factory.createMetricName("PendingTasks"), new Gauge() { - public Long getValue() + public Long value() { return executor.getTaskCount() - executor.getCompletedTaskCount(); } @@ -81,11 +81,11 @@ public class ThreadPoolMetrics public void release() { - CassandraMetricRegistry.unregister(factory.createMetricName("ActiveTasks")); - CassandraMetricRegistry.unregister(factory.createMetricName("PendingTasks")); - CassandraMetricRegistry.unregister(factory.createMetricName("CompletedTasks")); - CassandraMetricRegistry.unregister(factory.createMetricName("TotalBlockedTasks")); - CassandraMetricRegistry.unregister(factory.createMetricName("CurrentlyBlockedTasks")); + 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")); } class ThreadPoolMetricNameFactory implements MetricNameFactory @@ -99,7 +99,7 @@ public class ThreadPoolMetrics this.poolName = poolName; } - public String createMetricName(String metricName) + public MetricName createMetricName(String metricName) { String groupName = ThreadPoolMetrics.class.getPackage().getName(); String type = "ThreadPools"; @@ -110,7 +110,7 @@ public class ThreadPoolMetrics mbeanName.append(",scope=").append(poolName); mbeanName.append(",name=").append(metricName); - return MetricRegistry.name(groupName, type, metricName, path + "." + poolName, mbeanName.toString()); + return new MetricName(groupName, type, metricName, path + "." + poolName, mbeanName.toString()); } } } diff --git a/src/java/org/apache/cassandra/net/MessagingService.java b/src/java/org/apache/cassandra/net/MessagingService.java index 57d1c0e86b..d2926f43d7 100644 --- a/src/java/org/apache/cassandra/net/MessagingService.java +++ b/src/java/org/apache/cassandra/net/MessagingService.java @@ -783,7 +783,7 @@ public final class MessagingService implements MessagingServiceMBean boolean logTpstats = false; for (Map.Entry entry : droppedMessages.entrySet()) { - int dropped = (int) entry.getValue().dropped.getCount(); + int dropped = (int) entry.getValue().dropped.count(); Verb verb = entry.getKey(); int recent = dropped - lastDroppedInternal.get(verb); if (recent > 0) @@ -920,7 +920,7 @@ public final class MessagingService implements MessagingServiceMBean { Map map = new HashMap(); for (Map.Entry entry : droppedMessages.entrySet()) - map.put(entry.getKey().toString(), (int) entry.getValue().dropped.getCount()); + map.put(entry.getKey().toString(), (int) entry.getValue().dropped.count()); return map; } @@ -934,7 +934,7 @@ public final class MessagingService implements MessagingServiceMBean public long getTotalTimeouts() { - return ConnectionMetrics.totalTimeouts.getCount(); + return ConnectionMetrics.totalTimeouts.count(); } public long getRecentTotalTimouts() diff --git a/src/java/org/apache/cassandra/net/OutboundTcpConnectionPool.java b/src/java/org/apache/cassandra/net/OutboundTcpConnectionPool.java index 87312e45e0..81168c6873 100644 --- a/src/java/org/apache/cassandra/net/OutboundTcpConnectionPool.java +++ b/src/java/org/apache/cassandra/net/OutboundTcpConnectionPool.java @@ -101,7 +101,7 @@ public class OutboundTcpConnectionPool public long getTimeouts() { - return metrics.timeouts.getCount(); + return metrics.timeouts.count(); } public long getRecentTimeouts() diff --git a/src/java/org/apache/cassandra/scheduler/WeightedQueue.java b/src/java/org/apache/cassandra/scheduler/WeightedQueue.java index b3ea53d9bd..2d2e0bd192 100644 --- a/src/java/org/apache/cassandra/scheduler/WeightedQueue.java +++ b/src/java/org/apache/cassandra/scheduler/WeightedQueue.java @@ -90,12 +90,12 @@ class WeightedQueue implements WeightedQueueMBean public long getOperations() { - return metric.latency.getCount(); + return metric.latency.count(); } public long getTotalLatencyMicros() { - return metric.totalLatency.getCount(); + return metric.totalLatency.count(); } public double getRecentLatencyMicros() diff --git a/src/java/org/apache/cassandra/service/CacheService.java b/src/java/org/apache/cassandra/service/CacheService.java index 16afc5aaf2..b787b75fa3 100644 --- a/src/java/org/apache/cassandra/service/CacheService.java +++ b/src/java/org/apache/cassandra/service/CacheService.java @@ -151,22 +151,22 @@ public class CacheService implements CacheServiceMBean public long getKeyCacheHits() { - return keyCache.getMetrics().hits.getCount(); + return keyCache.getMetrics().hits.count(); } public long getRowCacheHits() { - return rowCache.getMetrics().hits.getCount(); + return rowCache.getMetrics().hits.count(); } public long getKeyCacheRequests() { - return keyCache.getMetrics().requests.getCount(); + return keyCache.getMetrics().requests.count(); } public long getRowCacheRequests() { - return rowCache.getMetrics().requests.getCount(); + return rowCache.getMetrics().requests.count(); } public double getKeyCacheRecentHitRate() @@ -219,7 +219,7 @@ public class CacheService implements CacheServiceMBean public long getRowCacheCapacityInBytes() { - return rowCache.getMetrics().capacity.getValue(); + return rowCache.getMetrics().capacity.value(); } public long getRowCacheCapacityInMB() @@ -237,7 +237,7 @@ public class CacheService implements CacheServiceMBean public long getKeyCacheCapacityInBytes() { - return keyCache.getMetrics().capacity.getValue(); + return keyCache.getMetrics().capacity.value(); } public long getKeyCacheCapacityInMB() @@ -255,7 +255,7 @@ public class CacheService implements CacheServiceMBean public long getRowCacheSize() { - return rowCache.getMetrics().size.getValue(); + return rowCache.getMetrics().size.value(); } public long getRowCacheEntries() @@ -265,7 +265,7 @@ public class CacheService implements CacheServiceMBean public long getKeyCacheSize() { - return keyCache.getMetrics().size.getValue(); + return keyCache.getMetrics().size.value(); } public long getKeyCacheEntries() diff --git a/src/java/org/apache/cassandra/service/StorageProxy.java b/src/java/org/apache/cassandra/service/StorageProxy.java index dae0fea8d7..2413f18dc7 100644 --- a/src/java/org/apache/cassandra/service/StorageProxy.java +++ b/src/java/org/apache/cassandra/service/StorageProxy.java @@ -1673,12 +1673,12 @@ public class StorageProxy implements StorageProxyMBean public long getReadOperations() { - return readMetrics.latency.getCount(); + return readMetrics.latency.count(); } public long getTotalReadLatencyMicros() { - return readMetrics.totalLatency.getCount(); + return readMetrics.totalLatency.count(); } public double getRecentReadLatencyMicros() @@ -1698,12 +1698,12 @@ public class StorageProxy implements StorageProxyMBean public long getRangeOperations() { - return rangeMetrics.latency.getCount(); + return rangeMetrics.latency.count(); } public long getTotalRangeLatencyMicros() { - return rangeMetrics.totalLatency.getCount(); + return rangeMetrics.totalLatency.count(); } public double getRecentRangeLatencyMicros() @@ -1723,12 +1723,12 @@ public class StorageProxy implements StorageProxyMBean public long getWriteOperations() { - return writeMetrics.latency.getCount(); + return writeMetrics.latency.count(); } public long getTotalWriteLatencyMicros() { - return writeMetrics.totalLatency.getCount(); + return writeMetrics.totalLatency.count(); } public double getRecentWriteLatencyMicros() @@ -1993,14 +1993,14 @@ public class StorageProxy implements StorageProxyMBean public long getReadRepairAttempted() { - return ReadRepairMetrics.attempted.getCount(); + return ReadRepairMetrics.attempted.count(); } public long getReadRepairRepairedBlocking() { - return ReadRepairMetrics.repairedBlocking.getCount(); + return ReadRepairMetrics.repairedBlocking.count(); } public long getReadRepairRepairedBackground() { - return ReadRepairMetrics.repairedBackground.getCount(); + return ReadRepairMetrics.repairedBackground.count(); } } diff --git a/test/unit/org/apache/cassandra/db/KeyspaceTest.java b/test/unit/org/apache/cassandra/db/KeyspaceTest.java index 7d3a1505f5..e7a2b69880 100644 --- a/test/unit/org/apache/cassandra/db/KeyspaceTest.java +++ b/test/unit/org/apache/cassandra/db/KeyspaceTest.java @@ -467,18 +467,18 @@ public class KeyspaceTest extends SchemaLoader rm.apply(); cfStore.forceBlockingFlush(); } - //cfStore.metric.sstablesPerReadHistogram.clear(); + cfStore.metric.sstablesPerReadHistogram.clear(); ColumnFamily cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes(""), ByteBufferUtil.bytes("col1499"), false, 1000, System.currentTimeMillis()); - assertEquals(cfStore.metric.sstablesPerReadHistogram.getSnapshot().getMax(), 5, 0.1); + assertEquals(cfStore.metric.sstablesPerReadHistogram.max(), 5, 0.1); int i = 0; for (Column c : cf.getSortedColumns()) { assertEquals(ByteBufferUtil.string(c.name), "col" + (1000 + i++)); } assertEquals(i, 500); - //cfStore.metric.sstablesPerReadHistogram.clear(); + cfStore.metric.sstablesPerReadHistogram.clear(); cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("col1500"), ByteBufferUtil.bytes("col2000"), false, 1000, System.currentTimeMillis()); - assertEquals(cfStore.metric.sstablesPerReadHistogram.getSnapshot().getMax(), 5, 0.1); + assertEquals(cfStore.metric.sstablesPerReadHistogram.max(), 5, 0.1); for (Column c : cf.getSortedColumns()) { @@ -487,9 +487,9 @@ public class KeyspaceTest extends SchemaLoader assertEquals(i, 1000); // reverse - //cfStore.metric.sstablesPerReadHistogram.clear(); + cfStore.metric.sstablesPerReadHistogram.clear(); cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("col2000"), ByteBufferUtil.bytes("col1500"), true, 1000, System.currentTimeMillis()); - assertEquals(cfStore.metric.sstablesPerReadHistogram.getSnapshot().getMax(), 5, 0.1); + assertEquals(cfStore.metric.sstablesPerReadHistogram.max(), 5, 0.1); i = 500; for (Column c : cf.getSortedColumns()) { @@ -536,13 +536,13 @@ public class KeyspaceTest extends SchemaLoader } ByteBuffer start = ct.builder().add(ByteBufferUtil.bytes("a5")).add(ByteBufferUtil.bytes(85)).build(); ByteBuffer finish = ct.builder().add(ByteBufferUtil.bytes("a5")).buildAsEndOfRange(); - //cfs.metric.sstablesPerReadHistogram.clear(); + cfs.metric.sstablesPerReadHistogram.clear(); ColumnFamily cf = cfs.getColumnFamily(key, start, finish, false, 1000, System.currentTimeMillis()); int colCount = 0; for (Column c : cf) colCount++; assertEquals(2, colCount); - assertEquals(2, cfs.metric.sstablesPerReadHistogram.getSnapshot().getMax(), 0.1); + assertEquals(2, cfs.metric.sstablesPerReadHistogram.max(), 0.1); } private void validateSliceLarge(ColumnFamilyStore cfStore) throws IOException diff --git a/test/unit/org/apache/cassandra/db/RowIterationTest.java b/test/unit/org/apache/cassandra/db/RowIterationTest.java index 084be2d32f..c083b197ef 100644 --- a/test/unit/org/apache/cassandra/db/RowIterationTest.java +++ b/test/unit/org/apache/cassandra/db/RowIterationTest.java @@ -85,7 +85,7 @@ public class RowIterationTest extends SchemaLoader rm.apply(); store.forceBlockingFlush(); - ColumnFamily cf = Util.getRangeSlice(store).get(0).cf; + ColumnFamily cf = Util.getRangeSlice(store).iterator().next().cf; assert cf.deletionInfo().equals(delInfo2); } diff --git a/tools/stress/src/org/apache/cassandra/stress/Session.java b/tools/stress/src/org/apache/cassandra/stress/Session.java index 5897552329..49449eb357 100644 --- a/tools/stress/src/org/apache/cassandra/stress/Session.java +++ b/tools/stress/src/org/apache/cassandra/stress/Session.java @@ -17,24 +17,17 @@ */ package org.apache.cassandra.stress; -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintStream; -import java.io.Serializable; +import java.io.*; import java.net.InetAddress; import java.net.UnknownHostException; import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.commons.cli.*; +import org.apache.commons.lang3.StringUtils; + +import com.yammer.metrics.Metrics; import org.apache.cassandra.cli.transport.FramedTransportFactory; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.EncryptionOptions; @@ -43,18 +36,14 @@ import org.apache.cassandra.db.ColumnFamilyType; import org.apache.cassandra.db.marshal.*; import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.exceptions.SyntaxException; -import org.apache.cassandra.metrics.CassandraMetricRegistry; import org.apache.cassandra.stress.util.CassandraClient; import org.apache.cassandra.thrift.*; import org.apache.cassandra.transport.SimpleClient; import org.apache.cassandra.utils.ByteBufferUtil; -import org.apache.commons.cli.*; -import org.apache.commons.lang3.StringUtils; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TTransport; import org.apache.thrift.transport.TTransportFactory; -import com.codahale.metrics.MetricRegistry; public class Session implements Serializable { @@ -69,7 +58,7 @@ public class Session implements Serializable public final AtomicInteger operations = new AtomicInteger(); public final AtomicInteger keys = new AtomicInteger(); - public final com.codahale.metrics.Timer latency = CassandraMetricRegistry.get().timer(MetricRegistry.name(Session.class, "latency")); + public final com.yammer.metrics.core.Timer latency = Metrics.newTimer(Session.class, "latency"); private static final String SSL_TRUSTSTORE = "truststore"; private static final String SSL_TRUSTSTORE_PW = "truststore-password"; diff --git a/tools/stress/src/org/apache/cassandra/stress/StressAction.java b/tools/stress/src/org/apache/cassandra/stress/StressAction.java index 4c7489ada5..46005a112c 100644 --- a/tools/stress/src/org/apache/cassandra/stress/StressAction.java +++ b/tools/stress/src/org/apache/cassandra/stress/StressAction.java @@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit; import com.google.common.util.concurrent.Uninterruptibles; import com.google.common.util.concurrent.RateLimiter; -import com.codahale.metrics.Snapshot; +import com.yammer.metrics.stats.Snapshot; import org.apache.cassandra.stress.operations.*; import org.apache.cassandra.stress.util.CassandraClient; import org.apache.cassandra.stress.util.Operation; diff --git a/tools/stress/src/org/apache/cassandra/stress/StressStatistics.java b/tools/stress/src/org/apache/cassandra/stress/StressStatistics.java index 3981180a0f..2f7d72d016 100644 --- a/tools/stress/src/org/apache/cassandra/stress/StressStatistics.java +++ b/tools/stress/src/org/apache/cassandra/stress/StressStatistics.java @@ -22,7 +22,8 @@ import java.io.PrintStream; import org.apache.commons.lang3.time.DurationFormatUtils; -import com.codahale.metrics.Snapshot; +import com.yammer.metrics.stats.Snapshot; + /** * Gathers and aggregates statistics for an operation diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CounterAdder.java b/tools/stress/src/org/apache/cassandra/stress/operations/CounterAdder.java index 39c258661f..ab6ae9ded8 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CounterAdder.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CounterAdder.java @@ -17,7 +17,7 @@ */ package org.apache.cassandra.stress.operations; -import com.codahale.metrics.Timer.Context; +import com.yammer.metrics.core.TimerContext; import org.apache.cassandra.stress.Session; import org.apache.cassandra.stress.util.CassandraClient; import org.apache.cassandra.stress.util.Operation; @@ -71,7 +71,7 @@ public class CounterAdder extends Operation ? getSuperColumnsMutationMap(superColumns) : getColumnsMutationMap(columns)); - Context context = session.latency.time(); + TimerContext context = session.latency.time(); boolean success = false; String exceptionMessage = null; diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CounterGetter.java b/tools/stress/src/org/apache/cassandra/stress/operations/CounterGetter.java index 2980df9228..56ef2434c8 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CounterGetter.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CounterGetter.java @@ -17,21 +17,16 @@ */ package org.apache.cassandra.stress.operations; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.List; - -import com.codahale.metrics.Timer.Context; - -import org.apache.cassandra.db.ColumnFamilyType; +import com.yammer.metrics.core.TimerContext; import org.apache.cassandra.stress.Session; import org.apache.cassandra.stress.util.CassandraClient; import org.apache.cassandra.stress.util.Operation; -import org.apache.cassandra.thrift.Cassandra; -import org.apache.cassandra.thrift.ColumnOrSuperColumn; -import org.apache.cassandra.thrift.ColumnParent; -import org.apache.cassandra.thrift.SlicePredicate; -import org.apache.cassandra.thrift.SliceRange; +import org.apache.cassandra.db.ColumnFamilyType; +import org.apache.cassandra.thrift.*; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.List; public class CounterGetter extends Operation { @@ -73,7 +68,7 @@ public class CounterGetter extends Operation String superColumn = 'S' + Integer.toString(j); ColumnParent parent = new ColumnParent("SuperCounter1").setSuper_column(superColumn.getBytes()); - Context context = session.latency.time(); + TimerContext context = session.latency.time(); boolean success = false; String exceptionMessage = null; @@ -118,7 +113,7 @@ public class CounterGetter extends Operation byte[] key = generateKey(); ByteBuffer keyBuffer = ByteBuffer.wrap(key); - Context context = session.latency.time(); + TimerContext context = session.latency.time(); boolean success = false; String exceptionMessage = null; diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterAdder.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterAdder.java index 3569af5aee..31e8371dd5 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterAdder.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterAdder.java @@ -26,7 +26,7 @@ import java.nio.ByteBuffer; import java.util.Collections; import java.util.List; -import com.codahale.metrics.Timer.Context; +import com.yammer.metrics.core.TimerContext; import org.apache.cassandra.db.ColumnFamilyType; import org.apache.cassandra.stress.Session; import org.apache.cassandra.stress.util.CassandraClient; @@ -75,7 +75,7 @@ public class CqlCounterAdder extends CQLOperation String key = String.format("%0" + session.getTotalKeysLength() + "d", index); List queryParams = Collections.singletonList(getUnQuotedCqlBlob(key, session.cqlVersion.startsWith("3"))); - Context context = session.latency.time(); + TimerContext context = session.latency.time(); boolean success = false; String exceptionMessage = null; diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterGetter.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterGetter.java index 0a1dfdf944..a4d037a97e 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterGetter.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterGetter.java @@ -26,7 +26,7 @@ import java.nio.ByteBuffer; import java.util.Collections; import java.util.List; -import com.codahale.metrics.Timer.Context; +import com.yammer.metrics.core.TimerContext; import org.apache.cassandra.db.ColumnFamilyType; import org.apache.cassandra.stress.Session; import org.apache.cassandra.stress.util.CassandraClient; @@ -73,7 +73,7 @@ public class CqlCounterGetter extends CQLOperation byte[] key = generateKey(); List queryParams = Collections.singletonList(getUnQuotedCqlBlob(key, session.cqlVersion.startsWith("3"))); - Context context = session.latency.time(); + TimerContext context = session.latency.time(); boolean success = false; String exceptionMessage = null; diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlIndexedRangeSlicer.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlIndexedRangeSlicer.java index 52fe73f08f..bf416cc952 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlIndexedRangeSlicer.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlIndexedRangeSlicer.java @@ -26,7 +26,7 @@ import java.nio.ByteBuffer; import java.util.Collections; import java.util.List; -import com.codahale.metrics.Timer.Context; +import com.yammer.metrics.core.TimerContext; import org.apache.cassandra.cql3.ResultSet; import org.apache.cassandra.db.ColumnFamilyType; import org.apache.cassandra.stress.Session; @@ -86,7 +86,7 @@ public class CqlIndexedRangeSlicer extends CQLOperation while (received < expectedPerValue) { - Context context = session.latency.time(); + TimerContext context = session.latency.time(); boolean success = false; String exceptionMessage = null; diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlInserter.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlInserter.java index 10d060ee3b..3572c36bf2 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlInserter.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlInserter.java @@ -26,7 +26,7 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; -import com.codahale.metrics.Timer.Context; +import com.yammer.metrics.core.TimerContext; import org.apache.cassandra.db.ColumnFamilyType; import org.apache.cassandra.stress.Session; import org.apache.cassandra.stress.util.CassandraClient; @@ -98,7 +98,7 @@ public class CqlInserter extends CQLOperation String key = String.format("%0" + session.getTotalKeysLength() + "d", index); queryParms.add(getUnQuotedCqlBlob(key, session.cqlVersion.startsWith("3"))); - Context context = session.latency.time(); + TimerContext context = session.latency.time(); boolean success = false; String exceptionMessage = null; diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlRangeSlicer.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlRangeSlicer.java index d1329bfeb2..c01767bc56 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlRangeSlicer.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlRangeSlicer.java @@ -26,7 +26,7 @@ import java.nio.ByteBuffer; import java.util.Collections; import java.util.List; -import com.codahale.metrics.Timer.Context; +import com.yammer.metrics.core.TimerContext; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.db.ColumnFamilyType; @@ -67,7 +67,7 @@ public class CqlRangeSlicer extends CQLOperation String key = String.format("%0" + session.getTotalKeysLength() + "d", index); List queryParams = Collections.singletonList(getUnQuotedCqlBlob(key, session.cqlVersion.startsWith("3"))); - Context context = session.latency.time(); + TimerContext context = session.latency.time(); boolean success = false; String exceptionMessage = null; diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlReader.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlReader.java index c53535c2bf..70273c1d1b 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlReader.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlReader.java @@ -26,7 +26,7 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; -import com.codahale.metrics.Timer.Context; +import com.yammer.metrics.core.TimerContext; import org.apache.cassandra.db.ColumnFamilyType; import org.apache.cassandra.stress.Session; import org.apache.cassandra.stress.util.CassandraClient; @@ -88,7 +88,7 @@ public class CqlReader extends CQLOperation byte[] key = generateKey(); queryParams.add(getUnQuotedCqlBlob(key, session.cqlVersion.startsWith("3"))); - Context context = session.latency.time(); + TimerContext context = session.latency.time(); boolean success = false; String exceptionMessage = null; diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/IndexedRangeSlicer.java b/tools/stress/src/org/apache/cassandra/stress/operations/IndexedRangeSlicer.java index 44e915c2b4..b7c72a27e7 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/IndexedRangeSlicer.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/IndexedRangeSlicer.java @@ -17,7 +17,7 @@ */ package org.apache.cassandra.stress.operations; -import com.codahale.metrics.Timer.Context; +import com.yammer.metrics.core.TimerContext; import org.apache.cassandra.stress.Session; import org.apache.cassandra.stress.util.CassandraClient; import org.apache.cassandra.stress.util.Operation; @@ -67,7 +67,7 @@ public class IndexedRangeSlicer extends Operation session.getKeysPerCall()); List results = null; - Context context = session.latency.time(); + TimerContext context = session.latency.time(); boolean success = false; String exceptionMessage = null; diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java b/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java index 35c74716b5..cbf6b984a3 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java @@ -17,7 +17,7 @@ */ package org.apache.cassandra.stress.operations; -import com.codahale.metrics.Timer.Context; +import com.yammer.metrics.core.TimerContext; import org.apache.cassandra.stress.Session; import org.apache.cassandra.stress.util.CassandraClient; import org.apache.cassandra.stress.util.Operation; @@ -74,7 +74,7 @@ public class Inserter extends Operation : getColumnsMutationMap(columns); Map>> record = Collections.singletonMap(ByteBufferUtil.bytes(rawKey), row); - Context context = session.latency.time(); + TimerContext context = session.latency.time(); boolean success = false; String exceptionMessage = null; diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/MultiGetter.java b/tools/stress/src/org/apache/cassandra/stress/operations/MultiGetter.java index b0657f0def..12a39fb3c9 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/MultiGetter.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/MultiGetter.java @@ -17,7 +17,7 @@ */ package org.apache.cassandra.stress.operations; -import com.codahale.metrics.Timer.Context; +import com.yammer.metrics.core.TimerContext; import org.apache.cassandra.stress.Session; import org.apache.cassandra.stress.util.CassandraClient; import org.apache.cassandra.stress.util.Operation; @@ -56,7 +56,7 @@ public class MultiGetter extends Operation { ColumnParent parent = new ColumnParent("Super1").setSuper_column(ByteBufferUtil.bytes("S" + j)); - Context context = session.latency.time(); + TimerContext context = session.latency.time(); boolean success = false; String exceptionMessage = null; @@ -99,7 +99,7 @@ public class MultiGetter extends Operation List keys = generateKeys(offset, offset + session.getKeysPerCall()); - Context context = session.latency.time(); + TimerContext context = session.latency.time(); boolean success = false; String exceptionMessage = null; diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/RangeSlicer.java b/tools/stress/src/org/apache/cassandra/stress/operations/RangeSlicer.java index d1b52b49f9..f9ba1154d6 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/RangeSlicer.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/RangeSlicer.java @@ -17,7 +17,7 @@ */ package org.apache.cassandra.stress.operations; -import com.codahale.metrics.Timer.Context; +import com.yammer.metrics.core.TimerContext; import org.apache.cassandra.stress.Session; import org.apache.cassandra.stress.util.CassandraClient; import org.apache.cassandra.stress.util.Operation; @@ -62,7 +62,7 @@ public class RangeSlicer extends Operation String superColumnName = "S" + Integer.toString(i); ColumnParent parent = new ColumnParent("Super1").setSuper_column(ByteBufferUtil.bytes(superColumnName)); - Context context = session.latency.time(); + TimerContext context = session.latency.time(); boolean success = false; String exceptionMessage = null; @@ -105,7 +105,7 @@ public class RangeSlicer extends Operation List slices = new ArrayList(); KeyRange range = new KeyRange(count).setStart_key(start).setEnd_key(ByteBufferUtil.EMPTY_BYTE_BUFFER); - Context context = session.latency.time(); + TimerContext context = session.latency.time(); boolean success = false; String exceptionMessage = null; diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/Reader.java b/tools/stress/src/org/apache/cassandra/stress/operations/Reader.java index e15241fb44..f75502a54b 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/Reader.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/Reader.java @@ -17,7 +17,7 @@ */ package org.apache.cassandra.stress.operations; -import com.codahale.metrics.Timer.Context; +import com.yammer.metrics.core.TimerContext; import org.apache.cassandra.stress.Session; import org.apache.cassandra.stress.util.CassandraClient; import org.apache.cassandra.stress.util.Operation; @@ -67,7 +67,7 @@ public class Reader extends Operation String superColumn = 'S' + Integer.toString(j); ColumnParent parent = new ColumnParent("Super1").setSuper_column(superColumn.getBytes(UTF_8)); - Context context = session.latency.time(); + TimerContext context = session.latency.time(); boolean success = false; String exceptionMessage = null; @@ -112,7 +112,7 @@ public class Reader extends Operation byte[] key = generateKey(); ByteBuffer keyBuffer = ByteBuffer.wrap(key); - Context context = session.latency.time(); + TimerContext context = session.latency.time(); boolean success = false; String exceptionMessage = null;