Search in sources :

Example 1 with MasterWebUIMetrics

use of alluxio.wire.MasterWebUIMetrics in project alluxio by Alluxio.

the class AlluxioMasterRestServiceHandler method getWebUIMetrics.

/**
 * Gets Web UI metrics page data.
 *
 * @return the response object
 */
@GET
@Path(WEBUI_METRICS)
public Response getWebUIMetrics() {
    return RestUtils.call(() -> {
        MasterWebUIMetrics response = new MasterWebUIMetrics();
        MetricRegistry mr = MetricsSystem.METRIC_REGISTRY;
        SortedMap<String, Gauge> gauges = mr.getGauges();
        SortedMap<String, Counter> counters = mr.getCounters();
        Long masterCapacityTotal = (Long) gauges.get(MetricKey.CLUSTER_CAPACITY_TOTAL.getName()).getValue();
        Long masterCapacityUsed = (Long) gauges.get(MetricKey.CLUSTER_CAPACITY_USED.getName()).getValue();
        int masterCapacityUsedPercentage = (masterCapacityTotal > 0) ? (int) (100L * masterCapacityUsed / masterCapacityTotal) : 0;
        response.setMasterCapacityUsedPercentage(masterCapacityUsedPercentage).setMasterCapacityFreePercentage(100 - masterCapacityUsedPercentage);
        Long masterUnderfsCapacityTotal = (Long) gauges.get(MetricKey.CLUSTER_ROOT_UFS_CAPACITY_TOTAL.getName()).getValue();
        Long masterUnderfsCapacityUsed = (Long) gauges.get(MetricKey.CLUSTER_ROOT_UFS_CAPACITY_USED.getName()).getValue();
        int masterUnderfsCapacityUsedPercentage = (masterUnderfsCapacityTotal > 0) ? (int) (100L * masterUnderfsCapacityUsed / masterUnderfsCapacityTotal) : 0;
        response.setMasterUnderfsCapacityUsedPercentage(masterUnderfsCapacityUsedPercentage).setMasterUnderfsCapacityFreePercentage(100 - masterUnderfsCapacityUsedPercentage);
        // cluster read size
        Long bytesReadLocal = counters.get(MetricKey.CLUSTER_BYTES_READ_LOCAL.getName()).getCount();
        Long bytesReadRemote = counters.get(MetricKey.CLUSTER_BYTES_READ_REMOTE.getName()).getCount();
        Long bytesReadDomainSocket = counters.get(MetricKey.CLUSTER_BYTES_READ_DOMAIN.getName()).getCount();
        Long bytesReadUfs = counters.get(MetricKey.CLUSTER_BYTES_READ_UFS_ALL.getName()).getCount();
        response.setTotalBytesReadLocal(FormatUtils.getSizeFromBytes(bytesReadLocal)).setTotalBytesReadDomainSocket(FormatUtils.getSizeFromBytes(bytesReadDomainSocket)).setTotalBytesReadRemote(FormatUtils.getSizeFromBytes(bytesReadRemote)).setTotalBytesReadUfs(FormatUtils.getSizeFromBytes(bytesReadUfs));
        // cluster cache hit and miss
        long bytesReadTotal = bytesReadLocal + bytesReadRemote + bytesReadDomainSocket;
        double cacheHitLocalPercentage = (bytesReadTotal > 0) ? (100D * (bytesReadLocal + bytesReadDomainSocket) / bytesReadTotal) : 0;
        double cacheHitRemotePercentage = (bytesReadTotal > 0) ? (100D * (bytesReadRemote - bytesReadUfs) / bytesReadTotal) : 0;
        double cacheMissPercentage = (bytesReadTotal > 0) ? (100D * bytesReadUfs / bytesReadTotal) : 0;
        response.setCacheHitLocal(String.format("%.2f", cacheHitLocalPercentage)).setCacheHitRemote(String.format("%.2f", cacheHitRemotePercentage)).setCacheMiss(String.format("%.2f", cacheMissPercentage));
        // cluster write size
        Long bytesWrittenLocal = counters.get(MetricKey.CLUSTER_BYTES_WRITTEN_LOCAL.getName()).getCount();
        Long bytesWrittenAlluxio = counters.get(MetricKey.CLUSTER_BYTES_WRITTEN_REMOTE.getName()).getCount();
        Long bytesWrittenDomainSocket = counters.get(MetricKey.CLUSTER_BYTES_WRITTEN_DOMAIN.getName()).getCount();
        Long bytesWrittenUfs = counters.get(MetricKey.CLUSTER_BYTES_WRITTEN_UFS_ALL.getName()).getCount();
        response.setTotalBytesWrittenLocal(FormatUtils.getSizeFromBytes(bytesWrittenLocal)).setTotalBytesWrittenRemote(FormatUtils.getSizeFromBytes(bytesWrittenAlluxio)).setTotalBytesWrittenDomainSocket(FormatUtils.getSizeFromBytes(bytesWrittenDomainSocket)).setTotalBytesWrittenUfs(FormatUtils.getSizeFromBytes(bytesWrittenUfs));
        // cluster read throughput
        Long bytesReadLocalThroughput = (Long) gauges.get(MetricKey.CLUSTER_BYTES_READ_LOCAL_THROUGHPUT.getName()).getValue();
        Long bytesReadDomainSocketThroughput = (Long) gauges.get(MetricKey.CLUSTER_BYTES_READ_DOMAIN_THROUGHPUT.getName()).getValue();
        Long bytesReadRemoteThroughput = (Long) gauges.get(MetricKey.CLUSTER_BYTES_READ_REMOTE_THROUGHPUT.getName()).getValue();
        Long bytesReadUfsThroughput = (Long) gauges.get(MetricKey.CLUSTER_BYTES_READ_UFS_THROUGHPUT.getName()).getValue();
        response.setTotalBytesReadLocalThroughput(FormatUtils.getSizeFromBytes(bytesReadLocalThroughput)).setTotalBytesReadDomainSocketThroughput(FormatUtils.getSizeFromBytes(bytesReadDomainSocketThroughput)).setTotalBytesReadRemoteThroughput(FormatUtils.getSizeFromBytes(bytesReadRemoteThroughput)).setTotalBytesReadUfsThroughput(FormatUtils.getSizeFromBytes(bytesReadUfsThroughput));
        // cluster write throughput
        Long bytesWrittenLocalThroughput = (Long) gauges.get(MetricKey.CLUSTER_BYTES_WRITTEN_LOCAL_THROUGHPUT.getName()).getValue();
        Long bytesWrittenAlluxioThroughput = (Long) gauges.get(MetricKey.CLUSTER_BYTES_WRITTEN_REMOTE_THROUGHPUT.getName()).getValue();
        Long bytesWrittenDomainSocketThroughput = (Long) gauges.get(MetricKey.CLUSTER_BYTES_WRITTEN_DOMAIN_THROUGHPUT.getName()).getValue();
        Long bytesWrittenUfsThroughput = (Long) gauges.get(MetricKey.CLUSTER_BYTES_WRITTEN_UFS_THROUGHPUT.getName()).getValue();
        response.setTotalBytesWrittenLocalThroughput(FormatUtils.getSizeFromBytes(bytesWrittenLocalThroughput)).setTotalBytesWrittenRemoteThroughput(FormatUtils.getSizeFromBytes(bytesWrittenAlluxioThroughput)).setTotalBytesWrittenDomainSocketThroughput(FormatUtils.getSizeFromBytes(bytesWrittenDomainSocketThroughput)).setTotalBytesWrittenUfsThroughput(FormatUtils.getSizeFromBytes(bytesWrittenUfsThroughput));
        // 
        // For the per UFS metrics below, if a UFS has been unmounted, its metrics will still exist
        // in the metrics system, but we don't show them in the UI. After remounting the UFS, the
        // new metrics will be accumulated on its old values and shown in the UI.
        // 
        // cluster per UFS read
        Map<String, String> ufsReadSizeMap = new TreeMap<>();
        Map<String, String> ufsWriteSizeMap = new TreeMap<>();
        Map<String, Counter> rpcInvocations = new TreeMap<>();
        Map<String, Metric> operations = new TreeMap<>();
        // UFS : (OPS : Count)
        Map<String, Map<String, Long>> ufsOpsSavedMap = new TreeMap<>();
        for (Map.Entry<String, Counter> entry : counters.entrySet()) {
            String metricName = entry.getKey();
            long value = entry.getValue().getCount();
            if (metricName.contains(MetricKey.CLUSTER_BYTES_READ_UFS.getName())) {
                String ufs = alluxio.metrics.Metric.getTagUfsValueFromFullName(metricName);
                if (ufs != null && isMounted(ufs)) {
                    ufsReadSizeMap.put(MetricsSystem.unescape(ufs), FormatUtils.getSizeFromBytes(value));
                }
            } else if (metricName.contains(MetricKey.CLUSTER_BYTES_WRITTEN_UFS.getName())) {
                String ufs = alluxio.metrics.Metric.getTagUfsValueFromFullName(metricName);
                if (ufs != null && isMounted(ufs)) {
                    ufsWriteSizeMap.put(MetricsSystem.unescape(ufs), FormatUtils.getSizeFromBytes(value));
                }
            } else if (metricName.endsWith("Ops")) {
                rpcInvocations.put(MetricsSystem.stripInstanceAndHost(metricName), entry.getValue());
            } else if (metricName.contains(UFS_OP_SAVED_PREFIX)) {
                String ufs = alluxio.metrics.Metric.getTagUfsValueFromFullName(metricName);
                if (ufs != null && isMounted(ufs)) {
                    // Unescape the URI for display
                    String ufsUnescaped = MetricsSystem.unescape(ufs);
                    Map<String, Long> perUfsMap = ufsOpsSavedMap.getOrDefault(ufsUnescaped, new TreeMap<>());
                    String alluxioOperation = alluxio.metrics.Metric.getBaseName(metricName).substring(UFS_OP_SAVED_PREFIX.length());
                    String equivalentOp = DefaultFileSystemMaster.Metrics.UFS_OPS_DESC.get(DefaultFileSystemMaster.Metrics.UFSOps.valueOf(alluxioOperation));
                    if (equivalentOp != null) {
                        alluxioOperation = String.format("%s (Roughly equivalent to %s operation)", alluxioOperation, equivalentOp);
                    }
                    perUfsMap.put(alluxioOperation, entry.getValue().getCount());
                    ufsOpsSavedMap.put(ufsUnescaped, perUfsMap);
                }
            } else {
                operations.put(MetricsSystem.stripInstanceAndHost(metricName), entry.getValue());
            }
        }
        String filesPinnedProperty = MetricKey.MASTER_FILES_PINNED.getName();
        operations.put(MetricsSystem.stripInstanceAndHost(filesPinnedProperty), gauges.get(filesPinnedProperty));
        response.setOperationMetrics(operations).setRpcInvocationMetrics(rpcInvocations);
        response.setUfsReadSize(ufsReadSizeMap);
        response.setUfsWriteSize(ufsWriteSizeMap);
        response.setUfsOpsSaved(ufsOpsSavedMap);
        // per UFS ops
        Map<String, Map<String, Long>> ufsOpsMap = new TreeMap<>();
        for (Map.Entry<String, Gauge> entry : gauges.entrySet()) {
            String metricName = entry.getKey();
            if (metricName.contains(UFS_OP_PREFIX)) {
                String ufs = alluxio.metrics.Metric.getTagUfsValueFromFullName(metricName);
                if (ufs != null && isMounted(ufs)) {
                    // Unescape the URI for display
                    String ufsUnescaped = MetricsSystem.unescape(ufs);
                    Map<String, Long> perUfsMap = ufsOpsMap.getOrDefault(ufsUnescaped, new TreeMap<>());
                    perUfsMap.put(alluxio.metrics.Metric.getBaseName(metricName).substring(UFS_OP_PREFIX.length()), (Long) entry.getValue().getValue());
                    ufsOpsMap.put(ufsUnescaped, perUfsMap);
                }
            }
        }
        response.setUfsOps(ufsOpsMap);
        response.setTimeSeriesMetrics(mFileSystemMaster.getTimeSeries());
        mMetaMaster.getJournalSpaceMonitor().ifPresent(monitor -> {
            try {
                response.setJournalDiskMetrics(monitor.getDiskInfo());
            } catch (IOException e) {
                LogUtils.warnWithException(LOG, "Failed to populate journal disk information for WebUI metrics.", e);
            }
        });
        if (response.getJournalDiskMetrics() == null) {
            response.setJournalDiskMetrics(Collections.emptyList());
        }
        Gauge lastCheckpointTimeGauge = gauges.get(MetricKey.MASTER_JOURNAL_LAST_CHECKPOINT_TIME.getName());
        Gauge entriesSinceCheckpointGauge = gauges.get(MetricKey.MASTER_JOURNAL_ENTRIES_SINCE_CHECKPOINT.getName());
        if (entriesSinceCheckpointGauge != null) {
            response.setJournalEntriesSinceCheckpoint((long) entriesSinceCheckpointGauge.getValue());
        }
        if (lastCheckpointTimeGauge != null) {
            long lastCheckpointTime = (long) lastCheckpointTimeGauge.getValue();
            String time;
            if (lastCheckpointTime > 0) {
                time = ZonedDateTime.ofInstant(Instant.ofEpochMilli(lastCheckpointTime), ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT);
            } else {
                time = "N/A";
            }
            response.setJournalLastCheckpointTime(time);
        }
        return response;
    }, ServerConfiguration.global());
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) IOException(java.io.IOException) TreeMap(java.util.TreeMap) Gauge(com.codahale.metrics.Gauge) Counter(com.codahale.metrics.Counter) Metric(com.codahale.metrics.Metric) MasterWebUIMetrics(alluxio.wire.MasterWebUIMetrics) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

MasterWebUIMetrics (alluxio.wire.MasterWebUIMetrics)1 Counter (com.codahale.metrics.Counter)1 Gauge (com.codahale.metrics.Gauge)1 Metric (com.codahale.metrics.Metric)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1