Search in sources :

Example 11 with Metrics

use of org.apache.pulsar.common.stats.Metrics in project incubator-pulsar by apache.

the class ManagedLedgerMetrics method aggregate.

/**
 * Aggregation by namespace (not thread-safe)
 *
 * @param ledgersByDimension
 * @return
 */
private List<Metrics> aggregate(Map<Metrics, List<ManagedLedgerImpl>> ledgersByDimension) {
    metricsCollection.clear();
    for (Entry<Metrics, List<ManagedLedgerImpl>> e : ledgersByDimension.entrySet()) {
        Metrics metrics = e.getKey();
        List<ManagedLedgerImpl> ledgers = e.getValue();
        // prepare aggregation map
        tempAggregatedMetricsMap.clear();
        for (ManagedLedgerImpl ledger : ledgers) {
            ManagedLedgerMXBean lStats = ledger.getStats();
            populateAggregationMapWithSum(tempAggregatedMetricsMap, "brk_ml_AddEntryBytesRate", lStats.getAddEntryBytesRate());
            populateAggregationMapWithSum(tempAggregatedMetricsMap, "brk_ml_AddEntryErrors", (double) lStats.getAddEntryErrors());
            populateAggregationMapWithSum(tempAggregatedMetricsMap, "brk_ml_AddEntryMessagesRate", lStats.getAddEntryMessagesRate());
            populateAggregationMapWithSum(tempAggregatedMetricsMap, "brk_ml_AddEntrySucceed", (double) lStats.getAddEntrySucceed());
            populateAggregationMapWithSum(tempAggregatedMetricsMap, "brk_ml_NumberOfMessagesInBacklog", (double) lStats.getNumberOfMessagesInBacklog());
            populateAggregationMapWithSum(tempAggregatedMetricsMap, "brk_ml_ReadEntriesBytesRate", lStats.getReadEntriesBytesRate());
            populateAggregationMapWithSum(tempAggregatedMetricsMap, "brk_ml_ReadEntriesErrors", (double) lStats.getReadEntriesErrors());
            populateAggregationMapWithSum(tempAggregatedMetricsMap, "brk_ml_ReadEntriesRate", lStats.getReadEntriesRate());
            populateAggregationMapWithSum(tempAggregatedMetricsMap, "brk_ml_ReadEntriesSucceeded", (double) lStats.getReadEntriesSucceeded());
            populateAggregationMapWithSum(tempAggregatedMetricsMap, "brk_ml_StoredMessagesSize", (double) lStats.getStoredMessagesSize());
            // handle bucket entries initialization here
            populateBucketEntries(tempAggregatedMetricsMap, "brk_ml_AddEntryLatencyBuckets", ENTRY_LATENCY_BUCKETS_MS, lStats.getAddEntryLatencyBuckets());
            populateBucketEntries(tempAggregatedMetricsMap, "brk_ml_LedgerSwitchLatencyBuckets", ENTRY_LATENCY_BUCKETS_MS, lStats.getLedgerSwitchLatencyBuckets());
            populateBucketEntries(tempAggregatedMetricsMap, "brk_ml_EntrySizeBuckets", ENTRY_SIZE_BUCKETS_BYTES, lStats.getEntrySizeBuckets());
            populateAggregationMapWithSum(tempAggregatedMetricsMap, "brk_ml_MarkDeleteRate", lStats.getMarkDeleteRate());
        }
        for (Entry<String, Double> ma : tempAggregatedMetricsMap.entrySet()) {
            metrics.put(ma.getKey(), ma.getValue());
        }
        metricsCollection.add(metrics);
    }
    return metricsCollection;
}
Also used : ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) Metrics(org.apache.pulsar.common.stats.Metrics) List(java.util.List) ManagedLedgerMXBean(org.apache.bookkeeper.mledger.ManagedLedgerMXBean)

Example 12 with Metrics

use of org.apache.pulsar.common.stats.Metrics in project incubator-pulsar by apache.

the class SimpleLoadManagerImpl method updateLoadBalancingMetrics.

private void updateLoadBalancingMetrics(String hostname, long finalRank, ResourceUnitRanking ranking) {
    List<Metrics> metrics = Lists.newArrayList();
    Map<String, String> dimensions = new HashMap<>();
    dimensions.put("broker", hostname);
    Metrics m = Metrics.create(dimensions);
    m.put("brk_lb_load_rank", finalRank);
    m.put("brk_lb_quota_pct_cpu", ranking.getAllocatedLoadPercentageCPU());
    m.put("brk_lb_quota_pct_memory", ranking.getAllocatedLoadPercentageMemory());
    m.put("brk_lb_quota_pct_bandwidth_in", ranking.getAllocatedLoadPercentageBandwidthIn());
    m.put("brk_lb_quota_pct_bandwidth_out", ranking.getAllocatedLoadPercentageBandwidthOut());
    metrics.add(m);
    this.loadBalancingMetrics.set(metrics);
}
Also used : Metrics(org.apache.pulsar.common.stats.Metrics) HashMap(java.util.HashMap)

