Search in sources :

Example 1 with SystemMetricsRequest

use of ee.ria.xroad.monitor.common.SystemMetricsRequest in project X-Road by nordic-institute.

the class MonitorClient method getMetrics.

/**
 * Get monitoring metrics
 */
public MetricSetType getMetrics(List<String> metricNames, boolean isOwner) {
    try {
        final Future<Object> response = Patterns.ask(metricsProvider, new SystemMetricsRequest(metricNames, isOwner), Timeout.apply(TIMEOUT_REQUEST, TimeUnit.SECONDS));
        Object obj = Await.result(response, Duration.apply(TIMEOUT_AWAIT, TimeUnit.SECONDS));
        if (obj instanceof SystemMetricsResponse) {
            final SystemMetricsResponse result = (SystemMetricsResponse) obj;
            return MetricTypes.of(result.getMetrics());
        } else {
            throw new CodedException(ErrorCodes.X_INTERNAL_ERROR, "Unexpected response");
        }
    } catch (Exception e) {
        log.warn("Unable to read metrics", e);
        throw new CodedException(ErrorCodes.X_INTERNAL_ERROR, "Unable to read metrics");
    }
}
Also used : SystemMetricsResponse(ee.ria.xroad.monitor.common.SystemMetricsResponse) CodedException(ee.ria.xroad.common.CodedException) SystemMetricsRequest(ee.ria.xroad.monitor.common.SystemMetricsRequest) CodedException(ee.ria.xroad.common.CodedException)

Example 2 with SystemMetricsRequest

use of ee.ria.xroad.monitor.common.SystemMetricsRequest in project X-Road by nordic-institute.

the class MetricsProviderActorTest method testLimitedSystemMetricsRequest.

@Test
public void testLimitedSystemMetricsRequest() throws Exception {
    final Props props = Props.create(MetricsProviderActor.class);
    final TestActorRef<MetricsProviderActor> ref = TestActorRef.create(actorSystem, props, "testActorRef");
    Future<Object> future = Patterns.ask(ref, new SystemMetricsRequest(null, false), Timeout.apply(1, TimeUnit.MINUTES));
    Object result = Await.result(future, Duration.apply(1, TimeUnit.MINUTES));
    assertTrue(future.isCompleted());
    assertTrue(result instanceof SystemMetricsResponse);
    SystemMetricsResponse response = (SystemMetricsResponse) result;
    MetricSetDto metricSetDto = response.getMetrics();
    Set<MetricDto> dtoSet = metricSetDto.getMetrics();
    log.info("metricSetDto: " + metricSetDto);
    for (MetricDto metricDto : dtoSet) {
        // Order of entries is undefined -> Must handle by name
        switch(metricDto.getName()) {
            case HISTOGRAM_NAME:
                Assert.fail("Should not have histrogram.");
                break;
            case GAUGE_NAME:
                Assert.fail("Should not have histrogram gauge.");
                break;
            default:
                Assert.fail("Unknown metric found in response.");
                break;
        }
    }
}
Also used : SystemMetricsResponse(ee.ria.xroad.monitor.common.SystemMetricsResponse) MetricDto(ee.ria.xroad.monitor.common.dto.MetricDto) SystemMetricsRequest(ee.ria.xroad.monitor.common.SystemMetricsRequest) MetricSetDto(ee.ria.xroad.monitor.common.dto.MetricSetDto) Props(akka.actor.Props) Test(org.junit.Test)

Example 3 with SystemMetricsRequest

use of ee.ria.xroad.monitor.common.SystemMetricsRequest in project X-Road by nordic-institute.

the class MetricsProviderActor method onReceive.

@Override
public void onReceive(Object o) throws Exception {
    if (o instanceof SystemMetricsRequest) {
        final SystemMetricsRequest req = (SystemMetricsRequest) o;
        log.info("Received SystemMetricsRequest: " + req);
        if (req.getMetricNames() != null && req.getMetricNames().size() > 0) {
            log.info("Specified metrics requested: " + req.getMetricNames());
            log.info("Is owner of security server: " + req.isClientOwner());
        }
        MetricRegistry metrics = MetricRegistryHolder.getInstance().getMetrics();
        final MetricSetDto.Builder builder = new MetricSetDto.Builder("systemMetrics");
        collectMetrics(builder, metrics, req.getMetricNames(), req.isClientOwner());
        if (req.isClientOwner() || !SystemProperties.getEnvMonitorLimitRemoteDataSet()) {
            collectOwnerMetrics(builder, metrics, req.getMetricNames());
        }
        MetricSetDto metricSet = builder.build();
        final SystemMetricsResponse response = new SystemMetricsResponse(metricSet);
        getSender().tell(response, getSelf());
    } else {
        unhandled(o);
    }
}
Also used : SystemMetricsResponse(ee.ria.xroad.monitor.common.SystemMetricsResponse) SystemMetricsRequest(ee.ria.xroad.monitor.common.SystemMetricsRequest) MetricRegistry(com.codahale.metrics.MetricRegistry) MetricSetDto(ee.ria.xroad.monitor.common.dto.MetricSetDto)

