Search in sources :

Example 1 with FlowMetricSet

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));
}
Also used : MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) MetricRegistry(com.codahale.metrics.MetricRegistry) FlowMetricSet(org.apache.nifi.metrics.FlowMetricSet)

Example 2 with FlowMetricSet

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);
}
Also used : MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) MetricRegistry(com.codahale.metrics.MetricRegistry) Metric(com.codahale.metrics.Metric) FlowMetricSet(org.apache.nifi.metrics.FlowMetricSet) Test(org.junit.Test)

Example 3 with FlowMetricSet

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);
}
Also used : MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) MetricRegistry(com.codahale.metrics.MetricRegistry) Metric(com.codahale.metrics.Metric) FlowMetricSet(org.apache.nifi.metrics.FlowMetricSet) Test(org.junit.Test)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)3 MemoryUsageGaugeSet (com.codahale.metrics.jvm.MemoryUsageGaugeSet)3 FlowMetricSet (org.apache.nifi.metrics.FlowMetricSet)3 Metric (com.codahale.metrics.Metric)2 Test (org.junit.Test)2