Java Code Examples for org.apache.ignite.configuration.IgniteConfiguration#setMetricExporterSpi()

The following examples show how to use org.apache.ignite.configuration.IgniteConfiguration#setMetricExporterSpi() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenCensusMetricExporterSpiTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    cfg.setDataStorageConfiguration(new DataStorageConfiguration()
        .setDefaultDataRegionConfiguration(
            new DataRegionConfiguration()
                .setPersistenceEnabled(true)));

    OpenCensusMetricExporterSpi ocSpi = new OpenCensusMetricExporterSpi();

    ocSpi.setExportFilter(mgrp -> !mgrp.name().startsWith(FILTERED_PREFIX));
    ocSpi.setPeriod(EXPORT_TIMEOUT);
    ocSpi.setSendConsistentId(true);
    ocSpi.setSendInstanceName(true);
    ocSpi.setSendNodeId(true);

    cfg.setMetricExporterSpi(ocSpi);

    return cfg;
}
 
Example 2
Source File: SqlViewExporterSpiTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    cfg.setConsistentId(igniteInstanceName);

    cfg.setDataStorageConfiguration(new DataStorageConfiguration()
        .setDataRegionConfigurations(
            new DataRegionConfiguration().setName("in-memory").setMaxSize(100L * 1024 * 1024))
        .setDefaultDataRegionConfiguration(
            new DataRegionConfiguration()
                .setPersistenceEnabled(true)));

    SqlViewMetricExporterSpi sqlSpi = new SqlViewMetricExporterSpi();

    if (igniteInstanceName.endsWith("1"))
        sqlSpi.setExportFilter(mgrp -> !mgrp.name().startsWith(FILTERED_PREFIX));

    cfg.setMetricExporterSpi(sqlSpi);

    return cfg;
}
 
Example 3
Source File: StandaloneGridKernalContext.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @return Ignite configuration which allows to start requied processors for WAL reader
 */
protected IgniteConfiguration prepareIgniteConfiguration() {
    IgniteConfiguration cfg = new IgniteConfiguration();

    cfg.setDiscoverySpi(new StandaloneNoopDiscoverySpi());
    cfg.setCommunicationSpi(new StandaloneNoopCommunicationSpi());

    final Marshaller marshaller = new BinaryMarshaller();
    cfg.setMarshaller(marshaller);

    final DataStorageConfiguration pstCfg = new DataStorageConfiguration();
    final DataRegionConfiguration regCfg = new DataRegionConfiguration();
    regCfg.setPersistenceEnabled(true);
    pstCfg.setDefaultDataRegionConfiguration(regCfg);

    cfg.setDataStorageConfiguration(pstCfg);

    marshaller.setContext(marshallerCtx);

    cfg.setMetricExporterSpi(new NoopMetricExporterSpi());
    cfg.setSystemViewExporterSpi(new JmxSystemViewExporterSpi());

    return cfg;
}
 
Example 4
Source File: GridManagerMxBeanIllegalArgumentHandleTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** Creates minimal disco manager mock, checks illegal state is not propagated */
@Test
public void testIllegalStateIsCatch() {
    final IgniteConfiguration cfg = new IgniteConfiguration();
    cfg.setMetricExporterSpi(new NoopMetricExporterSpi());

    final IgniteLogger log = Mockito.mock(IgniteLogger.class);

    final GridKernalContext ctx = Mockito.mock(GridKernalContext.class);
    when(ctx.config()).thenReturn(cfg);
    when(ctx.log(Mockito.anyString())).thenReturn(log);
    when(ctx.log(Mockito.any(Class.class))).thenReturn(log);

    final GridMetricManager mgr = new GridMetricManager(ctx);
    final long nHeapMax = mgr.nonHeapMemoryUsage().getMax();
    if (correctSetupOfTestPerformed)
        assertEquals(0, nHeapMax);

    final long heapMax = mgr.heapMemoryUsage().getMax();
    if (correctSetupOfTestPerformed)
        assertEquals(0, heapMax);
}
 
Example 5
Source File: IgnitePageMemReplaceDelayedWriteUnitTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param overallSize default region size in bytes
 * @return configuration for test.
 */
