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