use of org.apache.ignite.spi.metric.HistogramMetric in project ignite by apache.
the class CacheMetricsAddRemoveTest method checkMetricsNotEmpty.
/**
*/
private void checkMetricsNotEmpty(String cachePrefix) {
for (int i = 0; i < 2; i++) {
GridMetricManager mmgr = metricManager(i);
MetricRegistry mreg = mmgr.registry(cachePrefix);
assertNotNull(mreg.findMetric(CACHE_GETS));
assertNotNull(mreg.findMetric(CACHE_PUTS));
assertNotNull(mreg.findMetric(GET_TIME));
assertArrayEquals(BOUNDS, mreg.<HistogramMetric>findMetric(GET_TIME).bounds());
if (nearEnabled) {
mreg = mmgr.registry(metricName(cachePrefix, "near"));
assertNotNull(mreg.findMetric(CACHE_GETS));
assertNotNull(mreg.findMetric(CACHE_PUTS));
assertNotNull(mreg.findMetric(GET_TIME));
assertArrayEquals(BOUNDS, mreg.<HistogramMetric>findMetric(GET_TIME).bounds());
}
}
}
use of org.apache.ignite.spi.metric.HistogramMetric in project ignite by apache.
the class MetricsConfigurationTest method testHistogramConfiguration.
/**
* Tests configuration of {@link HistogramMetric}.
*/
@Test
public void testHistogramConfiguration() throws Exception {
try (IgniteEx g = startGrid(0)) {
MetricsMxBean bean = metricsBean(g);
// Empty name.
assertThrowsWithCause(() -> bean.configureHistogramMetric(null, BOUNDS), NullPointerException.class);
// Wrong bounds value.
assertThrowsWithCause(() -> bean.configureHistogramMetric(metricName(TX_METRICS, METRIC_SYSTEM_TIME_HISTOGRAM), null), NullPointerException.class);
assertThrowsWithCause(() -> bean.configureHistogramMetric(metricName(TX_METRICS, METRIC_SYSTEM_TIME_HISTOGRAM), new long[0]), IllegalArgumentException.class);
bean.configureHistogramMetric(metricName(TX_METRICS, METRIC_SYSTEM_TIME_HISTOGRAM), BOUNDS);
HistogramMetric systemTime = g.context().metric().registry(TX_METRICS).findMetric(METRIC_SYSTEM_TIME_HISTOGRAM);
assertArrayEquals(BOUNDS, systemTime.bounds());
}
}
use of org.apache.ignite.spi.metric.HistogramMetric in project ignite by apache.
the class MetricsConfigurationTest method testConfigRemovedOnCacheRemove.
/**
* Tests metric configuration removed on registry remove.
*/
@Test
public void testConfigRemovedOnCacheRemove() throws Exception {
String cacheRegName = cacheMetricsRegistryName("test", false);
checkOnStartAndRestart((g0, g1) -> {
g0.createCache("test");
awaitPartitionMapExchange();
HistogramMetricImpl getTime = g0.context().metric().registry(cacheRegName).findMetric("GetTime");
assertNotEquals(BOUNDS.length, getTime.bounds().length);
metricsBean(g0).configureHistogramMetric(metricName(cacheRegName, "GetTime"), BOUNDS);
assertArrayEquals(BOUNDS, g0.context().metric().registry(cacheRegName).<HistogramMetric>findMetric("GetTime").bounds());
assertArrayEquals(BOUNDS, g1.context().metric().registry(cacheRegName).<HistogramMetric>findMetric("GetTime").bounds());
}, (g0, g1) -> {
assertArrayEquals(BOUNDS, g0.context().metric().registry(cacheRegName).<HistogramMetric>findMetric("GetTime").bounds());
assertArrayEquals(BOUNDS, g1.context().metric().registry(cacheRegName).<HistogramMetric>findMetric("GetTime").bounds());
g0.destroyCache("test");
awaitPartitionMapExchange();
assertNull(g0.context().distributedMetastorage().read(metricName(cacheRegName, "GetTime")));
assertNull(g1.context().distributedMetastorage().read(metricName(cacheRegName, "GetTime")));
});
}
use of org.apache.ignite.spi.metric.HistogramMetric in project ignite by apache.
the class MetricRegistryMBean method getMBeanInfo.
/**
* {@inheritDoc}
*/
@Override
public MBeanInfo getMBeanInfo() {
Iterator<Metric> iter = mreg.iterator();
List<MBeanAttributeInfo> attributes = new ArrayList<>();
iter.forEachRemaining(metric -> {
if (metric instanceof HistogramMetric) {
String[] names = histogramBucketNames((HistogramMetric) metric);
assert names.length == ((HistogramMetric) metric).value().length;
for (String name : names) {
String n = name.substring(mreg.name().length() + 1);
attributes.add(new MBeanAttributeInfo(n, Long.class.getName(), metric.description() != null ? metric.description() : n, true, false, false));
}
} else {
attributes.add(new MBeanAttributeInfo(metric.name().substring(mreg.name().length() + 1), metricClass(metric), metric.description() != null ? metric.description() : metric.name(), true, false, false));
}
});
return new MBeanInfo(ReadOnlyMetricManager.class.getName(), mreg.name(), attributes.toArray(new MBeanAttributeInfo[attributes.size()]), null, null, null);
}
use of org.apache.ignite.spi.metric.HistogramMetric in project ignite by apache.
the class GridServiceMetricsTest method testServiceMetrics.
/**
* Invokes service in various ways: from clients, servers, etc. Checks these calls reflect in the metrics.
*
* @param serverCnt Number of server nodes.
* @param clientCnt Number of client nodes.
* @param perClusterCnt Number of service instances per cluster.
* @param perNodeCnt Number of service instances per node.
*/
private void testServiceMetrics(int serverCnt, int clientCnt, int perClusterCnt, int perNodeCnt) throws Throwable {
List<IgniteEx> servers = startGrids(serverCnt, false);
List<IgniteEx> clients = startGrids(clientCnt, true);
servers.get(0).services().deploy(serviceCfg(MyServiceFactory.create(), perClusterCnt, perNodeCnt));
awaitPartitionMapExchange();
List<MyService> serverStickyProxies = servers.stream().map(ignite -> (MyService) ignite.services().serviceProxy(SRVC_NAME, MyService.class, true)).collect(Collectors.toList());
List<MyService> clientStickyProxies = clients.stream().map(ignite -> (MyService) ignite.services().serviceProxy(SRVC_NAME, MyService.class, true)).collect(Collectors.toList());
long invokeCollector = 0;
// Call service through the server proxies.
for (int i = 0; i < INVOKE_CNT; ++i) {
// Call from server.
IgniteEx ignite = servers.get(i % servers.size());
callService4Times(ignite, serverStickyProxies.get(i % serverStickyProxies.size()));
// Call from client.
ignite = clients.get(i % clients.size());
callService4Times(ignite, clientStickyProxies.get(i % clientStickyProxies.size()));
invokeCollector += 8;
}
long invokesInMetrics = 0;
// Calculate and check invocations within the metrics.
for (IgniteEx ignite : servers) {
ReadOnlyMetricRegistry metrics = findMetricRegistry(ignite.context().metric(), SRVC_NAME);
// Metrics may not be deployed on this server node.
if (metrics == null)
continue;
for (Metric metric : metrics) {
if (metric instanceof HistogramMetric)
invokesInMetrics += sumHistogramEntries((HistogramMetric) metric);
}
}
// Compare calls number and metrics number.
assertEquals("Calculated wrong service invocation number.", invokesInMetrics, invokeCollector);
}
Aggregations