Hi all Thanks for the clarification in post ‘Adding metrics to Prometheus endpoint in the API’ - max_timer_driven_threads and max_event_driven_threads are constants and at this stage we are looking to expose them (and a few others below) to get better programmatic access to NiFi monitoring. But getting access to them is a challenge.
Tried: The object passed to the PrometheusReportingTask’s onTrigger method [1] is a StandardReportingContext [2] and this class has a FlowController instance that contains the thread and repository information we need. I tried to cast it to a StandardReportingContext so I could access the information but got a java.lang.ClassCastException, which I believe is caused by classes loaded with different classLoaders, stack trace below [3]. I tried to resolve this by adding the file org.apache.nifi.controller.reporting.ReportingContext under the local META-INF.services [4] to force the classLoader to load both classes, but same error. Question: How would you suggest accessing the maxTimerDrivenThreads, maxEventDrivenThreads, contentRepository, flowFileRepository and provenanceRepository fields that are available via the FlowController instance that’s in StandardReportingContext [2]? thanks [1] https://github.com/apache/nifi/blob/main/nifi-nar-bundles/nifi-prometheus-bundle/nifi-prometheus-reporting-task/src/main/java/org/apache/nifi/reporting/prometheus/PrometheusReportingTask.java#L196 [2] https://github.com/apache/nifi/blob/main/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/reporting/StandardReportingContext.java [3] 2021-02-12 11:15:29,434 ERROR [Timer-Driven Process Thread-3] o.a.n.r.p.PrometheusReportingTask PrometheusReportingTask[id=938b946e-0177-1000-221f-68f6ba8694a6] : java.lang.ClassCastException: org.apache.nifi.controller.reporting.StandardReportingContext cannot be cast to org.apache.nifi.controller.reporting.StandardReportingContext java.lang.ClassCastException: org.apache.nifi.controller.reporting.StandardReportingContext cannot be cast to org.apache.nifi.controller.reporting.StandardReportingContext at org.apache.nifi.reporting.prometheus.PrometheusReportingTask.onTrigger(PrometheusReportingTask.java:296) at org.apache.nifi.controller.tasks.ReportingTaskWrapper.run(ReportingTaskWrapper.java:44) 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.runAndReset(FutureTask.java:308) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) 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) [4] https://github.com/apache/nifi/blob/main/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/resources/META-INF/services
