Search in sources :

Example 1 with Metric

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;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Metric(org.apache.ignite.spi.metric.Metric) PushMetricsExporterAdapter(org.apache.ignite.internal.processors.metric.PushMetricsExporterAdapter)

Example 2 with Metric

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();
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) AtomicReference(java.util.concurrent.atomic.AtomicReference) IgniteException(org.apache.ignite.IgniteException) CacheGroupMetricsMXBean(org.apache.ignite.mxbean.CacheGroupMetricsMXBean) Consumer(java.util.function.Consumer) IgniteException(org.apache.ignite.IgniteException) IgniteEx(org.apache.ignite.internal.IgniteEx) Metric(org.apache.ignite.spi.metric.Metric) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) AtomicLongMetric(org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric) IntMetric(org.apache.ignite.spi.metric.IntMetric) LongMetric(org.apache.ignite.spi.metric.LongMetric)

Example 3 with Metric

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);
}
Also used : MBeanInfo(javax.management.MBeanInfo) ReadOnlyMetricManager(org.apache.ignite.spi.metric.ReadOnlyMetricManager) ArrayList(java.util.ArrayList) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) IntMetric(org.apache.ignite.spi.metric.IntMetric) Metric(org.apache.ignite.spi.metric.Metric) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) LongMetric(org.apache.ignite.spi.metric.LongMetric) DoubleMetric(org.apache.ignite.spi.metric.DoubleMetric) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 4 with Metric

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();
        }
    }
}
Also used : ReadOnlyMetricRegistry(org.apache.ignite.spi.metric.ReadOnlyMetricRegistry) Metric(org.apache.ignite.spi.metric.Metric) LongAdderMetric(org.apache.ignite.internal.processors.metric.impl.LongAdderMetric) LongMetric(org.apache.ignite.spi.metric.LongMetric)

Example 5 with Metric

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;
}
Also used : ReadOnlyMetricRegistry(org.apache.ignite.spi.metric.ReadOnlyMetricRegistry) Metric(org.apache.ignite.spi.metric.Metric) AtomicLongMetric(org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) HitRateMetric(org.apache.ignite.internal.processors.metric.impl.HitRateMetric)

Aggregations

Metric (org.apache.ignite.spi.metric.Metric)17 LongMetric (org.apache.ignite.spi.metric.LongMetric)12 IgniteEx (org.apache.ignite.internal.IgniteEx)8 MetricRegistry (org.apache.ignite.internal.processors.metric.MetricRegistry)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 HashMap (java.util.HashMap)6 Test (org.junit.Test)6 Map (java.util.Map)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Set (java.util.Set)4 IgniteCache (org.apache.ignite.IgniteCache)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 HistogramMetric (org.apache.ignite.spi.metric.HistogramMetric)4 ReadOnlyMetricRegistry (org.apache.ignite.spi.metric.ReadOnlyMetricRegistry)4 ArrayList (java.util.ArrayList)3 Arrays.stream (java.util.Arrays.stream)3 Collections.singleton (java.util.Collections.singleton)3 LinkedHashSet (java.util.LinkedHashSet)3