Example 4 with SystemMetricsRequest

use of ee.ria.xroad.monitor.common.SystemMetricsRequest in project X-Road by nordic-institute.

the class ClientActor method onReceive.

@Override
public void onReceive(Object o) throws Exception {
    if (o.equals("Start")) {
        selection.tell(new SystemMetricsRequest(null, true), getSelf());
        log.info("ClientActor sent SystemMetricsRequest");
    } else if (o instanceof SystemMetricsResponse) {
        SystemMetricsResponse response = (SystemMetricsResponse) o;
        log.info("ClientActor received SystemMetricsResponse");
    } else {
        unhandled(o);
    }
}
Also used : SystemMetricsResponse(ee.ria.xroad.monitor.common.SystemMetricsResponse) SystemMetricsRequest(ee.ria.xroad.monitor.common.SystemMetricsRequest)

Example 5 with SystemMetricsRequest

use of ee.ria.xroad.monitor.common.SystemMetricsRequest in project X-Road by nordic-institute.

the class MetricsProviderActorTest method testAllSystemMetricsRequest.

@Test
public void testAllSystemMetricsRequest() throws Exception {
    final Props props = Props.create(MetricsProviderActor.class);
    final TestActorRef<MetricsProviderActor> ref = TestActorRef.create(actorSystem, props, "testActorRef");
    Future<Object> future = Patterns.ask(ref, new SystemMetricsRequest(null, true), Timeout.apply(1, TimeUnit.MINUTES));
    Object result = Await.result(future, Duration.apply(1, TimeUnit.MINUTES));
    assertTrue(future.isCompleted());
    assertTrue(result instanceof SystemMetricsResponse);
    SystemMetricsResponse response = (SystemMetricsResponse) result;
    MetricSetDto metricSetDto = response.getMetrics();
    Set<MetricDto> dtoSet = metricSetDto.getMetrics();
    log.info("metricSetDto: " + metricSetDto);
    assertEquals(2, dtoSet.stream().count());
    for (MetricDto metricDto : dtoSet) {
        // Order of entries is undefined -> Must handle by name
        switch(metricDto.getName()) {
            case HISTOGRAM_NAME:
                log.info("metricDto: " + metricDto);
                assertEquals(HISTOGRAM_NAME, metricDto.getName());
                assertTrue(metricDto instanceof HistogramDto);
                HistogramDto h = (HistogramDto) metricDto;
                assertEquals(100L, (long) h.getMax());
                assertEquals(10L, (long) h.getMin());
                assertEquals(55L, (long) h.getMean());
                break;
            case GAUGE_NAME:
                log.info("metricDto: " + metricDto);
                assertEquals(GAUGE_NAME, metricDto.getName());
                break;
            default:
                Assert.fail("Unknown metric found in response.");
        }
    }
}
Also used : HistogramDto(ee.ria.xroad.monitor.common.dto.HistogramDto) SystemMetricsResponse(ee.ria.xroad.monitor.common.SystemMetricsResponse) MetricDto(ee.ria.xroad.monitor.common.dto.MetricDto) SystemMetricsRequest(ee.ria.xroad.monitor.common.SystemMetricsRequest) MetricSetDto(ee.ria.xroad.monitor.common.dto.MetricSetDto) Props(akka.actor.Props) Test(org.junit.Test)

Aggregations

SystemMetricsRequest (ee.ria.xroad.monitor.common.SystemMetricsRequest)6 SystemMetricsResponse (ee.ria.xroad.monitor.common.SystemMetricsResponse)6 MetricSetDto (ee.ria.xroad.monitor.common.dto.MetricSetDto)4 Props (akka.actor.Props)3 MetricDto (ee.ria.xroad.monitor.common.dto.MetricDto)3 Test (org.junit.Test)3 HistogramDto (ee.ria.xroad.monitor.common.dto.HistogramDto)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 CodedException (ee.ria.xroad.common.CodedException)1