use of com.baidu.hugegraph.metrics.ServerReporter in project incubator-hugegraph by apache.
the class MetricsAPI method all.
@GET
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin", "$owner= $action=metrics_read" })
public String all() {
ServerReporter reporter = ServerReporter.instance();
Map<String, Map<String, ? extends Metric>> result = new LinkedHashMap<>();
result.put("gauges", reporter.gauges());
result.put("counters", reporter.counters());
result.put("histograms", reporter.histograms());
result.put("meters", reporter.meters());
result.put("timers", reporter.timers());
return JsonUtil.toJson(result);
}
use of com.baidu.hugegraph.metrics.ServerReporter in project incubator-hugegraph by apache.
the class GraphManager method addMetrics.
private void addMetrics(HugeConfig config) {
final MetricManager metric = MetricManager.INSTANCE;
// Force to add server reporter
ServerReporter reporter = ServerReporter.instance(metric.getRegistry());
reporter.start(60L, TimeUnit.SECONDS);
// Add metrics for MAX_WRITE_THREADS
int maxWriteThreads = config.get(ServerOptions.MAX_WRITE_THREADS);
MetricsUtil.registerGauge(RestServer.class, "max-write-threads", () -> {
return maxWriteThreads;
});
// Add metrics for caches
@SuppressWarnings({ "rawtypes", "unchecked" }) Map<String, Cache<?, ?>> caches = (Map) CacheManager.instance().caches();
registerCacheMetrics(caches);
final AtomicInteger lastCachesSize = new AtomicInteger(caches.size());
MetricsUtil.registerGauge(Cache.class, "instances", () -> {
int count = caches.size();
if (count != lastCachesSize.get()) {
// Update if caches changed (effect in the next report period)
registerCacheMetrics(caches);
lastCachesSize.set(count);
}
return count;
});
// Add metrics for task
MetricsUtil.registerGauge(TaskManager.class, "workers", () -> {
return TaskManager.instance().workerPoolSize();
});
MetricsUtil.registerGauge(TaskManager.class, "pending-tasks", () -> {
return TaskManager.instance().pendingTasks();
});
}
Aggregations