@NotNull private IgniteConfiguration getConfiguration(long overallSize) {
    IgniteConfiguration cfg = new IgniteConfiguration();

    cfg.setEncryptionSpi(new NoopEncryptionSpi());

    cfg.setMetricExporterSpi(new NoopMetricExporterSpi());

    cfg.setEventStorageSpi(new NoopEventStorageSpi());

    cfg.setDataStorageConfiguration(
        new DataStorageConfiguration()
            .setDefaultDataRegionConfiguration(
                new DataRegionConfiguration()
                    .setPersistenceEnabled(true)
                    .setMaxSize(overallSize)));

    return cfg;
}
 
Example 6
Source File: JmxExporterSpiTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    cfg.setDataStorageConfiguration(new DataStorageConfiguration()
        .setDefaultDataRegionConfiguration(
            new DataRegionConfiguration()
                .setPersistenceEnabled(true)));

    JmxMetricExporterSpi jmxSpi = new JmxMetricExporterSpi();

    jmxSpi.setExportFilter(mgrp -> !mgrp.name().startsWith(FILTERED_PREFIX));

    cfg.setMetricExporterSpi(jmxSpi);

    return cfg;
}
 
Example 7
Source File: LogExporterSpiTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    cfg.setDataStorageConfiguration(new DataStorageConfiguration()
        .setDefaultDataRegionConfiguration(
            new DataRegionConfiguration()
                .setPersistenceEnabled(true)))
        .setGridLogger(log);

    LogExporterSpi logSpi = new LogExporterSpi();

    logSpi.setPeriod(EXPORT_TIMEOUT);

    logSpi.setExportFilter(mgrp -> !mgrp.name().startsWith(FILTERED_PREFIX));

    cfg.setMetricExporterSpi(logSpi);

    return cfg;
}
 
Example 8
Source File: ReadMetricsOnNodeStartupTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@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;
}
 
Example 9
Source File: IgnitionEx.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize default SPI implementations.
 *
 * @param cfg Ignite configuration.
 */
private void initializeDefaultSpi(IgniteConfiguration cfg) {
    if (cfg.getDiscoverySpi() == null)
        cfg.setDiscoverySpi(new TcpDiscoverySpi());

    if (cfg.getDiscoverySpi() instanceof TcpDiscoverySpi) {
        TcpDiscoverySpi tcpDisco = (TcpDiscoverySpi)cfg.getDiscoverySpi();

        if (tcpDisco.getIpFinder() == null)
            tcpDisco.setIpFinder(new TcpDiscoveryMulticastIpFinder());
    }

    if (cfg.getCommunicationSpi() == null)
        cfg.setCommunicationSpi(new TcpCommunicationSpi());

    if (cfg.getDeploymentSpi() == null)
        cfg.setDeploymentSpi(new LocalDeploymentSpi());

    if (cfg.getEventStorageSpi() == null)
        cfg.setEventStorageSpi(new NoopEventStorageSpi());

    if (cfg.getCheckpointSpi() == null)
        cfg.setCheckpointSpi(new NoopCheckpointSpi());

    if (cfg.getCollisionSpi() == null)
        cfg.setCollisionSpi(new NoopCollisionSpi());

    if (cfg.getFailoverSpi() == null)
        cfg.setFailoverSpi(new AlwaysFailoverSpi());

    if (cfg.getLoadBalancingSpi() == null)
        cfg.setLoadBalancingSpi(new RoundRobinLoadBalancingSpi());
    else {
        Collection<LoadBalancingSpi> spis = new ArrayList<>();

        boolean dfltLoadBalancingSpi = false;

        for (LoadBalancingSpi spi : cfg.getLoadBalancingSpi()) {
            spis.add(spi);

            if (!dfltLoadBalancingSpi && spi instanceof RoundRobinLoadBalancingSpi)
                dfltLoadBalancingSpi = true;
        }

        // Add default load balancing SPI for internal tasks.
        if (!dfltLoadBalancingSpi)
            spis.add(new RoundRobinLoadBalancingSpi());

        cfg.setLoadBalancingSpi(spis.toArray(new LoadBalancingSpi[spis.size()]));
    }

    if (cfg.getIndexingSpi() == null)
        cfg.setIndexingSpi(new NoopIndexingSpi());

    if (cfg.getEncryptionSpi() == null)
        cfg.setEncryptionSpi(new NoopEncryptionSpi());

    if (F.isEmpty(cfg.getMetricExporterSpi()))
        cfg.setMetricExporterSpi(new NoopMetricExporterSpi());

    if (F.isEmpty(cfg.getSystemViewExporterSpi())) {
        if (IgniteComponentType.INDEXING.inClassPath()) {
            try {
                cfg.setSystemViewExporterSpi(new JmxSystemViewExporterSpi(),
                    U.newInstance(SYSTEM_VIEW_SQL_SPI));
            }
            catch (IgniteCheckedException e) {
                throw new IgniteException(e);
            }

        }
        else
            cfg.setSystemViewExporterSpi(new JmxSystemViewExporterSpi());
    }
}
 
