Support Questions

Find answers, ask questions, and share your expertise
Announcements
Check out our newest addition to the community, the Cloudera Data Analytics (CDA) group hub.

NiFi ScriptedReportingTask error - java.lang.NoClassDefFoundError: org/apache/nifi/metrics/jvm/JmxJvmMetrics

New Contributor

I'm trying to use the ScriptedReportingTask but I'm getting this exception:

 

 

 

2020-06-18 21:53:55,892 ERROR [Timer-Driven Process Thread-9] o.a.n.r.script.ScriptedReportingTask ScriptedReportingTask[id=c96216cf-0172-1000-14c2-0419fd00a2ac] Failed to invoke @OnScheduled method due to java.lang.NoClassDefFoundError: org/apache/nifi/metrics/jvm/JmxJvmMetrics: {}
java.lang.NoClassDefFoundError: org/apache/nifi/metrics/jvm/JmxJvmMetrics
	at org.apache.nifi.reporting.script.ScriptedReportingTask.setup(ScriptedReportingTask.java:146)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.nifi.util.ReflectionUtils.invokeMethodsWithAnnotations(ReflectionUtils.java:142)
	at org.apache.nifi.util.ReflectionUtils.invokeMethodsWithAnnotations(ReflectionUtils.java:130)
	at org.apache.nifi.util.ReflectionUtils.invokeMethodsWithAnnotations(ReflectionUtils.java:75)
	at org.apache.nifi.util.ReflectionUtils.invokeMethodsWithAnnotation(ReflectionUtils.java:52)
	at org.apache.nifi.controller.scheduling.StandardProcessScheduler$2.run(StandardProcessScheduler.java:222)
	at org.apache.nifi.engine.FlowEngine$2.run(FlowEngine.java:110)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
2020-06-18 21:53:55,893 ERROR [Timer-Driven Process Thread-9] o.a.n.c.s.StandardProcessScheduler Failed to invoke the On-Scheduled Lifecycle methods of [ScriptedReportingTask[id=c96216cf-0172-1000-14c2-0419fd00a2ac], java.lang.reflect.InvocationTargetException, 30 sec] due to {}; administratively yielding this ReportingTask and will attempt to schedule it again after {}
java.lang.reflect.InvocationTargetException: null
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.nifi.util.ReflectionUtils.invokeMethodsWithAnnotations(ReflectionUtils.java:142)
	at org.apache.nifi.util.ReflectionUtils.invokeMethodsWithAnnotations(ReflectionUtils.java:130)
	at org.apache.nifi.util.ReflectionUtils.invokeMethodsWithAnnotations(ReflectionUtils.java:75)
	at org.apache.nifi.util.ReflectionUtils.invokeMethodsWithAnnotation(ReflectionUtils.java:52)
	at org.apache.nifi.controller.scheduling.StandardProcessScheduler$2.run(StandardProcessScheduler.java:222)
	at org.apache.nifi.engine.FlowEngine$2.run(FlowEngine.java:110)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: org/apache/nifi/metrics/jvm/JmxJvmMetrics
	at org.apache.nifi.reporting.script.ScriptedReportingTask.setup(ScriptedReportingTask.java:146)
	... 17 common frames omitted

 

 

 

 

NiFi Version: 1.11.4

Docker Image: apache/nifi:1.11.4

Script Engine: Groovy

Script Body:

 

 

 

def json = Class.forName("javax.json.Json")
def httpClients = Class.forName("org.apache.http.impl.client.HttpClients")
def contentType = Class.forName("org.apache.http.entity.ContentType")

def status = context.getEventAccess().getControllerStatus();
def factory = json.createBuilderFactory(Collections.emptyMap());
def builder = factory.createObjectBuilder();

