diff --git a/build.xml b/build.xml index a72adf4980..17b3705328 100644 --- a/build.xml +++ b/build.xml @@ -371,7 +371,7 @@ - + @@ -450,7 +450,7 @@ - + diff --git a/lib/metrics-core-2.0.3.jar b/lib/metrics-core-2.0.3.jar deleted file mode 100644 index 729e6e8e52..0000000000 Binary files a/lib/metrics-core-2.0.3.jar and /dev/null differ diff --git a/lib/metrics-core-3.0.1.jar b/lib/metrics-core-3.0.1.jar new file mode 100644 index 0000000000..9b50dad6d0 Binary files /dev/null and b/lib/metrics-core-3.0.1.jar differ diff --git a/src/java/org/apache/cassandra/concurrent/JMXEnabledThreadPoolExecutor.java b/src/java/org/apache/cassandra/concurrent/JMXEnabledThreadPoolExecutor.java index de448b5a71..db75e8fb5e 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.count(); + return (int) metrics.totalBlocked.getCount(); } public int getCurrentlyBlockedTasks() { - return (int) metrics.currentBlocked.count(); + return (int) metrics.currentBlocked.getCount(); } public int getCoreThreads() diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java index 7b11672469..ec127365c8 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java @@ -26,6 +26,7 @@ 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; @@ -33,9 +34,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; @@ -66,6 +67,7 @@ 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; @@ -303,7 +305,6 @@ 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: @@ -359,17 +360,17 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public long getMinRowSize() { - return metric.minRowSize.value(); + return metric.minRowSize.getValue(); } public long getMaxRowSize() { - return metric.maxRowSize.value(); + return metric.maxRowSize.getValue(); } public long getMeanRowSize() { - return metric.meanRowSize.value(); + return metric.meanRowSize.getValue(); } public int getMeanColumns() @@ -737,8 +738,8 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean } } - if (metric.memtableSwitchCount.count() == Long.MAX_VALUE) - metric.memtableSwitchCount.clear(); + if (metric.memtableSwitchCount.getCount() == Long.MAX_VALUE) + metric.resetMemTableSwitchCount(); metric.memtableSwitchCount.inc(); // when all the memtables have been written, including for indexes, mark the flush in the commitlog header. @@ -837,7 +838,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean while (true) { long last = liveRatioComputedAt.get(); - long operations = metric.writeLatency.latency.count(); + long operations = metric.writeLatency.latency.getCount(); if (operations < 2 * last) break; if (liveRatioComputedAt.compareAndSet(last, operations)) @@ -1074,12 +1075,12 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public long getMemtableColumnsCount() { - return metric.memtableColumnsCount.value(); + return metric.memtableColumnsCount.getValue(); } public long getMemtableDataSize() { - return metric.memtableDataSize.value(); + return metric.memtableDataSize.getValue(); } public long getTotalMemtableLiveSize() @@ -1089,7 +1090,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public int getMemtableSwitchCount() { - return (int) metric.memtableSwitchCount.count(); + return (int) metric.memtableSwitchCount.getCount(); } private Memtable getMemtableThreadSafe() @@ -1127,7 +1128,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public long getReadCount() { - return metric.readLatency.latency.count(); + return metric.readLatency.latency.getCount(); } public double getRecentReadLatencyMicros() @@ -1147,22 +1148,22 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public long getTotalReadLatencyMicros() { - return metric.readLatency.totalLatency.count(); + return metric.readLatency.totalLatency.getCount(); } public int getPendingTasks() { - return metric.pendingTasks.value(); + return metric.pendingTasks.getValue(); } public long getWriteCount() { - return metric.writeLatency.latency.count(); + return metric.writeLatency.latency.getCount(); } public long getTotalWriteLatencyMicros() { - return metric.writeLatency.totalLatency.count(); + return metric.writeLatency.totalLatency.getCount(); } public double getRecentWriteLatencyMicros() @@ -1766,17 +1767,17 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public long getTotalDiskSpaceUsed() { - return metric.totalDiskSpaceUsed.count(); + return metric.totalDiskSpaceUsed.getCount(); } public long getLiveDiskSpaceUsed() { - return metric.liveDiskSpaceUsed.count(); + return metric.liveDiskSpaceUsed.getCount(); } public int getLiveSSTableCount() { - return metric.liveSSTableCount.value(); + return metric.liveSSTableCount.getValue(); } /** @@ -2028,27 +2029,27 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public long getBloomFilterFalsePositives() { - return metric.bloomFilterFalsePositives.value(); + return metric.bloomFilterFalsePositives.getValue(); } public long getRecentBloomFilterFalsePositives() { - return metric.recentBloomFilterFalsePositives.value(); + return metric.recentBloomFilterFalsePositives.getValue(); } public double getBloomFilterFalseRatio() { - return metric.bloomFilterFalseRatio.value(); + return metric.bloomFilterFalseRatio.getValue(); } public double getRecentBloomFilterFalseRatio() { - return metric.recentBloomFilterFalseRatio.value(); + return metric.recentBloomFilterFalseRatio.getValue(); } public long getBloomFilterDiskSpaceUsed() { - return metric.bloomFilterDiskSpaceUsed.value(); + return metric.bloomFilterDiskSpaceUsed.getValue(); } @Override @@ -2159,17 +2160,17 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public long[] getEstimatedRowSizeHistogram() { - return metric.estimatedRowSizeHistogram.value(); + return metric.estimatedRowSizeHistogram.getValue(); } public long[] getEstimatedColumnCountHistogram() { - return metric.estimatedColumnCountHistogram.value(); + return metric.estimatedColumnCountHistogram.getValue(); } public double getCompressionRatio() { - return metric.compressionRatio.value(); + return metric.compressionRatio.getValue(); } /** 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 78b43d30a5..33f23a557b 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.value(); + return metrics.completedTasks.getValue(); } /** @@ -273,7 +273,7 @@ public class CommitLog implements CommitLogMBean */ public long getPendingTasks() { - return metrics.pendingTasks.value(); + return metrics.pendingTasks.getValue(); } /** @@ -281,7 +281,7 @@ public class CommitLog implements CommitLogMBean */ public long getTotalCommitlogSize() { - return metrics.totalCommitLogSize.value(); + return metrics.totalCommitLogSize.getValue(); } /** diff --git a/src/java/org/apache/cassandra/db/compaction/CompactionManager.java b/src/java/org/apache/cassandra/db/compaction/CompactionManager.java index 35354c8975..4e0b4929be 100644 --- a/src/java/org/apache/cassandra/db/compaction/CompactionManager.java +++ b/src/java/org/apache/cassandra/db/compaction/CompactionManager.java @@ -874,22 +874,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 diff --git a/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java b/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java index ff8c70a82d..6b04b92063 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()); - 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; @@ -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,8 +265,7 @@ public class DynamicEndpointSnitch extends AbstractEndpointSnitch implements ILa private void reset() { - for (ExponentiallyDecayingSample sample : samples.values()) - sample.clear(); + samples.clear(); } public Map getScores() @@ -295,7 +294,7 @@ public class DynamicEndpointSnitch extends AbstractEndpointSnitch implements ILa { InetAddress host = InetAddress.getByName(hostname); ArrayList timings = new ArrayList(); - ExponentiallyDecayingSample sample = samples.get(host); + ExponentiallyDecayingReservoir 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 31575113df..ba98ab3184 100644 --- a/src/java/org/apache/cassandra/metrics/CacheMetrics.java +++ b/src/java/org/apache/cassandra/metrics/CacheMetrics.java @@ -17,14 +17,12 @@ */ 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.core.MetricName; -import com.yammer.metrics.util.RatioGauge; +import com.codahale.metrics.Gauge; +import com.codahale.metrics.Meter; +import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.RatioGauge; import org.apache.cassandra.cache.ICache; @@ -60,37 +58,43 @@ public class CacheMetrics */ public CacheMetrics(String type, final ICache cache) { - capacity = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "Capacity", type), new Gauge() + capacity = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Capacity", type), new Gauge() { - public Long value() + public Long getValue() { return cache.capacity(); } }); - 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() + 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() { protected double getNumerator() { - return hits.count(); + return hits.getCount(); } protected double getDenominator() { - return requests.count(); + return requests.getCount(); + } + + public Ratio getRatio() + { + return Ratio.of(getNumerator(), getDenominator()); } }); - size = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "Size", type), new Gauge() + size = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Size", type), new Gauge() { - public Long value() + public Long getValue() { return cache.weightedSize(); } }); - entries = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "Entries", type), new Gauge() + entries = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Entries", type), new Gauge() { - public Integer value() + public Integer getValue() { return cache.size(); } @@ -101,8 +105,8 @@ public class CacheMetrics @Deprecated public double getRecentHitRate() { - long r = requests.count(); - long h = hits.count(); + long r = requests.getCount(); + long h = hits.getCount(); 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 new file mode 100644 index 0000000000..2f2a855ef9 --- /dev/null +++ b/src/java/org/apache/cassandra/metrics/CassandraMetricRegistry.java @@ -0,0 +1,46 @@ +/* + * 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.Metric; +import com.codahale.metrics.MetricRegistry; + +public class CassandraMetricRegistry +{ + private static MetricRegistry defaultRegistry = new MetricRegistry(); + + 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 d6ff01bfea..89a5c73ceb 100644 --- a/src/java/org/apache/cassandra/metrics/ClientRequestMetrics.java +++ b/src/java/org/apache/cassandra/metrics/ClientRequestMetrics.java @@ -20,18 +20,16 @@ */ 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.MetricRegistry; +import com.codahale.metrics.Counter; +import com.codahale.metrics.Meter; public class ClientRequestMetrics extends LatencyMetrics { - @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"); + @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")); public final Meter timeouts; public final Meter unavailables; @@ -40,14 +38,14 @@ public class ClientRequestMetrics extends LatencyMetrics { super("org.apache.cassandra.metrics", "ClientRequest", scope); - timeouts = Metrics.newMeter(factory.createMetricName("Timeouts"), "timeouts", TimeUnit.SECONDS); - unavailables = Metrics.newMeter(factory.createMetricName("Unavailables"), "unavailables", TimeUnit.SECONDS); + timeouts = CassandraMetricRegistry.get().meter(factory.createMetricName("Timeouts")); + unavailables = CassandraMetricRegistry.get().meter(factory.createMetricName("Unavailables")); } public void release() { super.release(); - Metrics.defaultRegistry().removeMetric(factory.createMetricName("Timeouts")); - Metrics.defaultRegistry().removeMetric(factory.createMetricName("Unavailables")); + CassandraMetricRegistry.unregister(factory.createMetricName("Timeouts")); + CassandraMetricRegistry.unregister(factory.createMetricName("Unavailables")); } } diff --git a/src/java/org/apache/cassandra/metrics/ColumnFamilyMetrics.java b/src/java/org/apache/cassandra/metrics/ColumnFamilyMetrics.java index 96ab5386cd..0b1e5dedb8 100644 --- a/src/java/org/apache/cassandra/metrics/ColumnFamilyMetrics.java +++ b/src/java/org/apache/cassandra/metrics/ColumnFamilyMetrics.java @@ -17,19 +17,21 @@ */ package org.apache.cassandra.metrics; -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 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 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}. */ @@ -40,7 +42,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 final Counter memtableSwitchCount; + public Counter memtableSwitchCount; /** Current compression ratio for all SSTables */ public final Gauge compressionRatio; /** Histogram of estimated row size (in bytes). */ @@ -97,24 +99,24 @@ public class ColumnFamilyMetrics { factory = new ColumnFamilyMetricNameFactory(cfs); - memtableColumnsCount = Metrics.newGauge(factory.createMetricName("MemtableColumnsCount"), new Gauge() + memtableColumnsCount = CassandraMetricRegistry.register(factory.createMetricName("MemtableColumnsCount"), new Gauge() { - public Long value() + public Long getValue() { return cfs.getDataTracker().getMemtable().getOperations(); } }); - memtableDataSize = Metrics.newGauge(factory.createMetricName("MemtableDataSize"), new Gauge() + memtableDataSize = CassandraMetricRegistry.register(factory.createMetricName("MemtableDataSize"), new Gauge() { - public Long value() + public Long getValue() { return cfs.getDataTracker().getMemtable().getLiveSize(); } }); - memtableSwitchCount = Metrics.newCounter(factory.createMetricName("MemtableSwitchCount")); - estimatedRowSizeHistogram = Metrics.newGauge(factory.createMetricName("EstimatedRowSizeHistogram"), new Gauge() + memtableSwitchCount = CassandraMetricRegistry.get().counter(factory.createMetricName("MemtableSwitchCount")); + estimatedRowSizeHistogram = CassandraMetricRegistry.register(factory.createMetricName("EstimatedRowSizeHistogram"), new Gauge() { - public long[] value() + public long[] getValue() { long[] histogram = new long[90]; for (SSTableReader sstable : cfs.getSSTables()) @@ -126,9 +128,9 @@ public class ColumnFamilyMetrics return histogram; } }); - estimatedColumnCountHistogram = Metrics.newGauge(factory.createMetricName("EstimatedColumnCountHistogram"), new Gauge() + estimatedColumnCountHistogram = CassandraMetricRegistry.register(factory.createMetricName("EstimatedColumnCountHistogram"), new Gauge() { - public long[] value() + public long[] getValue() { long[] histogram = new long[90]; for (SSTableReader sstable : cfs.getSSTables()) @@ -140,10 +142,10 @@ public class ColumnFamilyMetrics return histogram; } }); - sstablesPerReadHistogram = Metrics.newHistogram(factory.createMetricName("SSTablesPerReadHistogram")); - compressionRatio = Metrics.newGauge(factory.createMetricName("CompressionRatio"), new Gauge() + sstablesPerReadHistogram = CassandraMetricRegistry.get().histogram(factory.createMetricName("SSTablesPerReadHistogram")); + compressionRatio = CassandraMetricRegistry.register(factory.createMetricName("CompressionRatio"), new Gauge() { - public Double value() + public Double getValue() { double sum = 0; int total = 0; @@ -160,26 +162,26 @@ public class ColumnFamilyMetrics }); readLatency = new LatencyMetrics(factory, "Read"); writeLatency = new LatencyMetrics(factory, "Write"); - pendingTasks = Metrics.newGauge(factory.createMetricName("PendingTasks"), new Gauge() + pendingTasks = CassandraMetricRegistry.register(factory.createMetricName("PendingTasks"), new Gauge() { - public Integer value() + public Integer getValue() { // TODO this actually isn't a good measure of pending tasks return Keyspace.switchLock.getQueueLength(); } }); - liveSSTableCount = Metrics.newGauge(factory.createMetricName("LiveSSTableCount"), new Gauge() + liveSSTableCount = CassandraMetricRegistry.register(factory.createMetricName("LiveSSTableCount"), new Gauge() { - public Integer value() + public Integer getValue() { return cfs.getDataTracker().getSSTables().size(); } }); - liveDiskSpaceUsed = Metrics.newCounter(factory.createMetricName("LiveDiskSpaceUsed")); - totalDiskSpaceUsed = Metrics.newCounter(factory.createMetricName("TotalDiskSpaceUsed")); - minRowSize = Metrics.newGauge(factory.createMetricName("MinRowSize"), new Gauge() + liveDiskSpaceUsed = CassandraMetricRegistry.get().counter(factory.createMetricName("LiveDiskSpaceUsed")); + totalDiskSpaceUsed = CassandraMetricRegistry.get().counter(factory.createMetricName("TotalDiskSpaceUsed")); + minRowSize = CassandraMetricRegistry.register(factory.createMetricName("MinRowSize"), new Gauge() { - public Long value() + public Long getValue() { long min = 0; for (SSTableReader sstable : cfs.getSSTables()) @@ -190,9 +192,9 @@ public class ColumnFamilyMetrics return min; } }); - maxRowSize = Metrics.newGauge(factory.createMetricName("MaxRowSize"), new Gauge() + maxRowSize = CassandraMetricRegistry.register(factory.createMetricName("MaxRowSize"), new Gauge() { - public Long value() + public Long getValue() { long max = 0; for (SSTableReader sstable : cfs.getSSTables()) @@ -203,9 +205,9 @@ public class ColumnFamilyMetrics return max; } }); - meanRowSize = Metrics.newGauge(factory.createMetricName("MeanRowSize"), new Gauge() + meanRowSize = CassandraMetricRegistry.register(factory.createMetricName("MeanRowSize"), new Gauge() { - public Long value() + public Long getValue() { long sum = 0; long count = 0; @@ -217,9 +219,9 @@ public class ColumnFamilyMetrics return count > 0 ? sum / count : 0; } }); - bloomFilterFalsePositives = Metrics.newGauge(factory.createMetricName("BloomFilterFalsePositives"), new Gauge() + bloomFilterFalsePositives = CassandraMetricRegistry.register(factory.createMetricName("BloomFilterFalsePositives"), new Gauge() { - public Long value() + public Long getValue() { long count = 0L; for (SSTableReader sstable: cfs.getSSTables()) @@ -227,9 +229,9 @@ public class ColumnFamilyMetrics return count; } }); - recentBloomFilterFalsePositives = Metrics.newGauge(factory.createMetricName("RecentBloomFilterFalsePositives"), new Gauge() + recentBloomFilterFalsePositives = CassandraMetricRegistry.register(factory.createMetricName("RecentBloomFilterFalsePositives"), new Gauge() { - public Long value() + public Long getValue() { long count = 0L; for (SSTableReader sstable: cfs.getSSTables()) @@ -237,9 +239,9 @@ public class ColumnFamilyMetrics return count; } }); - bloomFilterFalseRatio = Metrics.newGauge(factory.createMetricName("BloomFilterFalseRatio"), new Gauge() + bloomFilterFalseRatio = CassandraMetricRegistry.register(factory.createMetricName("BloomFilterFalseRatio"), new Gauge() { - public Double value() + public Double getValue() { long falseCount = 0L; long trueCount = 0L; @@ -253,9 +255,9 @@ public class ColumnFamilyMetrics return (double) falseCount / (trueCount + falseCount); } }); - recentBloomFilterFalseRatio = Metrics.newGauge(factory.createMetricName("RecentBloomFilterFalseRatio"), new Gauge() + recentBloomFilterFalseRatio = CassandraMetricRegistry.register(factory.createMetricName("RecentBloomFilterFalseRatio"), new Gauge() { - public Double value() + public Double getValue() { long falseCount = 0L; long trueCount = 0L; @@ -269,9 +271,9 @@ public class ColumnFamilyMetrics return (double) falseCount / (trueCount + falseCount); } }); - bloomFilterDiskSpaceUsed = Metrics.newGauge(factory.createMetricName("BloomFilterDiskSpaceUsed"), new Gauge() + bloomFilterDiskSpaceUsed = CassandraMetricRegistry.register(factory.createMetricName("BloomFilterDiskSpaceUsed"), new Gauge() { - public Long value() + public Long getValue() { long total = 0; for (SSTableReader sst : cfs.getSSTables()) @@ -279,8 +281,9 @@ public class ColumnFamilyMetrics return total; } }); - speculativeRetry = Metrics.newCounter(factory.createMetricName("SpeculativeRetry")); - keyCacheHitRate = Metrics.newGauge(factory.createMetricName("KeyCacheHitRate"), new RatioGauge() + + speculativeRetry = CassandraMetricRegistry.get().counter(factory.createMetricName("SpeculativeRetry")); + keyCacheHitRate = CassandraMetricRegistry.register(factory.createMetricName("KeyCacheHitRate"), new RatioGauge() { protected double getNumerator() { @@ -297,8 +300,19 @@ 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) { @@ -314,25 +328,25 @@ public class ColumnFamilyMetrics { readLatency.release(); writeLatency.release(); - 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")); + 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")); } class ColumnFamilyMetricNameFactory implements MetricNameFactory @@ -348,7 +362,7 @@ public class ColumnFamilyMetrics isIndex = cfs.isIndex(); } - public MetricName createMetricName(String metricName) + public String createMetricName(String metricName) { String groupName = ColumnFamilyMetrics.class.getPackage().getName(); String type = isIndex ? "IndexColumnFamily" : "ColumnFamily"; @@ -360,7 +374,7 @@ public class ColumnFamilyMetrics mbeanName.append(",scope=").append(columnFamilyName); mbeanName.append(",name=").append(metricName); - return new MetricName(groupName, type, metricName, keyspaceName + "." + columnFamilyName, mbeanName.toString()); + return MetricRegistry.name(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 598d2955e3..4b87038f2d 100644 --- a/src/java/org/apache/cassandra/metrics/CommitLogMetrics.java +++ b/src/java/org/apache/cassandra/metrics/CommitLogMetrics.java @@ -17,9 +17,8 @@ */ package org.apache.cassandra.metrics; -import com.yammer.metrics.Metrics; -import com.yammer.metrics.core.Gauge; -import com.yammer.metrics.core.MetricName; +import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.Gauge; import org.apache.cassandra.db.commitlog.CommitLogAllocator; import org.apache.cassandra.db.commitlog.ICommitLogExecutorService; @@ -41,23 +40,23 @@ public class CommitLogMetrics public CommitLogMetrics(final ICommitLogExecutorService executor, final CommitLogAllocator allocator) { - completedTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "CompletedTasks"), new Gauge() + completedTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "CompletedTasks"), new Gauge() { - public Long value() + public Long getValue() { return executor.getCompletedTasks(); } }); - pendingTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "PendingTasks"), new Gauge() + pendingTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "PendingTasks"), new Gauge() { - public Long value() + public Long getValue() { return executor.getPendingTasks(); } }); - totalCommitLogSize = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "TotalCommitLogSize"), new Gauge() + totalCommitLogSize = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "TotalCommitLogSize"), new Gauge() { - public Long value() + public Long getValue() { return allocator.bytesUsed(); } diff --git a/src/java/org/apache/cassandra/metrics/CompactionMetrics.java b/src/java/org/apache/cassandra/metrics/CompactionMetrics.java index dd3803fca3..267d2922f8 100644 --- a/src/java/org/apache/cassandra/metrics/CompactionMetrics.java +++ b/src/java/org/apache/cassandra/metrics/CompactionMetrics.java @@ -19,13 +19,11 @@ 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.yammer.metrics.core.MetricName; +import com.codahale.metrics.MetricRegistry; +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; @@ -55,9 +53,9 @@ public class CompactionMetrics implements CompactionManager.CompactionExecutorSt public CompactionMetrics(final ThreadPoolExecutor... collectors) { - pendingTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "PendingTasks"), new Gauge() + pendingTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "PendingTasks"), new Gauge() { - public Integer value() + public Integer getValue() { int n = 0; for (String keyspaceName : Schema.instance.getKeyspaces()) @@ -70,9 +68,9 @@ public class CompactionMetrics implements CompactionManager.CompactionExecutorSt return n; } }); - completedTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "CompletedTasks"), new Gauge() + completedTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "CompletedTasks"), new Gauge() { - public Long value() + public Long getValue() { long completedTasks = 0; for (ThreadPoolExecutor collector : collectors) @@ -80,8 +78,8 @@ public class CompactionMetrics implements CompactionManager.CompactionExecutorSt return completedTasks; } }); - totalCompactionsCompleted = Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "TotalCompactionsCompleted"), "compaction completed", TimeUnit.SECONDS); - bytesCompacted = Metrics.newCounter(new MetricName(GROUP_NAME, TYPE_NAME, "BytesCompacted")); + totalCompactionsCompleted = CassandraMetricRegistry.get().meter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "TotalCompactionsCompleted")); + bytesCompacted = CassandraMetricRegistry.get().counter(MetricRegistry.name(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 5493505c95..24d3bbd42d 100644 --- a/src/java/org/apache/cassandra/metrics/ConnectionMetrics.java +++ b/src/java/org/apache/cassandra/metrics/ConnectionMetrics.java @@ -18,12 +18,10 @@ 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.yammer.metrics.core.MetricName; +import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.Gauge; +import com.codahale.metrics.Meter; import org.apache.cassandra.net.OutboundTcpConnectionPool; @@ -36,7 +34,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(new MetricName(GROUP_NAME, TYPE_NAME, "TotalTimeouts"), "total timeouts", TimeUnit.SECONDS); + public static final Meter totalTimeouts = CassandraMetricRegistry.get().meter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "TotalTimeouts")); private static long recentTimeouts; public final String address; @@ -66,58 +64,58 @@ public class ConnectionMetrics // ipv6 addresses will contain colons, which are invalid in a JMX ObjectName address = ip.getHostAddress().replaceAll(":", "."); - commandPendingTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "CommandPendingTasks", address), new Gauge() + commandPendingTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "CommandPendingTasks", address), new Gauge() { - public Integer value() + public Integer getValue() { return connectionPool.cmdCon.getPendingMessages(); } }); - commandCompletedTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "CommandCompletedTasks", address), new Gauge() + commandCompletedTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "CommandCompletedTasks", address), new Gauge() { - public Long value() + public Long getValue() { return connectionPool.cmdCon.getCompletedMesssages(); } }); - commandDroppedTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "CommandDroppedTasks", address), new Gauge() + commandDroppedTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "CommandDroppedTasks", address), new Gauge() { - public Long value() + public Long getValue() { return connectionPool.cmdCon.getDroppedMessages(); } }); - responsePendingTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "ResponsePendingTasks", address), new Gauge() + responsePendingTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "ResponsePendingTasks", address), new Gauge() { - public Integer value() + public Integer getValue() { return connectionPool.ackCon.getPendingMessages(); } }); - responseCompletedTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "ResponseCompletedTasks", address), new Gauge() + responseCompletedTasks = CassandraMetricRegistry.register(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "ResponseCompletedTasks", address), new Gauge() { - public Long value() + public Long getValue() { return connectionPool.ackCon.getCompletedMesssages(); } }); - timeouts = Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "Timeouts", address), "timeouts", TimeUnit.SECONDS); + timeouts = CassandraMetricRegistry.get().meter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Timeouts", address)); } public void release() { - 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)); + 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)); } @Deprecated public static long getRecentTotalTimeout() { - long total = totalTimeouts.count(); + long total = totalTimeouts.getCount(); long recent = total - recentTimeouts; recentTimeouts = total; return recent; @@ -126,7 +124,7 @@ public class ConnectionMetrics @Deprecated public long getRecentTimeout() { - long timeoutCount = timeouts.count(); + long timeoutCount = timeouts.getCount(); 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 e0b12bb489..9e77f24305 100644 --- a/src/java/org/apache/cassandra/metrics/DroppedMessageMetrics.java +++ b/src/java/org/apache/cassandra/metrics/DroppedMessageMetrics.java @@ -17,11 +17,8 @@ */ package org.apache.cassandra.metrics; -import java.util.concurrent.TimeUnit; - -import com.yammer.metrics.Metrics; -import com.yammer.metrics.core.Meter; -import com.yammer.metrics.core.MetricName; +import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.Meter; import org.apache.cassandra.net.MessagingService; @@ -40,13 +37,13 @@ public class DroppedMessageMetrics public DroppedMessageMetrics(MessagingService.Verb verb) { - dropped = Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "Dropped", verb.toString()), "dropped", TimeUnit.SECONDS); + dropped = CassandraMetricRegistry.get().meter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Dropped", verb.toString())); } @Deprecated public int getRecentlyDropped() { - long currentDropped = dropped.count(); + long currentDropped = dropped.getCount(); 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 0f3992fa23..a4cf004617 100644 --- a/src/java/org/apache/cassandra/metrics/HintedHandoffMetrics.java +++ b/src/java/org/apache/cassandra/metrics/HintedHandoffMetrics.java @@ -29,9 +29,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 com.yammer.metrics.core.MetricName; +import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.Counter; /** * Metrics for {@link HintedHandOffManager}. @@ -57,7 +56,7 @@ public class HintedHandoffMetrics { public Counter load(InetAddress address) { - return Metrics.newCounter(new MetricName(GROUP_NAME, TYPE_NAME, "Hints_created-" + address.getHostAddress())); + return CassandraMetricRegistry.get().counter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Hints_created-" + address.getHostAddress())); } }); @@ -90,12 +89,12 @@ public class HintedHandoffMetrics public DifferencingCounter(InetAddress address) { - this.meter = Metrics.newCounter(new MetricName(GROUP_NAME, TYPE_NAME, "Hints_not_stored-" + address.getHostAddress())); + this.meter = CassandraMetricRegistry.get().counter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Hints_not_stored-" + address.getHostAddress())); } public long diffrence() { - long current = meter.count(); + long current = meter.getCount(); long diffrence = current - reported; this.reported = current; return diffrence; @@ -103,7 +102,7 @@ public class HintedHandoffMetrics public long count() { - return meter.count(); + return meter.getCount(); } public void mark() diff --git a/src/java/org/apache/cassandra/metrics/LatencyMetrics.java b/src/java/org/apache/cassandra/metrics/LatencyMetrics.java index d17761324d..76a1f26e24 100644 --- a/src/java/org/apache/cassandra/metrics/LatencyMetrics.java +++ b/src/java/org/apache/cassandra/metrics/LatencyMetrics.java @@ -19,10 +19,9 @@ 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.MetricName; -import com.yammer.metrics.core.Timer; +import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.Counter; +import com.codahale.metrics.Timer; import org.apache.cassandra.utils.EstimatedHistogram; @@ -80,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 = CassandraMetricRegistry.get().timer(factory.createMetricName(namePrefix + "Latency")); + totalLatency = CassandraMetricRegistry.get().counter(factory.createMetricName(namePrefix + "TotalLatency")); } /** takes nanoseconds **/ @@ -101,15 +100,15 @@ public class LatencyMetrics public void release() { - Metrics.defaultRegistry().removeMetric(factory.createMetricName(namePrefix + "Latency")); - Metrics.defaultRegistry().removeMetric(factory.createMetricName(namePrefix + "TotalLatency")); + CassandraMetricRegistry.unregister(factory.createMetricName(namePrefix + "Latency")); + CassandraMetricRegistry.unregister(factory.createMetricName(namePrefix + "TotalLatency")); } @Deprecated public double getRecentLatency() { - long ops = latency.count(); - long n = totalLatency.count(); + long ops = latency.getCount(); + long n = totalLatency.getCount(); try { return ((double) n - lastLatency) / (ops - lastOpCount); @@ -134,9 +133,9 @@ public class LatencyMetrics this.scope = scope; } - public MetricName createMetricName(String metricName) + public String createMetricName(String metricName) { - return new MetricName(group, type, metricName, scope); + return MetricRegistry.name(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 5c1a5c23db..d728e40d18 100644 --- a/src/java/org/apache/cassandra/metrics/MetricNameFactory.java +++ b/src/java/org/apache/cassandra/metrics/MetricNameFactory.java @@ -17,8 +17,6 @@ */ package org.apache.cassandra.metrics; -import com.yammer.metrics.core.MetricName; - public interface MetricNameFactory { /** @@ -27,5 +25,5 @@ public interface MetricNameFactory * @param metricName Name part of {@link MetricName}. * @return new MetricName with given metric name. */ - MetricName createMetricName(String metricName); + String createMetricName(String metricName); } diff --git a/src/java/org/apache/cassandra/metrics/ReadRepairMetrics.java b/src/java/org/apache/cassandra/metrics/ReadRepairMetrics.java index c67ed90288..605876c486 100644 --- a/src/java/org/apache/cassandra/metrics/ReadRepairMetrics.java +++ b/src/java/org/apache/cassandra/metrics/ReadRepairMetrics.java @@ -20,12 +20,8 @@ package org.apache.cassandra.metrics; * */ - -import java.util.concurrent.TimeUnit; - -import com.yammer.metrics.Metrics; -import com.yammer.metrics.core.Meter; -import com.yammer.metrics.core.MetricName; +import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.Meter; /** * Metrics related to Read Repair. @@ -35,9 +31,9 @@ public class ReadRepairMetrics { public static final String TYPE_NAME = "ReadRepair"; public static final Meter repairedBlocking = - Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "RepairedBlocking"), "RepairedBlocking", TimeUnit.SECONDS); + CassandraMetricRegistry.get().meter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "RepairedBlocking")); public static final Meter repairedBackground = - Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "RepairedBackground"), "RepairedBackground", TimeUnit.SECONDS); + CassandraMetricRegistry.get().meter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "RepairedBackground")); public static final Meter attempted = - Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "Attempted"), "Attempted", TimeUnit.SECONDS); + CassandraMetricRegistry.get().meter(MetricRegistry.name(GROUP_NAME, TYPE_NAME, "Attempted")); } diff --git a/src/java/org/apache/cassandra/metrics/StorageMetrics.java b/src/java/org/apache/cassandra/metrics/StorageMetrics.java index 3cda71e61f..02e8e122b8 100644 --- a/src/java/org/apache/cassandra/metrics/StorageMetrics.java +++ b/src/java/org/apache/cassandra/metrics/StorageMetrics.java @@ -17,14 +17,13 @@ */ package org.apache.cassandra.metrics; -import com.yammer.metrics.Metrics; -import com.yammer.metrics.core.Counter; -import com.yammer.metrics.core.MetricName; +import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.Counter; /** * Metrics related to Storage. */ public class StorageMetrics { - public static final Counter load = Metrics.newCounter(new MetricName("org.apache.cassandra.metrics", "Storage", "Load")); + public static final Counter load = CassandraMetricRegistry.get().counter(MetricRegistry.name("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 96c79c9719..bca50d8598 100644 --- a/src/java/org/apache/cassandra/metrics/StreamingMetrics.java +++ b/src/java/org/apache/cassandra/metrics/StreamingMetrics.java @@ -20,9 +20,8 @@ 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.yammer.metrics.core.MetricName; +import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.Counter; import org.cliffc.high_scale_lib.NonBlockingHashMap; /** @@ -35,9 +34,9 @@ public class StreamingMetrics private static final ConcurrentMap instances = new NonBlockingHashMap(); - 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 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 final Counter incomingBytes; public final Counter outgoingBytes; @@ -54,7 +53,7 @@ public class StreamingMetrics public StreamingMetrics(final InetAddress peer) { - 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(":", "."))); + 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(":", "."))); } } diff --git a/src/java/org/apache/cassandra/metrics/ThreadPoolMetrics.java b/src/java/org/apache/cassandra/metrics/ThreadPoolMetrics.java index af54cdb835..2a3776ed18 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.yammer.metrics.Metrics; -import com.yammer.metrics.core.*; +import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.*; /** * Metrics for {@link ThreadPoolExecutor}. @@ -54,25 +54,25 @@ public class ThreadPoolMetrics { this.factory = new ThreadPoolMetricNameFactory(path, poolName); - activeTasks = Metrics.newGauge(factory.createMetricName("ActiveTasks"), new Gauge() + activeTasks = CassandraMetricRegistry.register(factory.createMetricName("ActiveTasks"), new Gauge() { - 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() + totalBlocked = CassandraMetricRegistry.get().counter(factory.createMetricName("TotalBlockedTasks")); + currentBlocked = CassandraMetricRegistry.get().counter(factory.createMetricName("CurrentlyBlockedTasks")); + completedTasks = CassandraMetricRegistry.register(factory.createMetricName("CompletedTasks"), new Gauge() { - public Long value() + public Long getValue() { return executor.getCompletedTaskCount(); } }); - pendingTasks = Metrics.newGauge(factory.createMetricName("PendingTasks"), new Gauge() + pendingTasks = CassandraMetricRegistry.register(factory.createMetricName("PendingTasks"), new Gauge() { - public Long value() + public Long getValue() { return executor.getTaskCount() - executor.getCompletedTaskCount(); } @@ -81,11 +81,11 @@ 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")); + 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")); } class ThreadPoolMetricNameFactory implements MetricNameFactory @@ -99,7 +99,7 @@ public class ThreadPoolMetrics this.poolName = poolName; } - public MetricName createMetricName(String metricName) + public String 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 new MetricName(groupName, type, metricName, path + "." + poolName, mbeanName.toString()); + return MetricRegistry.name(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 40b9f0ef3f..ac89e71e1e 100644 --- a/src/java/org/apache/cassandra/net/MessagingService.java +++ b/src/java/org/apache/cassandra/net/MessagingService.java @@ -782,7 +782,7 @@ public final class MessagingService implements MessagingServiceMBean boolean logTpstats = false; for (Map.Entry 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) @@ -919,7 +919,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.count()); + map.put(entry.getKey().toString(), (int) entry.getValue().dropped.getCount()); return map; } @@ -933,7 +933,7 @@ public final class MessagingService implements MessagingServiceMBean public long getTotalTimeouts() { - return ConnectionMetrics.totalTimeouts.count(); + return ConnectionMetrics.totalTimeouts.getCount(); } public long getRecentTotalTimouts() diff --git a/src/java/org/apache/cassandra/net/OutboundTcpConnectionPool.java b/src/java/org/apache/cassandra/net/OutboundTcpConnectionPool.java index 81168c6873..87312e45e0 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.count(); + return metrics.timeouts.getCount(); } public long getRecentTimeouts() diff --git a/src/java/org/apache/cassandra/scheduler/WeightedQueue.java b/src/java/org/apache/cassandra/scheduler/WeightedQueue.java index 2d2e0bd192..b3ea53d9bd 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.count(); + return metric.latency.getCount(); } public long getTotalLatencyMicros() { - return metric.totalLatency.count(); + return metric.totalLatency.getCount(); } public double getRecentLatencyMicros() diff --git a/src/java/org/apache/cassandra/service/CacheService.java b/src/java/org/apache/cassandra/service/CacheService.java index b787b75fa3..16afc5aaf2 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.count(); + return keyCache.getMetrics().hits.getCount(); } public long getRowCacheHits() { - return rowCache.getMetrics().hits.count(); + return rowCache.getMetrics().hits.getCount(); } public long getKeyCacheRequests() { - return keyCache.getMetrics().requests.count(); + return keyCache.getMetrics().requests.getCount(); } public long getRowCacheRequests() { - return rowCache.getMetrics().requests.count(); + return rowCache.getMetrics().requests.getCount(); } public double getKeyCacheRecentHitRate() @@ -219,7 +219,7 @@ public class CacheService implements CacheServiceMBean public long getRowCacheCapacityInBytes() { - return rowCache.getMetrics().capacity.value(); + return rowCache.getMetrics().capacity.getValue(); } public long getRowCacheCapacityInMB() @@ -237,7 +237,7 @@ public class CacheService implements CacheServiceMBean public long getKeyCacheCapacityInBytes() { - return keyCache.getMetrics().capacity.value(); + return keyCache.getMetrics().capacity.getValue(); } public long getKeyCacheCapacityInMB() @@ -255,7 +255,7 @@ public class CacheService implements CacheServiceMBean public long getRowCacheSize() { - return rowCache.getMetrics().size.value(); + return rowCache.getMetrics().size.getValue(); } public long getRowCacheEntries() @@ -265,7 +265,7 @@ public class CacheService implements CacheServiceMBean public long getKeyCacheSize() { - return keyCache.getMetrics().size.value(); + return keyCache.getMetrics().size.getValue(); } public long getKeyCacheEntries() diff --git a/src/java/org/apache/cassandra/service/StorageProxy.java b/src/java/org/apache/cassandra/service/StorageProxy.java index fb5cbe4f85..2056b497b2 100644 --- a/src/java/org/apache/cassandra/service/StorageProxy.java +++ b/src/java/org/apache/cassandra/service/StorageProxy.java @@ -1668,12 +1668,12 @@ public class StorageProxy implements StorageProxyMBean public long getReadOperations() { - return readMetrics.latency.count(); + return readMetrics.latency.getCount(); } public long getTotalReadLatencyMicros() { - return readMetrics.totalLatency.count(); + return readMetrics.totalLatency.getCount(); } public double getRecentReadLatencyMicros() @@ -1693,12 +1693,12 @@ public class StorageProxy implements StorageProxyMBean public long getRangeOperations() { - return rangeMetrics.latency.count(); + return rangeMetrics.latency.getCount(); } public long getTotalRangeLatencyMicros() { - return rangeMetrics.totalLatency.count(); + return rangeMetrics.totalLatency.getCount(); } public double getRecentRangeLatencyMicros() @@ -1718,12 +1718,12 @@ public class StorageProxy implements StorageProxyMBean public long getWriteOperations() { - return writeMetrics.latency.count(); + return writeMetrics.latency.getCount(); } public long getTotalWriteLatencyMicros() { - return writeMetrics.totalLatency.count(); + return writeMetrics.totalLatency.getCount(); } public double getRecentWriteLatencyMicros() @@ -1988,14 +1988,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(); } } diff --git a/test/unit/org/apache/cassandra/db/KeyspaceTest.java b/test/unit/org/apache/cassandra/db/KeyspaceTest.java index faee4e714f..9b5b6dd734 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.max(), 5, 0.1); + assertEquals(cfStore.metric.sstablesPerReadHistogram.getSnapshot().getMax(), 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.max(), 5, 0.1); + assertEquals(cfStore.metric.sstablesPerReadHistogram.getSnapshot().getMax(), 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.max(), 5, 0.1); + assertEquals(cfStore.metric.sstablesPerReadHistogram.getSnapshot().getMax(), 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.max(), 0.1); + assertEquals(2, cfs.metric.sstablesPerReadHistogram.getSnapshot().getMax(), 0.1); } private void validateSliceLarge(ColumnFamilyStore cfStore) throws IOException diff --git a/tools/stress/src/org/apache/cassandra/stress/Session.java b/tools/stress/src/org/apache/cassandra/stress/Session.java index f19d61e4a9..d51ea206f3 100644 --- a/tools/stress/src/org/apache/cassandra/stress/Session.java +++ b/tools/stress/src/org/apache/cassandra/stress/Session.java @@ -17,30 +17,41 @@ */ package org.apache.cassandra.stress; -import java.io.*; +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.net.InetAddress; import java.net.UnknownHostException; import java.nio.ByteBuffer; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; -import com.yammer.metrics.Metrics; +import com.codahale.metrics.MetricRegistry; + import org.apache.cassandra.cli.transport.FramedTransportFactory; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.EncryptionOptions; import org.apache.cassandra.config.EncryptionOptions.ClientEncryptionOptions; +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.db.marshal.*; -import org.apache.commons.cli.*; - -import org.apache.cassandra.db.ColumnFamilyType; +import org.apache.cassandra.metrics.CassandraMetricRegistry; import org.apache.cassandra.stress.util.CassandraClient; -import org.apache.cassandra.transport.SimpleClient; import org.apache.cassandra.thrift.*; -import org.apache.commons.lang.StringUtils; - +import org.apache.cassandra.transport.SimpleClient; import org.apache.cassandra.utils.ByteBufferUtil; +import org.apache.commons.cli.*; +import org.apache.commons.lang.StringUtils; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TTransport; @@ -59,7 +70,7 @@ public class Session implements Serializable public final AtomicInteger operations = new AtomicInteger(); public final AtomicInteger keys = new AtomicInteger(); - public final com.yammer.metrics.core.Timer latency = Metrics.newTimer(Session.class, "latency"); + public final com.codahale.metrics.Timer latency = CassandraMetricRegistry.get().timer(MetricRegistry.name(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 ea84647a77..1ad49f3999 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.yammer.metrics.stats.Snapshot; +import com.codahale.metrics.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 4afac5ada6..d448de729e 100644 --- a/tools/stress/src/org/apache/cassandra/stress/StressStatistics.java +++ b/tools/stress/src/org/apache/cassandra/stress/StressStatistics.java @@ -18,7 +18,7 @@ package org.apache.cassandra.stress; -import com.yammer.metrics.stats.Snapshot; +import com.codahale.metrics.Snapshot; import java.io.PrintStream; import org.apache.commons.lang.time.DurationFormatUtils; 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 ab6ae9ded8..39c258661f 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.yammer.metrics.core.TimerContext; +import com.codahale.metrics.Timer.Context; 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)); - TimerContext context = session.latency.time(); + Context 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 56ef2434c8..2980df9228 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CounterGetter.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CounterGetter.java @@ -17,17 +17,22 @@ */ package org.apache.cassandra.stress.operations; -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.db.ColumnFamilyType; -import org.apache.cassandra.thrift.*; - 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 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; + public class CounterGetter extends Operation { public CounterGetter(Session client, int index) @@ -68,7 +73,7 @@ public class CounterGetter extends Operation String superColumn = 'S' + Integer.toString(j); ColumnParent parent = new ColumnParent("SuperCounter1").setSuper_column(superColumn.getBytes()); - TimerContext context = session.latency.time(); + Context context = session.latency.time(); boolean success = false; String exceptionMessage = null; @@ -113,7 +118,7 @@ public class CounterGetter extends Operation byte[] key = generateKey(); ByteBuffer keyBuffer = ByteBuffer.wrap(key); - TimerContext context = session.latency.time(); + Context 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 31e8371dd5..3569af5aee 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.yammer.metrics.core.TimerContext; +import com.codahale.metrics.Timer.Context; 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"))); - TimerContext context = session.latency.time(); + Context 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 a4d037a97e..0a1dfdf944 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.yammer.metrics.core.TimerContext; +import com.codahale.metrics.Timer.Context; 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"))); - TimerContext context = session.latency.time(); + Context 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 bf416cc952..52fe73f08f 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.yammer.metrics.core.TimerContext; +import com.codahale.metrics.Timer.Context; 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) { - TimerContext context = session.latency.time(); + Context 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 3572c36bf2..10d060ee3b 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.yammer.metrics.core.TimerContext; +import com.codahale.metrics.Timer.Context; 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"))); - TimerContext context = session.latency.time(); + Context 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 c01767bc56..d1329bfeb2 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.yammer.metrics.core.TimerContext; +import com.codahale.metrics.Timer.Context; 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"))); - TimerContext context = session.latency.time(); + Context 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 70273c1d1b..c53535c2bf 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.yammer.metrics.core.TimerContext; +import com.codahale.metrics.Timer.Context; 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"))); - TimerContext context = session.latency.time(); + Context 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 b7c72a27e7..44e915c2b4 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.yammer.metrics.core.TimerContext; +import com.codahale.metrics.Timer.Context; 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; - TimerContext context = session.latency.time(); + Context 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 cbf6b984a3..35c74716b5 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.yammer.metrics.core.TimerContext; +import com.codahale.metrics.Timer.Context; 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); - TimerContext context = session.latency.time(); + Context 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 12a39fb3c9..b0657f0def 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.yammer.metrics.core.TimerContext; +import com.codahale.metrics.Timer.Context; 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)); - TimerContext context = session.latency.time(); + Context 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()); - TimerContext context = session.latency.time(); + Context 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 f9ba1154d6..d1b52b49f9 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.yammer.metrics.core.TimerContext; +import com.codahale.metrics.Timer.Context; 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)); - TimerContext context = session.latency.time(); + Context 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); - TimerContext context = session.latency.time(); + Context 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 f75502a54b..e15241fb44 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.yammer.metrics.core.TimerContext; +import com.codahale.metrics.Timer.Context; 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)); - TimerContext context = session.latency.time(); + Context 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); - TimerContext context = session.latency.time(); + Context context = session.latency.time(); boolean success = false; String exceptionMessage = null;