Example usage for org.apache.cassandra.io.sstable.format SSTableReader getBloomFilterSerializedSize

List of usage examples for org.apache.cassandra.io.sstable.format SSTableReader getBloomFilterSerializedSize

Introduction

In this page you can find the example usage for org.apache.cassandra.io.sstable.format SSTableReader getBloomFilterSerializedSize.

Prototype

public long getBloomFilterSerializedSize() 

Source Link

Usage

From source file:org.elassandra.index.ElasticsearchIndexMetrics.java

License:Apache License

/**
 * Creates metrics for given {@link ColumnFamilyStore}.
 *
 * @param cfs ColumnFamilyStore to measure metrics
 *//*from   w w w.j a v a2s.com*/
public ElasticsearchIndexMetrics(final ColumnFamilyStore cfs) {
    factory = new ColumnFamilyMetricNameFactory(cfs);

    samplers = Maps.newHashMap();
    for (Sampler sampler : Sampler.values()) {
        samplers.put(sampler, new TopKSampler<ByteBuffer>());
    }

    memtableColumnsCount = createColumnFamilyGauge("MemtableColumnsCount", new Gauge<Long>() {
        public Long getValue() {
            return cfs.getTracker().getView().getCurrentMemtable().getOperations();
        }
    });
    memtableOnHeapSize = createColumnFamilyGauge("MemtableOnHeapSize", new Gauge<Long>() {
        public Long getValue() {
            return cfs.getTracker().getView().getCurrentMemtable().getAllocator().onHeap().owns();
        }
    });
    memtableOffHeapSize = createColumnFamilyGauge("MemtableOffHeapSize", new Gauge<Long>() {
        public Long getValue() {
            return cfs.getTracker().getView().getCurrentMemtable().getAllocator().offHeap().owns();
        }
    });
    memtableLiveDataSize = createColumnFamilyGauge("MemtableLiveDataSize", new Gauge<Long>() {
        public Long getValue() {
            return cfs.getTracker().getView().getCurrentMemtable().getLiveDataSize();
        }
    });
    allMemtablesOnHeapSize = createColumnFamilyGauge("AllMemtablesHeapSize", new Gauge<Long>() {
        public Long getValue() {
            long size = 0;
            for (ColumnFamilyStore cfs2 : cfs.concatWithIndexes())
                size += cfs2.getTracker().getView().getCurrentMemtable().getAllocator().onHeap().owns();
            return size;
        }
    });
    allMemtablesOffHeapSize = createColumnFamilyGauge("AllMemtablesOffHeapSize", new Gauge<Long>() {
        public Long getValue() {
            long size = 0;
            for (ColumnFamilyStore cfs2 : cfs.concatWithIndexes())
                size += cfs2.getTracker().getView().getCurrentMemtable().getAllocator().offHeap().owns();
            return size;
        }
    });
    allMemtablesLiveDataSize = createColumnFamilyGauge("AllMemtablesLiveDataSize", new Gauge<Long>() {
        public Long getValue() {
            long size = 0;
            for (ColumnFamilyStore cfs2 : cfs.concatWithIndexes())
                size += cfs2.getTracker().getView().getCurrentMemtable().getLiveDataSize();
            return size;
        }
    });
    memtableSwitchCount = createColumnFamilyCounter("MemtableSwitchCount");
    estimatedRowSizeHistogram = Metrics.register(factory.createMetricName("EstimatedRowSizeHistogram"),
            new Gauge<long[]>() {
                public long[] getValue() {
                    return combineHistograms(cfs.getSSTables(), new GetHistogram() {
                        public EstimatedHistogram getHistogram(SSTableReader reader) {
                            return reader.getEstimatedRowSize();
                        }
                    });
                }
            });
    estimatedRowCount = Metrics.register(factory.createMetricName("EstimatedRowCount"), new Gauge<Long>() {
        public Long getValue() {
            long memtablePartitions = 0;
            for (Memtable memtable : cfs.getTracker().getView().getAllMemtables())
                memtablePartitions += memtable.partitionCount();
            return SSTableReader.getApproximateKeyCount(cfs.getSSTables()) + memtablePartitions;
        }
    });
    estimatedColumnCountHistogram = Metrics.register(factory.createMetricName("EstimatedColumnCountHistogram"),
            new Gauge<long[]>() {
                public long[] getValue() {
                    return combineHistograms(cfs.getSSTables(), new GetHistogram() {
                        public EstimatedHistogram getHistogram(SSTableReader reader) {
                            return reader.getEstimatedColumnCount();
                        }
                    });
                }
            });
    sstablesPerReadHistogram = createColumnFamilyHistogram("SSTablesPerReadHistogram",
            cfs.keyspace.metric.sstablesPerReadHistogram, true);
    compressionRatio = createColumnFamilyGauge("CompressionRatio", new Gauge<Double>() {
        public Double getValue() {
            double sum = 0;
            int total = 0;
            for (SSTableReader sstable : cfs.getSSTables()) {
                if (sstable.getCompressionRatio() != MetadataCollector.NO_COMPRESSION_RATIO) {
                    sum += sstable.getCompressionRatio();
                    total++;
                }
            }
            return total != 0 ? sum / total : 0;
        }
    }, new Gauge<Double>() // global gauge
    {
        public Double getValue() {
            double sum = 0;
            int total = 0;
            for (Keyspace keyspace : Keyspace.all()) {
                for (SSTableReader sstable : keyspace.getAllSSTables()) {
                    if (sstable.getCompressionRatio() != MetadataCollector.NO_COMPRESSION_RATIO) {
                        sum += sstable.getCompressionRatio();
                        total++;
                    }
                }
            }
            return total != 0 ? sum / total : 0;
        }
    });
    readLatency = new LatencyMetrics(factory, "Read", cfs.keyspace.metric.readLatency, globalReadLatency);
    writeLatency = new LatencyMetrics(factory, "Write", cfs.keyspace.metric.writeLatency, globalWriteLatency);
    rangeLatency = new LatencyMetrics(factory, "Range", cfs.keyspace.metric.rangeLatency, globalRangeLatency);
    pendingFlushes = createColumnFamilyCounter("PendingFlushes");
    pendingCompactions = createColumnFamilyGauge("PendingCompactions", new Gauge<Integer>() {
        public Integer getValue() {
            return cfs.getCompactionStrategy().getEstimatedRemainingTasks();
        }
    });
    liveSSTableCount = createColumnFamilyGauge("LiveSSTableCount", new Gauge<Integer>() {
        public Integer getValue() {
            return cfs.getTracker().getSSTables().size();
        }
    });
    liveDiskSpaceUsed = createColumnFamilyCounter("LiveDiskSpaceUsed");
    totalDiskSpaceUsed = createColumnFamilyCounter("TotalDiskSpaceUsed");
    minRowSize = createColumnFamilyGauge("MinRowSize", new Gauge<Long>() {
        public Long getValue() {
            long min = 0;
            for (SSTableReader sstable : cfs.getSSTables()) {
                if (min == 0 || sstable.getEstimatedRowSize().min() < min)
                    min = sstable.getEstimatedRowSize().min();
            }
            return min;
        }
    }, new Gauge<Long>() // global gauge
    {
        public Long getValue() {
            long min = Long.MAX_VALUE;
            for (Metric cfGauge : allColumnFamilyMetrics.get("MinRowSize")) {
                min = Math.min(min, ((Gauge<? extends Number>) cfGauge).getValue().longValue());
            }
            return min;
        }
    });
    maxRowSize = createColumnFamilyGauge("MaxRowSize", new Gauge<Long>() {
        public Long getValue() {
            long max = 0;
            for (SSTableReader sstable : cfs.getSSTables()) {
                if (sstable.getEstimatedRowSize().max() > max)
                    max = sstable.getEstimatedRowSize().max();
            }
            return max;
        }
    }, new Gauge<Long>() // global gauge
    {
        public Long getValue() {
            long max = 0;
            for (Metric cfGauge : allColumnFamilyMetrics.get("MaxRowSize")) {
                max = Math.max(max, ((Gauge<? extends Number>) cfGauge).getValue().longValue());
            }
            return max;
        }
    });
    meanRowSize = createColumnFamilyGauge("MeanRowSize", new Gauge<Long>() {
        public Long getValue() {
            long sum = 0;
            long count = 0;
            for (SSTableReader sstable : cfs.getSSTables()) {
                long n = sstable.getEstimatedRowSize().count();
                sum += sstable.getEstimatedRowSize().mean() * n;
                count += n;
            }
            return count > 0 ? sum / count : 0;
        }
    }, new Gauge<Long>() // global gauge
    {
        public Long getValue() {
            long sum = 0;
            long count = 0;
            for (Keyspace keyspace : Keyspace.all()) {
                for (SSTableReader sstable : keyspace.getAllSSTables()) {
                    long n = sstable.getEstimatedRowSize().count();
                    sum += sstable.getEstimatedRowSize().mean() * n;
                    count += n;
                }
            }
            return count > 0 ? sum / count : 0;
        }
    });
    bloomFilterFalsePositives = createColumnFamilyGauge("BloomFilterFalsePositives", new Gauge<Long>() {
        public Long getValue() {
            long count = 0L;
            for (SSTableReader sstable : cfs.getSSTables())
                count += sstable.getBloomFilterFalsePositiveCount();
            return count;
        }
    });
    recentBloomFilterFalsePositives = createColumnFamilyGauge("RecentBloomFilterFalsePositives",
            new Gauge<Long>() {
                public Long getValue() {
                    long count = 0L;
                    for (SSTableReader sstable : cfs.getSSTables())
                        count += sstable.getRecentBloomFilterFalsePositiveCount();
                    return count;
                }
            });
    bloomFilterFalseRatio = createColumnFamilyGauge("BloomFilterFalseRatio", new Gauge<Double>() {
        public Double getValue() {
            long falseCount = 0L;
            long trueCount = 0L;
            for (SSTableReader sstable : cfs.getSSTables()) {
                falseCount += sstable.getBloomFilterFalsePositiveCount();
                trueCount += sstable.getBloomFilterTruePositiveCount();
            }
            if (falseCount == 0L && trueCount == 0L)
                return 0d;
            return (double) falseCount / (trueCount + falseCount);
        }
    }, new Gauge<Double>() // global gauge
    {
        public Double getValue() {
            long falseCount = 0L;
            long trueCount = 0L;
            for (Keyspace keyspace : Keyspace.all()) {
                for (SSTableReader sstable : keyspace.getAllSSTables()) {
                    falseCount += sstable.getBloomFilterFalsePositiveCount();
                    trueCount += sstable.getBloomFilterTruePositiveCount();
                }
            }
            if (falseCount == 0L && trueCount == 0L)
                return 0d;
            return (double) falseCount / (trueCount + falseCount);
        }
    });
    recentBloomFilterFalseRatio = createColumnFamilyGauge("RecentBloomFilterFalseRatio", new Gauge<Double>() {
        public Double getValue() {
            long falseCount = 0L;
            long trueCount = 0L;
            for (SSTableReader sstable : cfs.getSSTables()) {
                falseCount += sstable.getRecentBloomFilterFalsePositiveCount();
                trueCount += sstable.getRecentBloomFilterTruePositiveCount();
            }
            if (falseCount == 0L && trueCount == 0L)
                return 0d;
            return (double) falseCount / (trueCount + falseCount);
        }
    }, new Gauge<Double>() // global gauge
    {
        public Double getValue() {
            long falseCount = 0L;
            long trueCount = 0L;
            for (Keyspace keyspace : Keyspace.all()) {
                for (SSTableReader sstable : keyspace.getAllSSTables()) {
                    falseCount += sstable.getRecentBloomFilterFalsePositiveCount();
                    trueCount += sstable.getRecentBloomFilterTruePositiveCount();
                }
            }
            if (falseCount == 0L && trueCount == 0L)
                return 0d;
            return (double) falseCount / (trueCount + falseCount);
        }
    });
    bloomFilterDiskSpaceUsed = createColumnFamilyGauge("BloomFilterDiskSpaceUsed", new Gauge<Long>() {
        public Long getValue() {
            long total = 0;
            for (SSTableReader sst : cfs.getSSTables())
                total += sst.getBloomFilterSerializedSize();
            return total;
        }
    });
    bloomFilterOffHeapMemoryUsed = createColumnFamilyGauge("BloomFilterOffHeapMemoryUsed", new Gauge<Long>() {
        public Long getValue() {
            long total = 0;
            for (SSTableReader sst : cfs.getSSTables())
                total += sst.getBloomFilterOffHeapSize();
            return total;
        }
    });
    indexSummaryOffHeapMemoryUsed = createColumnFamilyGauge("IndexSummaryOffHeapMemoryUsed", new Gauge<Long>() {
        public Long getValue() {
            long total = 0;
            for (SSTableReader sst : cfs.getSSTables())
                total += sst.getIndexSummaryOffHeapSize();
            return total;
        }
    });
    compressionMetadataOffHeapMemoryUsed = createColumnFamilyGauge("CompressionMetadataOffHeapMemoryUsed",
            new Gauge<Long>() {
                public Long getValue() {
                    long total = 0;
                    for (SSTableReader sst : cfs.getSSTables())
                        total += sst.getCompressionMetadataOffHeapSize();
                    return total;
                }
            });
    speculativeRetries = createColumnFamilyCounter("SpeculativeRetries");
    keyCacheHitRate = Metrics.register(factory.createMetricName("KeyCacheHitRate"), new RatioGauge() {
        @Override
        public Ratio getRatio() {
            return Ratio.of(getNumerator(), getDenominator());
        }

        protected double getNumerator() {
            long hits = 0L;
            for (SSTableReader sstable : cfs.getSSTables())
                hits += sstable.getKeyCacheHit();
            return hits;
        }

        protected double getDenominator() {
            long requests = 0L;
            for (SSTableReader sstable : cfs.getSSTables())
                requests += sstable.getKeyCacheRequest();
            return Math.max(requests, 1); // to avoid NaN.
        }
    });
    tombstoneScannedHistogram = createColumnFamilyHistogram("TombstoneScannedHistogram",
            cfs.keyspace.metric.tombstoneScannedHistogram, false);
    liveScannedHistogram = createColumnFamilyHistogram("LiveScannedHistogram",
            cfs.keyspace.metric.liveScannedHistogram, false);
    colUpdateTimeDeltaHistogram = createColumnFamilyHistogram("ColUpdateTimeDeltaHistogram",
            cfs.keyspace.metric.colUpdateTimeDeltaHistogram, false);
    coordinatorReadLatency = Metrics.timer(factory.createMetricName("CoordinatorReadLatency"));
    coordinatorScanLatency = Metrics.timer(factory.createMetricName("CoordinatorScanLatency"));
    waitingOnFreeMemtableSpace = Metrics.histogram(factory.createMetricName("WaitingOnFreeMemtableSpace"),
            false);

    trueSnapshotsSize = createColumnFamilyGauge("SnapshotsSize", new Gauge<Long>() {
        public Long getValue() {
            return cfs.trueSnapshotsSize();
        }
    });
    rowCacheHitOutOfRange = createColumnFamilyCounter("RowCacheHitOutOfRange");
    rowCacheHit = createColumnFamilyCounter("RowCacheHit");
    rowCacheMiss = createColumnFamilyCounter("RowCacheMiss");

    casPrepare = new LatencyMetrics(factory, "CasPrepare", cfs.keyspace.metric.casPrepare);
    casPropose = new LatencyMetrics(factory, "CasPropose", cfs.keyspace.metric.casPropose);
    casCommit = new LatencyMetrics(factory, "CasCommit", cfs.keyspace.metric.casCommit);
}