[英]Where to add a bean to the Apache Ignite configuration file?
我有一個 Apache Ignite 集群,我正在嘗試將其與 Prometheus 堆棧集成,一切都很好,除了沒有生成指標。
這是我當前的配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--
Alter configuration below as needed.
-->
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="clientMode" value="false"/>
<!-- Enabling Apache Ignite Persistent Store. -->
<property name="dataStorageConfiguration">
<bean class="org.apache.ignite.configuration.DataStorageConfiguration">
<property name="defaultDataRegionConfiguration">
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
<property name="persistenceEnabled" value="true"/>
</bean>
</property>
</bean>
</property>
<property name="consistentId" value="myIgniteNode01"/>
<property name="cacheConfiguration">
<list>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<!-- Set a cache name. -->
<property name="name" value="ReplicatedCache"/>
<!-- Set cache mode. -->
<property name="cacheMode" value="REPLICATED"/>
<!-- Other cache configurations. -->
</bean>
</list>
</property>
<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="ipFinder">
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
<property name="addresses">
<list>
<!--
Explicitly specifying address of a local node to let it start and
operate normally even if there is no more nodes in the cluster.
You can also optionally specify an individual port or port range.
-->
<value>xxx.xxx.xxx.xxx:xxxx</value>
<value>yyy.yyy.yyy.yyy:yyyy</value>
<value>zzz.zzz.zzz.zzz:zzzz</value>
</list>
</property>
</bean>
</property>
</bean>
</property>
</bean>
<bean id="opencensusWrapper" class="org.springframework.beans.factory.config.MethodInvokingBean">
<property name="staticMethod" value="io.opencensus.exporter.stats.prometheus.PrometheusStatsCollector.createAndRegister"/>
</bean>
<bean id="httpServer" class="io.prometheus.client.exporter.HTTPServer">
<constructor-arg type="java.lang.String" value="xxx.xxx.xxx.xxx"/>
<constructor-arg type="int" value="xxxx"/>
<constructor-arg type="boolean" value="true"/>
</bean>
</beans>
我需要添加以下 bean:
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="metricsUpdateFrequency" value="1000"/>
<property name="metricExporterSpi">
<list>
<bean class="org.apache.ignite.spi.metric.opencensus.OpenCensusMetricExporterSpi">
<property name="period" value="1000" />
</bean>
</list>
</property>
但我不知道在哪里添加它。
我嘗試了以下方法:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--
Alter configuration below as needed.
-->
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="metricsUpdateFrequency" value="1000"/>
<property name="metricExporterSpi">
<list>
<bean class="org.apache.ignite.spi.metric.opencensus.OpenCensusMetricExporterSpi">
<property name="period" value="1000" />
</bean>
</list>
</property>
<property name="clientMode" value="false"/>
<!-- Enabling Apache Ignite Persistent Store. -->
<property name="dataStorageConfiguration">
<bean class="org.apache.ignite.configuration.DataStorageConfiguration">
<property name="defaultDataRegionConfiguration">
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
<property name="persistenceEnabled" value="true"/>
</bean>
</property>
</bean>
</property>
<property name="consistentId" value="myIgniteNode01"/>
<property name="cacheConfiguration">
<list>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<!-- Set a cache name. -->
<property name="name" value="ReplicatedCache"/>
<!-- Set cache mode. -->
<property name="cacheMode" value="REPLICATED"/>
<!-- Other cache configurations. -->
</bean>
</list>
</property>
<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="ipFinder">
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
<property name="addresses">
<list>
<!--
Explicitly specifying address of a local node to let it start and
operate normally even if there is no more nodes in the cluster.
You can also optionally specify an individual port or port range.
-->
<value>xxx.xxx.xxx.xxx:xxxx</value>
<value>yyy.yyy.yyy.yyy:yyyy</value>
<value>zzz.zzz.zzz.zzz:zzzz</value>
</list>
</property>
</bean>
</property>
</bean>
</property>
</bean>
<bean id="opencensusWrapper" class="org.springframework.beans.factory.config.MethodInvokingBean">
<property name="staticMethod" value="io.opencensus.exporter.stats.prometheus.PrometheusStatsCollector.createAndRegister"/>
</bean>
<bean id="httpServer" class="io.prometheus.client.exporter.HTTPServer">
<constructor-arg type="java.lang.String" value="xxx.xxx.xxx.xxx"/>
<constructor-arg type="int" value="xxxx"/>
<constructor-arg type="boolean" value="true"/>
</bean>
</beans>
但是該服務無法啟動並會拋出如下錯誤:
service.sh[536823]: class org.apache.ignite.IgniteException: Failed to instantiate Spring XML application context (make sure all classes used in Spring configuration are present at CLASSPATH) [springUrl=file:/etc/apache-ignite/default-config.xml]
service.sh[536823]: at org.apache.ignite.internal.util.IgniteUtils.convertException(IgniteUtils.java:1145)
service.sh[536823]: at org.apache.ignite.Ignition.start(Ignition.java:356)
service.sh[536823]: at org.apache.ignite.startup.cmdline.CommandLineStartup.main(CommandLineStartup.java:365)
service.sh[536823]: Caused by: class org.apache.ignite.IgniteCheckedException: Failed to instantiate Spring XML application context (make sure all classes used in Spring configuration are present at CLASSPATH) [springUrl=file:/etc/apache-ignite/default-config.xml]
service.sh[536823]: at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.applicationContext(IgniteSpringHelperImpl.java:381)
service.sh[536823]: at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.loadConfigurations(IgniteSpringHelperImpl.java:103)
service.sh[536823]: at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.loadConfigurations(IgniteSpringHelperImpl.java:97)
service.sh[536823]: at org.apache.ignite.internal.IgnitionEx.loadConfigurations(IgnitionEx.java:730)
service.sh[536823]: at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:915)
service.sh[536823]: at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:840)
service.sh[536823]: at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:710)
service.sh[536823]: at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:679)
service.sh[536823]: at org.apache.ignite.Ignition.start(Ignition.java:353)
service.sh[536823]: ... 1 more
service.sh[536823]: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grid.cfg' defined in URL [file:/etc/apache-ignite/default-config.xml]: Cannot create inner bean 'org.apache.ignite.spi.metric.opencensus.OpenCensusMetricExporterSpi#6fd02e5' of type [org.apache.ignite.spi.metric.opencens>
service.sh[536823]: at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:389)
service.sh[536823]: at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:127)
service.sh[536823]: at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:428)
service.sh[536823]: at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:173)
service.sh[536823]: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1702)
service.sh[536823]: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1447)
service.sh[536823]: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
service.sh[536823]: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
service.sh[536823]: at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
service.sh[536823]: at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
service.sh[536823]: at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
service.sh[536823]: at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
service.sh[536823]: at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897)
service.sh[536823]: at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
service.sh[536823]: at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
service.sh[536823]: at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.applicationContext(IgniteSpringHelperImpl.java:375)
service.sh[536823]: ... 9 more
service.sh[536823]: Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.ignite.spi.metric.opencensus.OpenCensusMetricExporterSpi] for bean with name 'org.apache.ignite.spi.metric.opencensus.OpenCensusMetricExporterSpi#6fd02e5' defined in URL [file:/etc/apache-ignite/default-config.xml]>
service.sh[536823]: at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1486)
service.sh[536823]: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:488)
service.sh[536823]: at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:374)
service.sh[536823]: ... 24 more
service.sh[536823]: Caused by: java.lang.ClassNotFoundException: org.apache.ignite.spi.metric.opencensus.OpenCensusMetricExporterSpi
service.sh[536823]: at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
service.sh[536823]: at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
service.sh[536823]: at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
service.sh[536823]: at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
service.sh[536823]: at java.lang.Class.forName0(Native Method)
service.sh[536823]: at java.lang.Class.forName(Class.java:348)
service.sh[536823]: at org.springframework.util.ClassUtils.forName(ClassUtils.java:284)
service.sh[536823]: at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:469)
service.sh[536823]: at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1551)
service.sh[536823]: at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1478)
service.sh[536823]: ... 26 more
service.sh[536823]: Failed to start grid: Failed to instantiate Spring XML application context (make sure all classes used in Spring configuration are present at CLASSPATH) [springUrl=file:/etc/apache-ignite/default-config.xml]
service.sh[536823]: Note! You may use 'USER_LIBS' environment variable to specify your classpath.
這是我的systemd
服務文件:
[Unit]
Description=Apache Ignite In-Memory Computing Platform Service
After=syslog.target network.target
[Service]
Type=forking
User=ignite
WorkingDirectory=/usr/share/apache-ignite/work
PermissionsStartOnly=true
Environment="USER_LIBS=/lib/apache-ignite/ignite-prometheus-1.0-SNAPSHOT-jar-with-dependencies.jar"
ExecStartPre=-/bin/mkdir -p /var/run/apache-ignite
ExecStartPre=-/bin/chown ignite:ignite /var/run/apache-ignite
ExecStartPre=-/usr/bin/env bash /usr/share/apache-ignite/bin/service.sh set-firewall
ExecStart=/usr/share/apache-ignite/bin/service.sh start %i
PIDFile=/var/run/apache-ignite/%i.pid
[Install]
WantedBy=multi-user.target
任何幫助表示贊賞,在此先感謝。
更新:我已經將ignite-opencensus
庫復制到apache-ignite
lib 目錄:
ls -l /lib/apache-ignite/
total 17696
-rw-r--r-- 1 root root 18587 Sep 29 12:21 annotations-16.0.3.jar
-rw-r--r-- 1 root root 49789 Sep 29 12:21 cache-api-1.0.0.jar
drwxr-xr-x 3 root root 4096 Dec 12 12:49 ignite-control-utility
-rw-r--r-- 1 root root 14614623 Sep 29 12:21 ignite-core-2.14.0.jar
drwxr-xr-x 3 root root 4096 Dec 12 12:49 ignite-indexing
drwxr-x--- 3 root root 4096 Dec 18 16:55 ignite-opencensus
-rw-r----- 1 ignite root 3394491 Dec 18 16:53 ignite-prometheus-1.0-SNAPSHOT-jar-with-dependencies.jar
drwxr-xr-x 3 root root 4096 Dec 12 12:49 ignite-spring
drwxr-xr-x 2 root root 4096 Dec 12 12:49 licenses
drwxr-xr-x 25 root root 4096 Dec 12 12:49 optional
-rw-r--r-- 1 root root 4205 Sep 29 12:21 README.txt
更新2:
我已經在 Ubuntu 20.04 上使用此文檔安裝了apache-ignite
版本 2.14.0。
我需要將它與 Prometheus 集成,所以我點擊了此鏈接。
一切正常,除了這些之外沒有其他指標:
# HELP oc_worker_spans_dropped Number of spans dropped by the exporter thread.
# TYPE oc_worker_spans_dropped counter
oc_worker_spans_dropped 0.0
# HELP oc_worker_spans_pushed Number of spans pushed by the exporter thread to the exporter.
# TYPE oc_worker_spans_pushed counter
oc_worker_spans_pushed 0.0
# HELP oc_worker_spans_referenced Current number of spans referenced by the exporter thread.
# TYPE oc_worker_spans_referenced gauge
oc_worker_spans_referenced 0.0
UPDATE3:我剛剛再次檢查了文檔,因為它提到了/usr/lib/apache/
目錄,我也檢查了該目錄:
ls -l /usr/lib/apache-ignite/
total 17696
-rw-r--r-- 1 root root 18587 Sep 29 12:21 annotations-16.0.3.jar
-rw-r--r-- 1 root root 49789 Sep 29 12:21 cache-api-1.0.0.jar
drwxr-xr-x 3 root root 4096 Dec 12 12:49 ignite-control-utility
-rw-r--r-- 1 root root 14614623 Sep 29 12:21 ignite-core-2.14.0.jar
drwxr-xr-x 3 root root 4096 Dec 12 12:49 ignite-indexing
drwxr-x--- 3 root root 4096 Dec 19 15:46 ignite-opencensus
-rw-r----- 1 ignite root 3394491 Dec 18 16:53 ignite-prometheus-1.0-SNAPSHOT-jar-with-dependencies.jar
drwxr-xr-x 3 root root 4096 Dec 12 12:49 ignite-spring
drwxr-xr-x 2 root root 4096 Dec 12 12:49 licenses
drwxr-xr-x 25 root root 4096 Dec 12 12:49 optional
-rw-r--r-- 1 root root 4205 Sep 29 12:21 README.txt
如您所見, ignite-opencensus
存在於此路徑中。
您在正確的位置有配置選項。 您沒有的是 CLASSPATH 中的 OpenCensus 導出器。 最簡單的方法是將ignite-opencensus
文件夾從$IGNITE_HOME/libs/optional
復制到$IGNITE_HOME/libs
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.