builder.add("componentId", status.getId());
builder.add("bytesRead", status.getBytesRead());
builder.add("bytesWritten", status.getBytesWritten());
builder.add("bytesReceived", status.getBytesReceived());
builder.add("bytesSent", status.getBytesSent());
builder.add("bytesTransferred", status.getBytesTransferred());
builder.add("flowFilesReceived", status.getFlowFilesReceived());
builder.add("flowFilesSent", status.getFlowFilesSent());
builder.add("flowFilesTransferred", status.getFlowFilesTransferred());
builder.add("inputContentSize", status.getInputContentSize());
builder.add("inputCount", status.getInputCount());
builder.add("outputContentSize", status.getOutputContentSize());
builder.add("outputCount", status.getOutputCount());
builder.add("queuedContentSize", status.getQueuedContentSize());
builder.add("activeThreadCount", status.getActiveThreadCount());
builder.add("queuedCount", status.getQueuedCount());

def requestEntity = new org.apache.http.entity.StringEntity(builder.build().toString(), contentType.APPLICATION_JSON);
def httpclient = httpClients.createDefault();
def postMethod = new org.apache.http.client.methods.HttpPost("http://nifitwo:9999/rootStatus");
postMethod.setEntity(requestEntity);
httpclient.execute(postMethod);
httpclient.close();

 

 

 

 

3 REPLIES 3

New Contributor

You can download the nifi-metrics.jar with dependencies and add them to the lib folder. After a restarting nifi the problem should be resolved.

New Contributor

I tried but now NiFi can not start.

 

I'm using this jar file: https://mvnrepository.com/artifact/org.apache.nifi/nifi-metrics/1.11.4

 

nifi    | 2020-07-14 12:16:36,811 ERROR [main] org.apache.nifi.NiFi Failure to launch NiFi due to java.util.ServiceConfigurationError: org.apache.nifi.reporting.ReportingTask: Provider org.apache.nifi.reporting.azure.loganalytics.AzureLogAnalyticsReportingTask could not be instantiated
nifi    | java.util.ServiceConfigurationError: org.apache.nifi.reporting.ReportingTask: Provider org.apache.nifi.reporting.azure.loganalytics.AzureLogAnalyticsReportingTask could not be instantiated
nifi    | 	at java.util.ServiceLoader.fail(ServiceLoader.java:232)
nifi    | 	at java.util.ServiceLoader.access$100(ServiceLoader.java:185)
nifi    | 	at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384)
nifi    | 	at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
nifi    | 	at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
nifi    | 	at org.apache.nifi.nar.StandardExtensionDiscoveringManager.loadExtensions(StandardExtensionDiscoveringManager.java:156)
nifi    | 	at org.apache.nifi.nar.StandardExtensionDiscoveringManager.discoverExtensions(StandardExtensionDiscoveringManager.java:131)
nifi    | 	at org.apache.nifi.nar.StandardExtensionDiscoveringManager.discoverExtensions(StandardExtensionDiscoveringManager.java:117)
nifi    | 	at org.apache.nifi.web.server.JettyServer.start(JettyServer.java:942)
nifi    | 	at org.apache.nifi.NiFi.<init>(NiFi.java:158)
nifi    | 	at org.apache.nifi.NiFi.<init>(NiFi.java:72)
nifi    | 	at org.apache.nifi.NiFi.main(NiFi.java:301)
nifi    | Caused by: java.lang.NoClassDefFoundError: com/codahale/metrics/Metric
nifi    | 	at org.apache.nifi.reporting.azure.loganalytics.AzureLogAnalyticsReportingTask.<init>(AzureLogAnalyticsReportingTask.java:52)
nifi    | 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
nifi    | 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
nifi    | 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
nifi    | 	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
nifi    | 	at java.lang.Class.newInstance(Class.java:442)
nifi    | 	at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
nifi    | 	... 9 common frames omitted
nifi    | Caused by: java.lang.ClassNotFoundException: com.codahale.metrics.Metric
nifi    | 	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
nifi    | 	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
nifi    | 	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
nifi    | 	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
nifi    | 	... 16 common frames omitted

 

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.