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;
}
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);
}
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;
}
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;
}
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);
}
Aggregations