Search in sources :

Example 1 with SystemMetricsResponse

use of ee.ria.xroad.monitor.common.SystemMetricsResponse 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 SystemMetricsResponse

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

the class SecurityServerMetricsMessage method createMetricsResponse.

private static SystemMetricsResponse createMetricsResponse() {
    HistogramDto histogramDto = new HistogramDto("exampleHistogram", 75, 95, 98, 99, 99.9, MAX_VALUE, 50, 51, MIN_VALUE, 2);
    MetricSetDto.Builder builder = new MetricSetDto.Builder(EXPECTED_METRIC_SET_NAME);
    builder.withMetric(histogramDto);
    return new SystemMetricsResponse(builder.build());
}
Also used : HistogramDto(ee.ria.xroad.monitor.common.dto.HistogramDto) SystemMetricsResponse(ee.ria.xroad.monitor.common.SystemMetricsResponse) MetricSetDto(ee.ria.xroad.monitor.common.dto.MetricSetDto)

Example 3 with SystemMetricsResponse

use of ee.ria.xroad.monitor.common.SystemMetricsResponse 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 4 with SystemMetricsResponse

use of ee.ria.xroad.monitor.common.SystemMetricsResponse 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 5 with SystemMetricsResponse

use of ee.ria.xroad.monitor.common.SystemMetricsResponse 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)

Aggregations

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