Example 10
Source File: GridTestKernalContext.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param log Logger to use in context config.
 * @param cfg Configuration to use in Test
 */
public GridTestKernalContext(IgniteLogger log, IgniteConfiguration cfg) {
    super(new GridLoggerProxy(log, null, null, null),
            new IgniteKernal(null),
            cfg,
            new GridKernalGatewayImpl(null),
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            cfg.getPluginProviders() != null && cfg.getPluginProviders().length > 0 ?
                Arrays.asList(cfg.getPluginProviders()) : U.allPluginProviders(),
            null,
            null,
            null,
            new LongJVMPauseDetector(log)
    );

    GridTestUtils.setFieldValue(grid(), "cfg", config());
    GridTestUtils.setFieldValue(grid(), "ctx", this);

    config().setGridLogger(log);

    if (cfg.getMetricExporterSpi() == null || cfg.getMetricExporterSpi().length == 0)
        cfg.setMetricExporterSpi(new NoopMetricExporterSpi());

    add(new GridMetricManager(this));
    add(new GridResourceProcessor(this));
    add(new GridInternalSubscriptionProcessor(this));
}
 
Example 11
Source File: GridTransactionsSystemUserTimeMetricsTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    cfg.setGridLogger(testLog);

    boolean isClient = igniteInstanceName.contains(CLIENT);

    if (!isClient) {
        CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME);

        ccfg.setAtomicityMode(TRANSACTIONAL);
        ccfg.setBackups(1);
        ccfg.setWriteSynchronizationMode(FULL_SYNC);

        cfg.setCacheConfiguration(ccfg);
    }

    cfg.setMetricExporterSpi(new JmxMetricExporterSpi());

    cfg.setCommunicationSpi(new TestCommunicationSpi());

    return cfg;
}
 
Example 12
Source File: OpenCensusMetricsExporterExample.java    From ignite with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Setting up prometheus stats collector.
    PrometheusStatsCollector.createAndRegister();

    // Setting up HTTP server that would serve http://localhost:8080 requests.
    HTTPServer srv = new HTTPServer(HOST, PORT, true);

    IgniteConfiguration cfg = new IgniteConfiguration();

    // Setting up OpenCensus exporter.
    OpenCensusMetricExporterSpi openCensusMetricExporterSpi = new OpenCensusMetricExporterSpi();

    // Metrics written to the collector each 1 second.
    openCensusMetricExporterSpi.setPeriod(PERIOD);

    cfg.setMetricExporterSpi(openCensusMetricExporterSpi);

    try (Ignite ignite = Ignition.start(cfg)) {
        // Creating cache.
        IgniteCache<Integer, Integer> cache = ignite.createCache("my-cache");

        // Putting some data to the cache.
        for (int i = 0; i < 100; i++)
            cache.put(i, i);

        // Sleeping for 2 sec to make sure data exported to the prometheus.
        Thread.sleep(2 * PERIOD);

        // If desktop supported opens up page with the metrics.
        if (Desktop.isDesktopSupported()) {
            Desktop desktop = Desktop.getDesktop();

            try {
                desktop.browse(new URI(METRICS_URL));

                Thread.sleep(2 * PERIOD);
            }
            catch (IOException | URISyntaxException e) {
                throw new RuntimeException(e);
            }
        }
        else {
            // In case desktop disabled printing URL content.
            URLConnection conn = new URL(METRICS_URL).openConnection();

            try (InputStream in = conn.getInputStream()) {
                String content = IOUtils.toString(in, conn.getContentEncoding());

                System.out.println(content);
            }
        }
    }
}