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");
}
}
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;
}
}
}
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);
}
}
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);
}
}
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.");
}
}
}
Aggregations