private void getMemoryUsage(MetricsRecordBuilder rb) { MemoryUsage memNonHeap = memoryMXBean.getNonHeapMemoryUsage(); MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage(); Runtime runtime = Runtime.getRuntime(); rb.addGauge(MemNonHeapUsedM, memNonHeap.getUsed() / M) .addGauge(MemNonHeapCommittedM, memNonHeap.getCommitted() / M) .addGauge(MemNonHeapMaxM, memNonHeap.getMax() / M) .addGauge(MemHeapUsedM, memHeap.getUsed() / M) .addGauge(MemHeapCommittedM, memHeap.getCommitted() / M) .addGauge(MemHeapMaxM, memHeap.getMax() / M) .addGauge(MemMaxM, runtime.maxMemory() / M); }
private void getMemoryUsage(MetricsRecordBuilder rb) { MemoryUsage memNonHeap = memoryMXBean.getNonHeapMemoryUsage(); MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage(); Runtime runtime = Runtime.getRuntime(); rb.addGauge(MemNonHeapUsedM, memNonHeap.getUsed() / M) .addGauge(MemNonHeapCommittedM, memNonHeap.getCommitted() / M) .addGauge(MemNonHeapMaxM, calculateMaxMemoryUsage(memNonHeap)) .addGauge(MemHeapUsedM, memHeap.getUsed() / M) .addGauge(MemHeapCommittedM, memHeap.getCommitted() / M) .addGauge(MemHeapMaxM, calculateMaxMemoryUsage(memHeap)) .addGauge(MemMaxM, runtime.maxMemory() / M); }
private void addGauge(String name, Gauge<?> gauge, MetricsRecordBuilder builder) { final MetricsInfo info = Interns.info(name, EMPTY_STRING); final Object o = gauge.getValue(); // Figure out which gauge types metrics2 supports and call the right method if (o instanceof Integer) { builder.addGauge(info, (int) o); } else if (o instanceof Long) { builder.addGauge(info, (long) o); } else if (o instanceof Float) { builder.addGauge(info, (float) o); } else if (o instanceof Double) { builder.addGauge(info, (double) o); } else { LOG.warn("Ignoring Gauge (" + name + ") with unhandled type: " + o.getClass()); } }
@Override public synchronized void getMetrics(MetricsCollector builder, boolean all) { MetricsRecordBuilder rb = builder.addRecord(MS_NAME) .addGauge(MsInfo.NumActiveSources, sources.size()) .addGauge(MsInfo.NumAllSources, allSources.size()) .addGauge(MsInfo.NumActiveSinks, sinks.size()) .addGauge(MsInfo.NumAllSinks, allSinks.size()); for (MetricsSinkAdapter sa : sinks.values()) { sa.snapshot(rb, all); } registry.snapshot(rb, all); }
@Override public void snapshot(MetricsRecordBuilder rb, boolean all) { try { Object ret = method.invoke(obj, (Object[]) null); if (isInt(t)) rb.addGauge(info, ((Integer) ret).intValue()); else if (isLong(t)) rb.addGauge(info, ((Long) ret).longValue()); else if (isFloat(t)) rb.addGauge(info, ((Float) ret).floatValue()); else rb.addGauge(info, ((Double) ret).doubleValue()); } catch (Exception ex) { LOG.error("Error invoking method "+ method.getName(), ex); } } };
@Override public void getMetrics(MetricsCollector metricsCollector, boolean all) { MetricsRecordBuilder metricsRecordBuilder = metricsCollector.addRecord(metricsName); if (stochasticCosts != null) { synchronized (stochasticCosts) { for (Map.Entry<String, Map<String, Double>> tableEntry : stochasticCosts.entrySet()) { for (Map.Entry<String, Double> costEntry : tableEntry.getValue().entrySet()) { String attrName = tableEntry.getKey() + TABLE_FUNCTION_SEP + costEntry.getKey(); Double cost = costEntry.getValue(); String functionDesc = costFunctionDescs.get(costEntry.getKey()); if (functionDesc == null) { functionDesc = costEntry.getKey(); } metricsRecordBuilder.addGauge(Interns.info(attrName, functionDesc), cost); } } } } metricsRegistry.snapshot(metricsRecordBuilder, all); } }
@Override public synchronized void snapshot(MetricsRecordBuilder builder, boolean all) { if (all || changed()) { builder.addGauge(numInfo, previousCount); for (int i = 0; i < quantiles.length; i++) { long newValue = 0; // If snapshot is null, we failed to update since the window was empty if (previousSnapshot != null) { newValue = previousSnapshot.get(quantiles[i]); } builder.addGauge(quantileInfos[i], newValue); } if (changed()) { clearChanged(); } } }
/** * Add Dropwizard-Metrics rate information to a Hadoop-Metrics2 record builder, converting the * rates to the appropriate unit. * * @param builder A Hadoop-Metrics2 record builder. * @param name A base name for this record. */ private void addMeter(String name, Meter meter, MetricsRecordBuilder builder) { builder.addGauge(Interns.info(name + "_count", EMPTY_STRING), meter.getCount()); builder.addGauge(Interns.info(name + "_mean_rate", EMPTY_STRING), meter.getMeanRate()); builder.addGauge(Interns.info(name + "_1min_rate", EMPTY_STRING), meter.getOneMinuteRate()); builder.addGauge(Interns.info(name + "_5min_rate", EMPTY_STRING), meter.getFiveMinuteRate()); builder.addGauge(Interns.info(name + "_15min_rate", EMPTY_STRING), meter.getFifteenMinuteRate()); }
/** * Add Dropwizard-Metrics value-distribution data to a Hadoop-Metrics2 record building, converting * the durations to the appropriate unit. * * @param builder A Hadoop-Metrics2 record builder. * @param name A base name for this record. * @param desc A description for this record. * @param snapshot The distribution of measured values. * @param count The number of values which were measured. */ private void addSnapshot(MetricsRecordBuilder builder, String name, String desc, Snapshot snapshot, long count) { builder.addGauge(Interns.info(name + "_count", desc), count); addSnapshot(builder, name, desc, snapshot); }
private void getIoStats(MetricsRecordBuilder rb) { rb.addGauge(MaxDecodingTime, maxDecodingTime.value()); rateOfDecoding.snapshot(rb, true); for (MutableQuantiles q : decodingTimes) { q.snapshot(rb, true); } }
private void addAvgResponseTimePerPriority(MetricsRecordBuilder rb) { for (int i = 0; i < responseTimeAvgInLastWindow.length(); i++) { rb.addGauge(Interns.info("Priority." + i + ".AvgResponseTime", "Average" + " response time of priority " + i), responseTimeAvgInLastWindow.get(i)); } }
private void addCallVolumePerPriority(MetricsRecordBuilder rb) { for (int i = 0; i < responseTimeCountInLastWindow.length(); i++) { rb.addGauge(Interns.info("Priority." + i + ".CompletedCallVolume", "Completed Call volume " + "of priority "+ i), responseTimeCountInLastWindow.get(i)); } }
/** * Yes this is a get function that doesn't return anything. Thanks Hadoop for breaking all * expectations of java programmers. Instead of returning anything Hadoop metrics expects * getMetrics to push the metrics into the collector. * * @param collector the collector * @param all get all the metrics regardless of when they last changed. */ @Override public void getMetrics(MetricsCollector collector, boolean all) { MetricsRecordBuilder mrb = collector.addRecord(metricsName); if (tableSources != null) { for (MetricsTableSource tableMetricSource : tableSources.values()) { if (tableMetricSource instanceof MetricsTableSourceImpl) { ((MetricsTableSourceImpl) tableMetricSource).snapshot(mrb, all); } } mrb.addGauge(Interns.info(NUM_TABLES, NUMBER_OF_TABLES_DESC), tableSources.size()); metricsRegistry.snapshot(mrb, all); } } }
@Override public void getMetrics(MetricsCollector metricsCollector, boolean all) { MetricsRecordBuilder metricsRecordBuilder = metricsCollector.addRecord(metricsName); // masterWrapper can be null because this function is called inside of init. if (masterWrapper != null) { metricsRecordBuilder .addGauge(Interns.info(NUM_MASTER_WALS_NAME, NUM_MASTER_WALS_DESC), masterWrapper.getNumWALFiles()); } metricsRegistry.snapshot(metricsRecordBuilder, all); }
/** * Yes this is a get function that doesn't return anything. Thanks Hadoop for breaking all * expectations of java programmers. Instead of returning anything Hadoop metrics expects * getMetrics to push the metrics into the collector. * * @param collector the collector * @param all get all the metrics regardless of when they last changed. */ @Override public void getMetrics(MetricsCollector collector, boolean all) { MetricsRecordBuilder mrb = collector.addRecord(metricsName); if (regionSources != null) { for (MetricsRegionSource regionMetricSource : regionSources) { if (regionMetricSource instanceof MetricsRegionSourceImpl) { ((MetricsRegionSourceImpl) regionMetricSource).snapshot(mrb, all); } } mrb.addGauge(Interns.info(NUM_REGIONS, NUMBER_OF_REGIONS_DESC), regionSources.size()); metricsRegistry.snapshot(mrb, all); } } }
private void getTaskSchedulerStats(MetricsRecordBuilder rb) { rb.addGauge(SchedulerClusterNodeCount, clusterNodeCount.value()) .addGauge(SchedulerExecutorsPerInstance, numExecutors.value()) .addGauge(SchedulerMemoryPerInstance, memoryPerInstance.value()) .addGauge(SchedulerCpuCoresPerInstance, cpuCoresPerInstance.value()) .addGauge(SchedulerDisabledNodeCount, disabledNodeCount.value()) .addCounter(SchedulerPendingTaskCount, pendingTasksCount.value()) .addCounter(SchedulerSchedulableTaskCount, schedulableTasksCount.value()) .addCounter(SchedulerRunningTaskCount, runningTasksCount.value()) .addCounter(SchedulerSuccessfulTaskCount, successfulTasksCount.value()) .addCounter(SchedulerPendingPreemptionTaskCount, pendingPreemptionTasksCount.value()) .addCounter(SchedulerPreemptedTaskCount, preemptedTasksCount.value()) .addCounter(SchedulerCompletedDagCount, completedDagcount.value()); }
@Override public void snapshot(MetricsRecordBuilder builder, boolean all) { if (all || changed()) { builder.addGauge(info(), value()); clearChanged(); } } }
@Override public void snapshot(MetricsRecordBuilder builder, boolean all) { if (all || changed()) { builder.addGauge(info(), value()); clearChanged(); } }
@Override public void snapshot(MetricsRecordBuilder builder, boolean all) { if (all || changed()) { builder.addGauge(info(), value()); clearChanged(); } }
private void getCacheStats(MetricsRecordBuilder rb) { float cacheHitRatio = cacheRequestedBytes.value() == 0 ? 0.0f : (float) cacheHitBytes.value() / (float) cacheRequestedBytes.value(); long cacheCapacityRemaining = cacheCapacityTotal.value() - cacheCapacityUsed.value(); float cacheRemainingPercent = cacheCapacityTotal.value() == 0 ? 0.0f : (float) cacheCapacityRemaining / (float) cacheCapacityTotal.value(); rb.addCounter(CacheCapacityRemaining, cacheCapacityRemaining) .addGauge(CacheCapacityRemainingPercentage, cacheRemainingPercent) .addCounter(CacheCapacityTotal, cacheCapacityTotal.value()) .addCounter(CacheCapacityUsed, cacheCapacityUsed.value()) .addCounter(CacheReadRequests, cacheReadRequests.value()) .addCounter(CacheRequestedBytes, cacheRequestedBytes.value()) .addCounter(CacheHitBytes, cacheHitBytes.value()) .addCounter(CacheAllocatedArena, cacheAllocatedArena.value()) .addCounter(CacheNumLockedBuffers, cacheNumLockedBuffers.value()) .addGauge(CacheHitRatio, cacheHitRatio); }