Example 13 with Metrics

use of org.apache.pulsar.common.stats.Metrics in project incubator-pulsar by apache.

the class MBeanStatsGenerator method convert.

private Metrics convert(ObjectInstance instance) {
    ObjectName objName = instance.getObjectName();
    MBeanInfo info = null;
    try {
        info = mbs.getMBeanInfo(objName);
    } catch (Exception e) {
        // [Bug 6158364] skipping MBean if access failed
        return null;
    }
    Metrics metrics = null;
    // create a metrics instance by MBean dimension
    metrics = createMetricsByDimension(objName);
    // get each of attribute,value from the MBean
    for (MBeanAttributeInfo attr : info.getAttributes()) {
        Object value;
        try {
            value = mbs.getAttribute(instance.getObjectName(), attr.getName());
            metrics.put(attr.getName(), value);
        } catch (Exception e) {
        // skip
        }
    }
    return metrics;
}
Also used : Metrics(org.apache.pulsar.common.stats.Metrics) MBeanInfo(javax.management.MBeanInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName)

Example 14 with Metrics

use of org.apache.pulsar.common.stats.Metrics in project incubator-pulsar by apache.

the class ReplicationMetrics method add.

public Metrics add(String namespace, String local, String remote) {
    Map<String, String> dimensionMap = Maps.newHashMap();
    dimensionMap.put("namespace", namespace);
    dimensionMap.put("from_cluster", local);
    dimensionMap.put("to_cluster", remote);
    Metrics dMetrics = Metrics.create(dimensionMap);
    dMetrics.put("brk_repl_out_rate", msgRateOut);
    dMetrics.put("brk_repl_out_tp_rate", msgThroughputOut);
    dMetrics.put("brk_replication_backlog", msgReplBacklog);
    dMetrics.put("brk_repl_is_connected", connected);
    return dMetrics;
}
Also used : Metrics(org.apache.pulsar.common.stats.Metrics)

Example 15 with Metrics

use of org.apache.pulsar.common.stats.Metrics in project incubator-pulsar by apache.

the class JvmMetrics method generate.

@SuppressWarnings("restriction")
@Override
public List<Metrics> generate() {
    Metrics m = createMetrics();
    Runtime r = Runtime.getRuntime();
    m.put("jvm_heap_used", r.totalMemory() - r.freeMemory());
    m.put("jvm_max_memory", r.maxMemory());
    m.put("jvm_total_memory", r.totalMemory());
    m.put("jvm_direct_memory_used", getJvmDirectMemoryUsed());
    m.put("jvm_max_direct_memory", sun.misc.VM.maxDirectMemory());
    m.put("jvm_thread_cnt", getThreadCount());
    m.put("jvm_gc_young_pause", currentYoungGcTime);
    m.put("jvm_gc_young_count", currentYoungGcCount);
    m.put("jvm_gc_old_pause", currentOldGcTime);
    m.put("jvm_gc_old_count", currentOldGcCount);
    long totalAllocated = 0;
    long totalUsed = 0;
    for (PoolArenaMetric arena : PooledByteBufAllocator.DEFAULT.directArenas()) {
        for (PoolChunkListMetric list : arena.chunkLists()) {
            for (PoolChunkMetric chunk : list) {
                int size = chunk.chunkSize();
                int used = size - chunk.freeBytes();
                totalAllocated += size;
                totalUsed += used;
            }
        }
    }
    m.put("brk_default_pool_allocated", totalAllocated);
    m.put("brk_default_pool_used", totalUsed);
    return Lists.newArrayList(m);
}
Also used : PoolArenaMetric(io.netty.buffer.PoolArenaMetric) Metrics(org.apache.pulsar.common.stats.Metrics) PoolChunkListMetric(io.netty.buffer.PoolChunkListMetric) PoolChunkMetric(io.netty.buffer.PoolChunkMetric)

Aggregations

Metrics (org.apache.pulsar.common.stats.Metrics)18 Test (org.testng.annotations.Test)4 PoolArenaMetric (io.netty.buffer.PoolArenaMetric)3 PoolChunkListMetric (io.netty.buffer.PoolChunkListMetric)3 PoolChunkMetric (io.netty.buffer.PoolChunkMetric)3 ManagedLedgerImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl)3 HashMap (java.util.HashMap)2 BrokerService (org.apache.pulsar.broker.service.BrokerService)2 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)1 Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 ByteBuf (io.netty.buffer.ByteBuf)1 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1