Search in sources :

Example 1 with GlobalRegistry

use of org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry in project java-chassis by ServiceComb.

the class OsMetersInitializer method init.

@Override
public void init(GlobalRegistry globalRegistry, EventBus eventBus, MetricsBootstrapConfig config) {
    if (!isOsLinux) {
        LOGGER.info("only support linux os to collect cpu and net info");
        return;
    }
    Registry registry = globalRegistry.getDefaultRegistry();
    osMeter = new OsMeter(registry);
    SpectatorUtils.registerMeter(registry, osMeter);
}
Also used : OsMeter(org.apache.servicecomb.metrics.core.meter.os.OsMeter) GlobalRegistry(org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry) Registry(com.netflix.spectator.api.Registry)

Example 2 with GlobalRegistry

use of org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry in project java-chassis by ServiceComb.

the class TestMetricsRestPublisher method measure_normal.

@Test
public void measure_normal() {
    Clock clock = new ManualClock();
    GlobalRegistry globalRegistry = new GlobalRegistry();
    Registry registry = new DefaultRegistry(clock);
    registry.timer(registry.createId("name", "t1", "v1", "t2", "v2"));
    globalRegistry.add(registry);
    EventBus eventBus = new EventBus();
    publisher.init(globalRegistry, eventBus, new MetricsBootstrapConfig());
    Map<String, Double> result = publisher.measure();
    Assert.assertEquals(2, result.size());
    Assert.assertEquals(0, result.get("name(statistic=count,t1=v1,t2=v2)"), 0);
    Assert.assertEquals(0, result.get("name(statistic=totalTime,t1=v1,t2=v2)"), 0);
}
Also used : ManualClock(com.netflix.spectator.api.ManualClock) GlobalRegistry(org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry) MetricsBootstrapConfig(org.apache.servicecomb.foundation.metrics.MetricsBootstrapConfig) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) GlobalRegistry(org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry) Registry(com.netflix.spectator.api.Registry) EventBus(com.google.common.eventbus.EventBus) ManualClock(com.netflix.spectator.api.ManualClock) Clock(com.netflix.spectator.api.Clock) Test(org.junit.Test)

Example 3 with GlobalRegistry

use of org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry in project java-chassis by ServiceComb.

the class MetricsRestPublisher method measure.

@ApiResponses({ @ApiResponse(code = 400, response = String.class, message = "illegal request content") })
@GET
@Path("/")
public Map<String, Double> measure() {
    Map<String, Double> measurements = new LinkedHashMap<>();
    if (globalRegistry == null) {
        return measurements;
    }
    StringBuilder sb = new StringBuilder();
    for (Registry registry : globalRegistry.getRegistries()) {
        for (Meter meter : registry) {
            meter.measure().forEach(measurement -> {
                String key = idToString(measurement.id(), sb);
                measurements.put(key, measurement.value());
            });
        }
    }
    return measurements;
}
Also used : Meter(com.netflix.spectator.api.Meter) GlobalRegistry(org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry) Registry(com.netflix.spectator.api.Registry) LinkedHashMap(java.util.LinkedHashMap) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with GlobalRegistry

use of org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry in project java-chassis by ServiceComb.

the class MetricsBootListener method onAfterRegistry.

@Override
public void onAfterRegistry(BootEvent event) {
    slowInvocationLogger = new SlowInvocationLogger(event.getScbEngine());
    metricsBootstrap.start(new GlobalRegistry(), EventManager.getEventBus());
}
Also used : GlobalRegistry(org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry) SlowInvocationLogger(org.apache.servicecomb.metrics.core.publish.SlowInvocationLogger)

Example 5 with GlobalRegistry

use of org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry in project java-chassis by ServiceComb.

the class VertxMetersInitializer method init.

@Override
public void init(GlobalRegistry globalRegistry, EventBus eventBus, MetricsBootstrapConfig config) {
    Registry registry = globalRegistry.getDefaultRegistry();
    Id endpointsId = registry.createId(VERTX_ENDPOINTS);
    VertxEndpointsMeter clientMeter = new HttpClientEndpointsMeter(endpointsId.withTag(ENDPOINTS_TYPE, ENDPOINTS_CLINET), SharedVertxFactory.getMetricsFactory().getVertxMetrics().getClientEndpointMetricManager().getClientEndpointMetricMap());
    SpectatorUtils.registerMeter(registry, clientMeter);
    VertxEndpointsMeter serverMeter = new ServerEndpointsMeter(endpointsId.withTag(ENDPOINTS_TYPE, ENDPOINTS_SERVER), SharedVertxFactory.getMetricsFactory().getVertxMetrics().getServerEndpointMetricMap());
    SpectatorUtils.registerMeter(registry, serverMeter);
}
Also used : VertxEndpointsMeter(org.apache.servicecomb.metrics.core.meter.vertx.VertxEndpointsMeter) HttpClientEndpointsMeter(org.apache.servicecomb.metrics.core.meter.vertx.HttpClientEndpointsMeter) ServerEndpointsMeter(org.apache.servicecomb.metrics.core.meter.vertx.ServerEndpointsMeter) GlobalRegistry(org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry) Registry(com.netflix.spectator.api.Registry) Id(com.netflix.spectator.api.Id)

Aggregations

GlobalRegistry (org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry)18 Registry (com.netflix.spectator.api.Registry)14 Test (org.junit.Test)6 EventBus (com.google.common.eventbus.EventBus)4 Meter (com.netflix.spectator.api.Meter)4 Expectations (mockit.Expectations)4 MetricsBootstrapConfig (org.apache.servicecomb.foundation.metrics.MetricsBootstrapConfig)4 OsMeter (org.apache.servicecomb.metrics.core.meter.os.OsMeter)4 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)3 ManualClock (com.netflix.spectator.api.ManualClock)3 Clock (com.netflix.spectator.api.Clock)2 Measurement (com.netflix.spectator.api.Measurement)2 Sample (io.prometheus.client.Collector.MetricFamilySamples.Sample)2 CollectorRegistry (io.prometheus.client.CollectorRegistry)2 VertxImpl (io.vertx.core.impl.VertxImpl)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2