Search in sources :

Example 1 with ServerReporter

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);
}
Also used : Metric(com.codahale.metrics.Metric) ServerReporter(com.baidu.hugegraph.metrics.ServerReporter) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) RolesAllowed(jakarta.annotation.security.RolesAllowed) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 2 with ServerReporter

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();
    });
}
Also used : MetricManager(org.apache.tinkerpop.gremlin.server.util.MetricManager) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerReporter(com.baidu.hugegraph.metrics.ServerReporter) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Cache(com.baidu.hugegraph.backend.cache.Cache)

Aggregations

ServerReporter (com.baidu.hugegraph.metrics.ServerReporter)2 Map (java.util.Map)2 Cache (com.baidu.hugegraph.backend.cache.Cache)1 Metric (com.codahale.metrics.Metric)1 Timed (com.codahale.metrics.annotation.Timed)1 RolesAllowed (jakarta.annotation.security.RolesAllowed)1 GET (jakarta.ws.rs.GET)1 Produces (jakarta.ws.rs.Produces)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MetricManager (org.apache.tinkerpop.gremlin.server.util.MetricManager)1