Search in sources :

Example 1 with MetricsService

use of org.apache.nifi.reporting.datadog.metrics.MetricsService in project nifi by apache.

the class TestDataDogReportingTask method testUpdateMetricsProcessor.

// test updating metrics of processors
@Test
public void testUpdateMetricsProcessor() throws InitializationException, IOException {
    MetricsService ms = new MetricsService();
    Map<String, Double> processorMetrics = ms.getProcessorMetrics(procStatus);
    Map<String, String> tagsMap = ImmutableMap.of("env", "test");
    DataDogReportingTask dataDogReportingTask = new TestableDataDogReportingTask();
    dataDogReportingTask.initialize(initContext);
    dataDogReportingTask.setup(configurationContext);
    dataDogReportingTask.updateMetrics(processorMetrics, Optional.of("sampleProcessor"), tagsMap);
    verify(metricRegistry).register(eq("nifi.sampleProcessor.FlowFilesReceivedLast5Minutes"), Mockito.<Gauge>any());
    verify(metricRegistry).register(eq("nifi.sampleProcessor.ActiveThreads"), Mockito.<Gauge>any());
    verify(metricRegistry).register(eq("nifi.sampleProcessor.BytesWrittenLast5Minutes"), Mockito.<Gauge>any());
    verify(metricRegistry).register(eq("nifi.sampleProcessor.BytesReadLast5Minutes"), Mockito.<Gauge>any());
    verify(metricRegistry).register(eq("nifi.sampleProcessor.FlowFilesSentLast5Minutes"), Mockito.<Gauge>any());
}
Also used : MetricsService(org.apache.nifi.reporting.datadog.metrics.MetricsService) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) Test(org.junit.Test)

Example 2 with MetricsService

use of org.apache.nifi.reporting.datadog.metrics.MetricsService in project nifi by apache.

the class TestDataDogReportingTask method testUpdateMetricsJVM.

// test updating JMV metrics
@Test
public void testUpdateMetricsJVM() throws InitializationException, IOException {
    MetricsService ms = new MetricsService();
    Map<String, Double> processorMetrics = ms.getJVMMetrics(virtualMachineMetrics);
    Map<String, String> tagsMap = ImmutableMap.of("env", "test");
    DataDogReportingTask dataDogReportingTask = new TestableDataDogReportingTask();
    dataDogReportingTask.initialize(initContext);
    dataDogReportingTask.setup(configurationContext);
    dataDogReportingTask.updateMetrics(processorMetrics, Optional.<String>absent(), tagsMap);
    verify(metricRegistry).register(eq("nifi.flow.jvm.heap_usage"), Mockito.<Gauge>any());
    verify(metricRegistry).register(eq("nifi.flow.jvm.thread_count"), Mockito.<Gauge>any());
    verify(metricRegistry).register(eq("nifi.flow.jvm.thread_states.terminated"), Mockito.<Gauge>any());
    verify(metricRegistry).register(eq("nifi.flow.jvm.heap_used"), Mockito.<Gauge>any());
    verify(metricRegistry).register(eq("nifi.flow.jvm.thread_states.runnable"), Mockito.<Gauge>any());
    verify(metricRegistry).register(eq("nifi.flow.jvm.thread_states.timed_waiting"), Mockito.<Gauge>any());
    verify(metricRegistry).register(eq("nifi.flow.jvm.uptime"), Mockito.<Gauge>any());
    verify(metricRegistry).register(eq("nifi.flow.jvm.daemon_thread_count"), Mockito.<Gauge>any());
    verify(metricRegistry).register(eq("nifi.flow.jvm.file_descriptor_usage"), Mockito.<Gauge>any());
    verify(metricRegistry).register(eq("nifi.flow.jvm.thread_states.blocked"), Mockito.<Gauge>any());
}
Also used : MetricsService(org.apache.nifi.reporting.datadog.metrics.MetricsService) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) Test(org.junit.Test)

Example 3 with MetricsService

use of org.apache.nifi.reporting.datadog.metrics.MetricsService in project nifi by apache.

the class TestDataDogReportingTask method initContexts.

// init all contexts
private void initContexts() {
    configurationContext = Mockito.mock(ConfigurationContext.class);
    context = Mockito.mock(ReportingContext.class);
    Mockito.when(context.getProperty(DataDogReportingTask.ENVIRONMENT)).thenReturn(new MockPropertyValue(env, null));
    Mockito.when(context.getProperty(DataDogReportingTask.METRICS_PREFIX)).thenReturn(new MockPropertyValue(prefix, null));
    Mockito.when(context.getProperty(DataDogReportingTask.API_KEY)).thenReturn(new MockPropertyValue("agent", null));
    Mockito.when(context.getProperty(DataDogReportingTask.DATADOG_TRANSPORT)).thenReturn(new MockPropertyValue("DataDog Agent", null));
    EventAccess eventAccess = Mockito.mock(EventAccess.class);
    Mockito.when(eventAccess.getControllerStatus()).thenReturn(status);
    Mockito.when(context.getEventAccess()).thenReturn(eventAccess);
    logger = Mockito.mock(Logger.class);
    initContext = Mockito.mock(ReportingInitializationContext.class);
    Mockito.when(initContext.getIdentifier()).thenReturn(UUID.randomUUID().toString());
    // Mockito.when(initContext.getLogger()).thenReturn(logger);
    metricsMap = new ConcurrentHashMap<>();
    metricRegistry = Mockito.mock(MetricRegistry.class);
    virtualMachineMetrics = VirtualMachineMetrics.getInstance();
    metricsService = Mockito.mock(MetricsService.class);
}
Also used : EventAccess(org.apache.nifi.reporting.EventAccess) ConfigurationContext(org.apache.nifi.controller.ConfigurationContext) ReportingInitializationContext(org.apache.nifi.reporting.ReportingInitializationContext) MetricsService(org.apache.nifi.reporting.datadog.metrics.MetricsService) MetricRegistry(com.codahale.metrics.MetricRegistry) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) Logger(java.util.logging.Logger) ReportingContext(org.apache.nifi.reporting.ReportingContext)

Example 4 with MetricsService

use of org.apache.nifi.reporting.datadog.metrics.MetricsService in project nifi by apache.

the class TestMetricsService method init.

@Before
public void init() {
    status = new ProcessGroupStatus();
    metricsService = new MetricsService();
    status.setId("1234");
    status.setFlowFilesReceived(5);
    status.setBytesReceived(10000);
    status.setFlowFilesSent(10);
    status.setBytesSent(20000);
    status.setQueuedCount(100);
    status.setQueuedContentSize(1024L);
    status.setBytesRead(60000L);
    status.setBytesWritten(80000L);
    status.setActiveThreadCount(5);
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) MetricsService(org.apache.nifi.reporting.datadog.metrics.MetricsService) Before(org.junit.Before)

Aggregations

MetricsService (org.apache.nifi.reporting.datadog.metrics.MetricsService)4 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)2 Test (org.junit.Test)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Logger (java.util.logging.Logger)1 ConfigurationContext (org.apache.nifi.controller.ConfigurationContext)1 ProcessGroupStatus (org.apache.nifi.controller.status.ProcessGroupStatus)1 EventAccess (org.apache.nifi.reporting.EventAccess)1 ReportingContext (org.apache.nifi.reporting.ReportingContext)1 ReportingInitializationContext (org.apache.nifi.reporting.ReportingInitializationContext)1 MockPropertyValue (org.apache.nifi.util.MockPropertyValue)1 Before (org.junit.Before)1