cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brandonwilli...@apache.org
Subject [15/20] git commit: Track metrics at a keyspace level
Date Fri, 13 Jun 2014 12:54:04 GMT
Track metrics at a keyspace level

Patch by brandonwilliams, reviewed by yukim for CASSANDRA-6539


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/68dd6349
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/68dd6349
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/68dd6349

Branch: refs/heads/trunk
Commit: 68dd6349551f5b26b399a80f38624e02bf89a9b4
Parents: 6eda57c
Author: Brandon Williams <brandonwilliams@apache.org>
Authored: Thu Jun 12 18:42:21 2014 -0500
Committer: Brandon Williams <brandonwilliams@apache.org>
Committed: Fri Jun 13 07:49:22 2014 -0500

----------------------------------------------------------------------
 .../cassandra/metrics/KeyspaceMetrics.java      | 202 +++++++++++++++++++
 1 file changed, 202 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/68dd6349/src/java/org/apache/cassandra/metrics/KeyspaceMetrics.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/metrics/KeyspaceMetrics.java b/src/java/org/apache/cassandra/metrics/KeyspaceMetrics.java
new file mode 100644
index 0000000..4a0980f
--- /dev/null
+++ b/src/java/org/apache/cassandra/metrics/KeyspaceMetrics.java
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cassandra.metrics;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.yammer.metrics.Metrics;
+import com.yammer.metrics.core.*;
+import com.yammer.metrics.stats.Snapshot;
+
+import org.apache.cassandra.db.ColumnFamilyStore;
+import org.apache.cassandra.db.Keyspace;
+
+/**
+ * Metrics for {@link ColumnFamilyStore}.
+ */
+public class KeyspaceMetrics
+{
+    /** Total amount of data stored in the memtable, including column related overhead. */
+    public final Gauge<Long> memtableDataSize;
+    /** Total amount of data stored in the memtables (2i and pending flush memtables included).
*/
+    public final Gauge<Long> allMemtablesDataSize;
+    /** Total number of columns present in the memtable. */
+    public final Gauge<Long> memtableColumnsCount;
+    /** Number of times flush has resulted in the memtable being switched out. */
+    public final Gauge<Long> memtableSwitchCount;
+    /** Estimated number of tasks pending for this column family */
+    public final Gauge<Integer> pendingTasks;
+    /** Estimate of number of pending compactios for this CF */
+    public final Gauge<Integer> pendingCompactions;
+    /** Disk space used by SSTables belonging to this CF */
+    public final Gauge<Long> liveDiskSpaceUsed;
+    /** Total disk space used by SSTables belonging to this CF, including obsolete ones waiting
to be GC'd */
+    public final Gauge<Long> totalDiskSpaceUsed;
+    /** Disk space used by bloom filter */
+    public final Gauge<Long> bloomFilterDiskSpaceUsed;
+
+    private final MetricNameFactory factory;
+
+    /**
+     * Creates metrics for given {@link ColumnFamilyStore}.
+     *
+     * @param ks Keyspace to measure metrics
+     */
+    public KeyspaceMetrics(final Keyspace ks)
+    {
+        factory = new KeyspaceMetricNameFactory(ks);
+
+        memtableColumnsCount = Metrics.newGauge(factory.createMetricName("MemtableColumnsCount"),
new Gauge<Long>()
+        {
+            public Long value()
+            {
+                long total = 0;
+                for (ColumnFamilyStore cf : ks.getColumnFamilyStores())
+                {
+                    total += cf.metric.memtableColumnsCount.value();
+                }
+                return total;
+            }
+        });
+        memtableDataSize = Metrics.newGauge(factory.createMetricName("MemtableDataSize"),
new Gauge<Long>()
+        {
+            public Long value()
+            {
+                long total = 0;
+                for (ColumnFamilyStore cf : ks.getColumnFamilyStores())
+                {
+                    total += cf.metric.memtableDataSize.value();
+                }
+                return total;
+            }
+        });
+        allMemtablesDataSize = Metrics.newGauge(factory.createMetricName("AllMemtablesDataSize"),
new Gauge<Long>()
+        {
+            public Long value()
+            {
+                long total = 0;
+                for (ColumnFamilyStore cf : ks.getColumnFamilyStores())
+                {
+                    total += cf.metric.allMemtablesDataSize.value();
+                }
+                return total;
+            }
+        });
+        memtableSwitchCount = Metrics.newGauge(factory.createMetricName("MemtableSwitchCount"),
new Gauge<Long>()
+        {
+            public Long value()
+            {
+                long sum = 0;
+                for (ColumnFamilyStore cf : ks.getColumnFamilyStores())
+                    sum += cf.metric.memtableSwitchCount.count();
+                return sum;
+            }
+        });
+        pendingCompactions = Metrics.newGauge(factory.createMetricName("PendingCompactions"),
new Gauge<Integer>()
+        {
+            public Integer value()
+            {
+                int sum = 0;
+                for (ColumnFamilyStore cf : ks.getColumnFamilyStores())
+                {
+                    sum += cf.metric.pendingCompactions.value();
+                }
+                return sum;
+            }
+        });
+        pendingTasks = Metrics.newGauge(factory.createMetricName("PendingTasks"), new Gauge<Integer>()
+        {
+            public Integer value()
+            {
+                return Keyspace.switchLock.getQueueLength();
+            }
+        });
+        liveDiskSpaceUsed = Metrics.newGauge(factory.createMetricName("LiveDiskSpaceUsed"),
new Gauge<Long>()
+        {
+            public Long value()
+            {
+                long sum = 0;
+                for (ColumnFamilyStore cf : ks.getColumnFamilyStores())
+                {
+                    sum += cf.metric.liveDiskSpaceUsed.count();
+                }
+                return sum;
+            }
+        });
+        totalDiskSpaceUsed = Metrics.newGauge(factory.createMetricName("TotalDiskSpaceUsed"),
new Gauge<Long>()
+        {
+            public Long value()
+            {
+                long sum = 0;
+                for (ColumnFamilyStore cf : ks.getColumnFamilyStores())
+                {
+                    sum += cf.metric.totalDiskSpaceUsed.count();
+                }
+                return sum;
+            }
+        });
+        bloomFilterDiskSpaceUsed = Metrics.newGauge(factory.createMetricName("BloomFilterDiskSpaceUsed"),
new Gauge<Long>()
+        {
+            public Long value()
+            {
+                long total = 0;
+                for (ColumnFamilyStore cf : ks.getColumnFamilyStores())
+                    total += cf.metric.bloomFilterDiskSpaceUsed.value();
+                return total;
+            }
+        });
+    }
+
+    /**
+     * Release all associated metrics.
+     */
+    public void release()
+    {
+        Metrics.defaultRegistry().removeMetric(factory.createMetricName("AllMemtablesDataSize"));
+        Metrics.defaultRegistry().removeMetric(factory.createMetricName("MemtableDataSize"));
+        Metrics.defaultRegistry().removeMetric(factory.createMetricName("MemtableSwitchCount"));
+        Metrics.defaultRegistry().removeMetric(factory.createMetricName("PendingTasks"));
+        Metrics.defaultRegistry().removeMetric(factory.createMetricName("LiveDiskSpaceUsed"));
+        Metrics.defaultRegistry().removeMetric(factory.createMetricName("TotalDiskSpaceUsed"));
+        Metrics.defaultRegistry().removeMetric(factory.createMetricName("BloomFilterDiskSpaceUsed"));
+    }
+
+    class KeyspaceMetricNameFactory implements MetricNameFactory
+    {
+        private final String keyspaceName;
+
+        KeyspaceMetricNameFactory(Keyspace ks)
+        {
+            this.keyspaceName = ks.getName();
+        }
+
+        public MetricName createMetricName(String metricName)
+        {
+            String groupName = ColumnFamilyMetrics.class.getPackage().getName();
+
+            StringBuilder mbeanName = new StringBuilder();
+            mbeanName.append(groupName).append(":");
+            mbeanName.append("type=Keyspace");
+            mbeanName.append(",keyspace=").append(keyspaceName);
+            mbeanName.append(",name=").append(metricName);
+
+            return new MetricName(groupName, "keyspace", metricName, keyspaceName, mbeanName.toString());
+        }
+    }
+}


Mime
View raw message