Search in sources :

Example 1 with WorkerWebUIMetrics

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

the class AlluxioWorkerRestServiceHandler method getWebUIMetrics.

/**
 * Gets web ui metrics page data.
 *
 * @return the response object
 */
@GET
@Path(WEBUI_METRICS)
public Response getWebUIMetrics() {
    return RestUtils.call(() -> {
        WorkerWebUIMetrics response = new WorkerWebUIMetrics();
        MetricRegistry mr = MetricsSystem.METRIC_REGISTRY;
        SortedMap<String, Gauge> gauges = mr.getGauges();
        Long workerCapacityTotal = (Long) gauges.get(MetricsSystem.getMetricName(MetricKey.WORKER_CAPACITY_TOTAL.getName())).getValue();
        Long workerCapacityUsed = (Long) gauges.get(MetricsSystem.getMetricName(MetricKey.WORKER_CAPACITY_USED.getName())).getValue();
        int workerCapacityUsedPercentage = (workerCapacityTotal > 0) ? (int) (100L * workerCapacityUsed / workerCapacityTotal) : 0;
        response.setWorkerCapacityUsedPercentage(workerCapacityUsedPercentage);
        response.setWorkerCapacityFreePercentage(100L - workerCapacityUsedPercentage);
        Map<String, Metric> operations = new TreeMap<>();
        // Remove the instance name from the metrics.
        for (Map.Entry<String, Counter> entry : mr.getCounters().entrySet()) {
            operations.put(MetricsSystem.stripInstanceAndHost(entry.getKey()), entry.getValue());
        }
        response.setOperationMetrics(operations);
        return response;
    }, ServerConfiguration.global());
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) WorkerWebUIMetrics(alluxio.wire.WorkerWebUIMetrics) TreeMap(java.util.TreeMap) Gauge(com.codahale.metrics.Gauge) Counter(com.codahale.metrics.Counter) Metric(com.codahale.metrics.Metric) Map(java.util.Map) SortedMap(java.util.SortedMap) TreeMap(java.util.TreeMap) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

WorkerWebUIMetrics (alluxio.wire.WorkerWebUIMetrics)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 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