use of org.apache.nifi.metrics.FlowMetricSet in project nifi by apache.
the class MetricsReportingTask method init.
/**
* Register all wanted metrics to {@link #metricRegistry}.
* <p>
* {@inheritDoc}
*/
@Override
protected void init(ReportingInitializationContext config) {
metricRegistry = new MetricRegistry();
currentStatusReference = new AtomicReference<>();
metricRegistry.registerAll(new MemoryUsageGaugeSet());
metricRegistry.registerAll(new FlowMetricSet(currentStatusReference));
}
use of org.apache.nifi.metrics.FlowMetricSet in project nifi by apache.
the class MetricsReportingTaskTest method testValidLifeCycleReportsCorrectly.
/**
* Make sure that in a single life cycle the correct metrics are registered, the correct {@link ProcessGroupStatus}
* is used and that metrics are actually reported.
*/
@Test
public void testValidLifeCycleReportsCorrectly() throws Exception {
reportingContextStub.getEventAccess().setProcessGroupStatus(rootGroupStatus);
testedReportingTask.initialize(reportingInitContextStub);
testedReportingTask.connect(configurationContextStub);
testedReportingTask.onTrigger(reportingContextStub);
verify(reporterMock).report();
// Verify correct metrics are registered
ArgumentCaptor<MetricRegistry> registryCaptor = ArgumentCaptor.forClass(MetricRegistry.class);
verify(reporterServiceStub).createReporter(registryCaptor.capture());
MetricRegistry usedRegistry = registryCaptor.getValue();
Map<String, Metric> usedMetrics = usedRegistry.getMetrics();
assertTrue(usedMetrics.keySet().containsAll(new MemoryUsageGaugeSet().getMetrics().keySet()));
assertTrue(usedMetrics.keySet().containsAll(new FlowMetricSet(testedReportingTask.currentStatusReference).getMetrics().keySet()));
// Verify the most current ProcessGroupStatus is updated
assertEquals(testedReportingTask.currentStatusReference.get(), rootGroupStatus);
}
use of org.apache.nifi.metrics.FlowMetricSet in project nifi by apache.
the class MetricsReportingTaskTest method testValidLifeCycleReportsCorrectlyProcessGroupSpecified.
/**
* Make sure that in a single life cycle the correct metrics are registered, the correct {@link ProcessGroupStatus}
* is used and that metrics are actually reported.
*/
@Test
public void testValidLifeCycleReportsCorrectlyProcessGroupSpecified() throws Exception {
reportingContextStub.setProperty(MetricsReportingTask.PROCESS_GROUP_ID.getName(), TEST_GROUP_ID);
reportingContextStub.getEventAccess().setProcessGroupStatus(TEST_GROUP_ID, innerGroupStatus);
testedReportingTask.initialize(reportingInitContextStub);
testedReportingTask.connect(configurationContextStub);
testedReportingTask.onTrigger(reportingContextStub);
verify(reporterMock).report();
// Verify correct metrics are registered
ArgumentCaptor<MetricRegistry> registryCaptor = ArgumentCaptor.forClass(MetricRegistry.class);
verify(reporterServiceStub).createReporter(registryCaptor.capture());
MetricRegistry usedRegistry = registryCaptor.getValue();
Map<String, Metric> usedMetrics = usedRegistry.getMetrics();
assertTrue(usedMetrics.keySet().containsAll(new MemoryUsageGaugeSet().getMetrics().keySet()));
assertTrue(usedMetrics.keySet().containsAll(new FlowMetricSet(testedReportingTask.currentStatusReference).getMetrics().keySet()));
// Verify the most current ProcessGroupStatus is updated
assertEquals(testedReportingTask.currentStatusReference.get(), innerGroupStatus);
}
Aggregations