use of org.apache.ignite.spi.metric.Metric in project ignite by apache.
the class ReadMetricsOnNodeStartupTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setGridLogger(listeningLog);
PushMetricsExporterAdapter adapter = new PushMetricsExporterAdapter() {
@Override
public void export() {
try {
mreg.forEach(metrics -> {
// Read metric value.
metrics.forEach(Metric::getAsString);
});
} catch (Throwable e) {
log.error("Exception on metric export", e);
throw e;
}
exportLatch.countDown();
}
};
adapter.setPeriod(EXPORT_TIMEOUT);
cfg.setMetricExporterSpi(adapter);
return cfg;
}
use of org.apache.ignite.spi.metric.Metric in project ignite by apache.
the class CacheGroupMetricsTest method checkClientNode.
/**
* @throws Exception if failed.
*/
public void checkClientNode(boolean pds) throws Exception {
this.pds = pds;
startGrid(0);
IgniteEx client = startClientGrid(1);
if (pds)
client.cluster().state(ClusterState.ACTIVE);
AtomicReference<Exception> err = new AtomicReference<>();
Consumer<String> lsnr = new Consumer<String>() {
@Override
public void accept(String s) {
if (s.contains("Exception"))
err.set(new IgniteException("Error was logged: " + s));
}
};
testLog.registerListener(lsnr);
String[] names = new String[] { "group1", "group2", "cache4" };
for (String name : names) {
T2<CacheGroupMetricsMXBean, MetricRegistry> grp1 = cacheGroupMetrics(1, name);
for (Metric metric : grp1.get2()) metric.getAsString();
}
testLog.unregisterListener(lsnr);
if (err.get() != null)
throw err.get();
}
use of org.apache.ignite.spi.metric.Metric 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.Metric in project ignite by apache.
the class TcpCommunicationMetricsListener method resetMetrics.
/**
* Resets metrics for this instance.
*/
public void resetMetrics() {
rcvdMsgsMetric.reset();
sentMsgsMetric.reset();
sentBytesMetric.reset();
rcvdBytesMetric.reset();
for (Metric metric : mreg) {
if (metric.name().startsWith(SENT_MESSAGES_BY_TYPE_METRIC_NAME))
metric.reset();
else if (metric.name().startsWith(RECEIVED_MESSAGES_BY_TYPE_METRIC_NAME))
metric.reset();
}
for (ReadOnlyMetricRegistry mreg : spiCtx.metricRegistries()) {
if (mreg.name().startsWith(COMMUNICATION_METRICS_GROUP_NAME + SEPARATOR)) {
mreg.findMetric(SENT_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_NAME).reset();
mreg.findMetric(RECEIVED_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_NAME).reset();
}
}
}
use of org.apache.ignite.spi.metric.Metric in project ignite by apache.
the class GridMetricManager method find.
/**
* @param name Metric name.
* @param type Metric type.
* @return Metric.
*/
private <T extends Metric> T find(String name, Class<T> type) {
A.notNull(name, "name");
T2<String, String> splitted = fromFullName(name);
MetricRegistry mreg = (MetricRegistry) registries.get(splitted.get1());
if (mreg == null) {
if (log.isInfoEnabled())
log.info("Metric registry not found[registry=" + splitted.get1() + ']');
return null;
}
Metric m = mreg.findMetric(splitted.get2());
if (m == null) {
if (log.isInfoEnabled())
log.info("Metric not found[registry=" + splitted.get1() + ", metricName=" + splitted.get2() + ']');
return null;
}
if (!m.getClass().isAssignableFrom(type)) {
log.error("Metric '" + name + "' has wrong type[type=" + m.getClass().getSimpleName() + ']');
return null;
}
return (T) m;
}
Aggregations