org.apache.nifi.controller.status.ProcessorStatus Java Examples

The following examples show how to use org.apache.nifi.controller.status.ProcessorStatus. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestAzureLogAnalyticsReportingTask.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void initProcessorStatuses() {
    procStatus = new ProcessorStatus();
    procStatus.setProcessingNanos(123456789);
    procStatus.setInputCount(2);
    procStatus.setOutputCount(4);
    procStatus.setActiveThreadCount(6);
    procStatus.setBytesSent(1256);
    procStatus.setName("sampleProcessor");
    Collection<ProcessorStatus> processorStatuses = new ArrayList<>();
    processorStatuses.add(procStatus);
    rootGroupStatus.setProcessorStatus(processorStatuses);

    ProcessGroupStatus groupStatus = new ProcessGroupStatus();
    groupStatus.setProcessorStatus(processorStatuses);

    Collection<ProcessGroupStatus> groupStatuses = new ArrayList<>();
    groupStatuses.add(groupStatus);
    rootGroupStatus.setProcessGroupStatus(groupStatuses);
}
 
Example #2
Source File: StatusConfigReporter.java    From nifi-minifi with Apache License 2.0 6 votes vote down vote up
private static <E> Map<String, E> transformStatusCollection(Collection<E> statusCollection) {
    Map<String, E> statusMap = new HashMap<>();
    for (E status : statusCollection) {
        if (status instanceof ProcessorStatus) {
            statusMap.put(((ProcessorStatus) status).getId(), status);
            if (((ProcessorStatus) status).getName() != null) {
                statusMap.put(((ProcessorStatus) status).getName(), status);
            }
        } else if (status instanceof ConnectionStatus) {
            statusMap.put(((ConnectionStatus) status).getId(), status);
            if (((ConnectionStatus) status).getName() != null) {
                statusMap.put(((ConnectionStatus) status).getName(), status);
            }
        } else if (status instanceof RemoteProcessGroupStatus) {
            statusMap.put(((RemoteProcessGroupStatus) status).getId(), status);
            if (((RemoteProcessGroupStatus) status).getName() != null) {
                statusMap.put(((RemoteProcessGroupStatus) status).getName(), status);
            }
        }
    }
    return statusMap;
}
 
Example #3
Source File: ProcessorStatusEnumerator.java    From nifi with Apache License 2.0 6 votes vote down vote up
private ProcessorStatus getNextProcessorStatus() {
    if (processorStatusIterator != null && processorStatusIterator.hasNext()) {
        return processorStatusIterator.next();
    }
    // No more connections in this PG, so move to the next
    processorStatusIterator = null;
    Iterator<ProcessGroupStatus> i = iteratorBreadcrumb.peek();
    if (i == null) {
        return null;
    }

    if (i.hasNext()) {
        ProcessGroupStatus nextPG = i.next();
        iteratorBreadcrumb.push(nextPG.getProcessGroupStatus().iterator());
        processorStatusIterator = nextPG.getProcessorStatus().iterator();
        return getNextProcessorStatus();
    } else {
        // No more child PGs, remove it from the breadcrumb trail and try again
        iteratorBreadcrumb.pop();
        return getNextProcessorStatus();
    }
}
 
Example #4
Source File: TestDataDogReportingTask.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private void initProcessorStatuses() {
    procStatus = new ProcessorStatus();
    procStatus.setProcessingNanos(123456789);
    procStatus.setInputCount(2);
    procStatus.setOutputCount(4);
    procStatus.setActiveThreadCount(6);
    procStatus.setBytesSent(1256);
    procStatus.setName("sampleProcessor");
    Collection<ProcessorStatus> processorStatuses = new ArrayList<>();
    processorStatuses.add(procStatus);
    status.setProcessorStatus(processorStatuses);

    ProcessGroupStatus groupStatus = new ProcessGroupStatus();
    groupStatus.setProcessorStatus(processorStatuses);

    Collection<ProcessGroupStatus> groupStatuses = new ArrayList<>();
    groupStatuses.add(groupStatus);
    status.setProcessGroupStatus(groupStatuses);
}
 
Example #5
Source File: TestMetricsService.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetProcessGroupStatusMetrics() {
    ProcessorStatus procStatus = new ProcessorStatus();
    List<ProcessorStatus> processorStatuses = new ArrayList<>();
    processorStatuses.add(procStatus);
    status.setProcessorStatus(processorStatuses);

    final Map<String, Double> metrics = metricsService.getDataFlowMetrics(status);

    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_RECEIVED));
    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_SENT));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_SENT));
    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_QUEUED));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_QUEUED));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_READ));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_WRITTEN));
    Assert.assertTrue(metrics.containsKey(MetricNames.ACTIVE_THREADS));
}
 
Example #6
Source File: TestMetricsService.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetProcessGroupStatusMetrics() {
    ProcessorStatus procStatus = new ProcessorStatus();
    List<ProcessorStatus> processorStatuses = new ArrayList<>();
    processorStatuses.add(procStatus);
    status.setProcessorStatus(processorStatuses);

    final Map<String, Double> metrics = metricsService.getDataFlowMetrics(status);

    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_RECEIVED));
    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_SENT));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_SENT));
    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_QUEUED));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_QUEUED));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_READ));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_WRITTEN));
    Assert.assertTrue(metrics.containsKey(MetricNames.ACTIVE_THREADS));
}
 
Example #7
Source File: ControllerFacade.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the status for the specified processor.
 *
 * @param processorId processor id
 * @return the status for the specified processor
 */
public ProcessorStatus getProcessorStatus(final String processorId) {
    final ProcessGroup root = flowController.getGroup(flowController.getRootGroupId());
    final ProcessorNode processor = root.findProcessor(processorId);

    // ensure the processor was found
    if (processor == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate processor with id '%s'.", processorId));
    }

    // calculate the process group status
    final String groupId = processor.getProcessGroup().getIdentifier();
    final ProcessGroupStatus processGroupStatus = flowController.getGroupStatus(groupId, NiFiUserUtils.getNiFiUser());
    if (processGroupStatus == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId));
    }

    final ProcessorStatus status = processGroupStatus.getProcessorStatus().stream().filter(processorStatus -> processorId.equals(processorStatus.getId())).findFirst().orElse(null);
    if (status == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate processor with id '%s'.", processorId));
    }

    return status;
}
 
Example #8
Source File: TestDataDogReportingTask.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void initProcessorStatuses() {
    procStatus = new ProcessorStatus();
    procStatus.setProcessingNanos(123456789);
    procStatus.setInputCount(2);
    procStatus.setOutputCount(4);
    procStatus.setActiveThreadCount(6);
    procStatus.setBytesSent(1256);
    procStatus.setName("sampleProcessor");
    Collection<ProcessorStatus> processorStatuses = new ArrayList<>();
    processorStatuses.add(procStatus);
    status.setProcessorStatus(processorStatuses);

    ProcessGroupStatus groupStatus = new ProcessGroupStatus();
    groupStatus.setProcessorStatus(processorStatuses);

    Collection<ProcessGroupStatus> groupStatuses = new ArrayList<>();
    groupStatuses.add(groupStatus);
    status.setProcessGroupStatus(groupStatuses);
}
 
Example #9
Source File: TestNiFiFlowAnalyzer.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessorsWithinSinglePath() throws Exception {

    ProcessGroupStatus rootPG = createEmptyProcessGroupStatus();

    final ProcessorStatus pr0 = createProcessor(rootPG, "GenerateFlowFile");
    final ProcessorStatus pr1 = createProcessor(rootPG, "UpdateAttribute");

    connect(rootPG, pr0, pr1);

    final NiFiFlowAnalyzer analyzer = new NiFiFlowAnalyzer();

    final NiFiFlow nifiFlow = new NiFiFlow(rootPG.getId());
    analyzer.analyzeProcessGroup(nifiFlow, rootPG);

    assertEquals(2, nifiFlow.getProcessors().size());

    analyzer.analyzePaths(nifiFlow);
    final Map<String, NiFiFlowPath> paths = nifiFlow.getFlowPaths();

    assertEquals(1, paths.size());

    // Should be able to find a path from a given processor GUID.
    final NiFiFlowPath pathForPr0 = nifiFlow.findPath(pr0.getId());
    final NiFiFlowPath pathForPr1 = nifiFlow.findPath(pr1.getId());
    final NiFiFlowPath path0 = paths.get(pr0.getId());
    assertEquals(path0, pathForPr0);
    assertEquals(path0, pathForPr1);
}
 
Example #10
Source File: TestMetricsService.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetProcessorGroupStatusMetrics() {
    ProcessorStatus procStatus = new ProcessorStatus();
    List<ProcessorStatus> processorStatuses = new ArrayList<>();
    processorStatuses.add(procStatus);
    status.setProcessorStatus(processorStatuses);

    final Map<String, Double> metrics = metricsService.getProcessorMetrics(procStatus);

    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_READ));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_WRITTEN));
    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED));
    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_SENT));
    Assert.assertTrue(metrics.containsKey(MetricNames.ACTIVE_THREADS));
}
 
Example #11
Source File: TestMetricsService.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetProcessGroupStatusMetricsWithID() {
    ProcessGroupStatus status = new ProcessGroupStatus();
    String id = "1234";
    status.setId(id);
    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);

    // create a processor status with processing time
    ProcessorStatus procStatus = new ProcessorStatus();
    procStatus.setProcessingNanos(123456789);

    Collection<ProcessorStatus> processorStatuses = new ArrayList<>();
    processorStatuses.add(procStatus);
    status.setProcessorStatus(processorStatuses);

    // create a group status with processing time
    ProcessGroupStatus groupStatus = new ProcessGroupStatus();
    groupStatus.setProcessorStatus(processorStatuses);

    Collection<ProcessGroupStatus> groupStatuses = new ArrayList<>();
    groupStatuses.add(groupStatus);
    status.setProcessGroupStatus(groupStatuses);

    final MetricsService service = new MetricsService();

    final Map<String,String> metrics = service.getMetrics(status, true);

    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED + MetricNames.METRIC_NAME_SEPARATOR + id));
}
 
Example #12
Source File: TestDataDogReportingTask.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testOnTrigger() throws InitializationException, IOException {
    DataDogReportingTask dataDogReportingTask = new TestableDataDogReportingTask();
    dataDogReportingTask.initialize(initContext);
    dataDogReportingTask.setup(configurationContext);
    dataDogReportingTask.onTrigger(context);

    verify(metricsService, atLeast(1)).getProcessorMetrics(Mockito.<ProcessorStatus>any());
    verify(metricsService, atLeast(1)).getJVMMetrics(Mockito.<JmxJvmMetrics>any());
}
 
Example #13
Source File: MetricsService.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected long calculateProcessingNanos(final ProcessGroupStatus status) {
    long nanos = 0L;

    for (final ProcessorStatus procStats : status.getProcessorStatus()) {
        nanos += procStats.getProcessingNanos();
    }

    for (final ProcessGroupStatus childGroupStatus : status.getProcessGroupStatus()) {
        nanos += calculateProcessingNanos(childGroupStatus);
    }

    return nanos;
}
 
Example #14
Source File: MetricsService.java    From nifi with Apache License 2.0 5 votes vote down vote up
public Map<String, Double> getProcessorMetrics(ProcessorStatus status) {
    final Map<String, Double> metrics = new HashMap<>();
    metrics.put(MetricNames.FLOW_FILES_RECEIVED, new Double(status.getInputCount()));
    metrics.put(MetricNames.FLOW_FILES_SENT, new Double(status.getOutputCount()));
    metrics.put(MetricNames.BYTES_READ, new Double(status.getInputBytes()));
    metrics.put(MetricNames.BYTES_WRITTEN, new Double(status.getOutputBytes()));
    metrics.put(MetricNames.ACTIVE_THREADS, new Double(status.getActiveThreadCount()));
    metrics.put(MetricNames.TOTAL_TASK_DURATION, new Double(status.getProcessingNanos()));
    return metrics;
}
 
Example #15
Source File: TestAmbariReportingTask.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    status = new ProcessGroupStatus();
    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);

    // create a processor status with processing time
    ProcessorStatus procStatus = new ProcessorStatus();
    procStatus.setProcessingNanos(123456789);

    Collection<ProcessorStatus> processorStatuses = new ArrayList<>();
    processorStatuses.add(procStatus);
    status.setProcessorStatus(processorStatuses);

    // create a group status with processing time
    ProcessGroupStatus groupStatus = new ProcessGroupStatus();
    groupStatus.setProcessorStatus(processorStatuses);

    Collection<ProcessGroupStatus> groupStatuses = new ArrayList<>();
    groupStatuses.add(groupStatus);
    status.setProcessGroupStatus(groupStatuses);
}
 
Example #16
Source File: ControllerFacade.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the status for the specified processor.
 *
 * @param processorId processor id
 * @return the status for the specified processor
 */
public ProcessorStatus getProcessorStatus(final String processorId) {
    final ProcessorStatus status = flowController.getEventAccess().getProcessorStatus(processorId, NiFiUserUtils.getNiFiUser());
    if (status == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate processor with id '%s'.", processorId));
    }

    return status;
}
 
Example #17
Source File: StandardEventAccess.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessorStatus getProcessorStatus(final String processorId, final NiFiUser user) {
    final ProcessorNode procNode = flowController.getFlowManager().getProcessorNode(processorId);
    if (procNode == null) {
        return null;
    }

    FlowFileEvent flowFileEvent = flowFileEventRepository.reportTransferEvents(processorId, System.currentTimeMillis());
    if (flowFileEvent == null) {
        flowFileEvent = EmptyFlowFileEvent.INSTANCE;
    }

    final Predicate<Authorizable> authorizer = authorizable -> authorizable.isAuthorized(flowController.getAuthorizer(), RequestAction.READ, user);
    return getProcessorStatus(flowFileEvent, procNode, authorizer);
}
 
Example #18
Source File: FlowMetricSet.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Calculate the total processing time of a process group.
 *
 * @param status the current process group status.
 * @return the total amount of nanoseconds spent in each processor in the process group.
 */
private long calculateProcessingNanos(final ProcessGroupStatus status) {
    long nanos = 0L;

    for (final ProcessorStatus procStats : status.getProcessorStatus()) {
        nanos += procStats.getProcessingNanos();
    }

    for (final ProcessGroupStatus childGroupStatus : status.getProcessGroupStatus()) {
        nanos += calculateProcessingNanos(childGroupStatus);
    }

    return nanos;
}
 
Example #19
Source File: ProcessorStatusEnumerator.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public boolean moveNext() {
    currentRow = null;
    if (iteratorBreadcrumb.isEmpty()) {
        // Start the breadcrumb trail to follow recursively into process groups looking for connections
        ProcessGroupStatus rootStatus = context.getEventAccess().getControllerStatus();
        iteratorBreadcrumb.push(rootStatus.getProcessGroupStatus().iterator());
        processorStatusIterator = rootStatus.getProcessorStatus().iterator();
    }

    final ProcessorStatus connectionStatus = getNextProcessorStatus();
    if (connectionStatus == null) {
        // If we are out of data, close the InputStream. We do this because
        // Calcite does not necessarily call our close() method.
        close();
        try {
            onFinish();
        } catch (final Exception e) {
            logger.error("Failed to perform tasks when enumerator was finished", e);
        }

        return false;
    }

    currentRow = filterColumns(connectionStatus);

    recordsRead++;
    return true;
}
 
Example #20
Source File: TestNiFiFlowAnalyzer.java    From nifi with Apache License 2.0 5 votes vote down vote up
private ProcessorStatus createProcessor(ProcessGroupStatus pgStatus, String type) {
    final ProcessorStatus processor = new ProcessorStatus();
    processor.setName(type);
    processor.setId(nextComponentId());
    processor.setGroupId(pgStatus.getId());
    pgStatus.getProcessorStatus().add(processor);

    return  processor;
}
 
Example #21
Source File: ITReportLineageToAtlas.java    From nifi with Apache License 2.0 5 votes vote down vote up
public TemplateContentHander(String name) {
    rootPgStatus = new ProcessGroupStatus();
    rootPgStatus.setId(name);
    rootPgStatus.setName(name);
    pgStatus = rootPgStatus;
    current = rootPgStatus;
    pgStack.push(rootPgStatus);

    setters.put("id", idSetters);
    setters.put("name", nameSetters);

    idSetters.put(ProcessGroupStatus.class, s("processGroups",
            (o, id) -> ((ProcessGroupStatus) o).setId(id)));
    idSetters.put(ProcessorStatus.class, s("processors",
            (o, id) -> ((ProcessorStatus) o).setId(id)));

    idSetters.put(PortStatus.class, (o, id) -> ((PortStatus) o).setId(id));

    idSetters.put(ConnectionStatus.class, (o, id) -> {
        if (context.isConnectionSource) {
            ((ConnectionStatus) o).setSourceId(id);
        } else if (context.isConnectionDestination) {
            ((ConnectionStatus) o).setDestinationId(id);
        } else {
            ((ConnectionStatus) o).setId(id);
        }
    });

    nameSetters.put(ProcessGroupStatus.class, s("processGroups",
            (o, n) -> ((ProcessGroupStatus) o).setName(n)));

    nameSetters.put(ProcessorStatus.class, s("processors",
            (o, n) -> ((ProcessorStatus) o).setName(n)));

    nameSetters.put(PortStatus.class, (o, n) -> ((PortStatus) o).setName(n));

    nameSetters.put(ConnectionStatus.class, s("connections",
            (o, n) -> ((ConnectionStatus) o).setName(n)));
}
 
Example #22
Source File: StandardGangliaReporter.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private long calculateProcessingNanos(final ProcessGroupStatus status) {
    long nanos = 0L;

    for (final ProcessorStatus procStats : status.getProcessorStatus()) {
        nanos += procStats.getProcessingNanos();
    }

    for (final ProcessGroupStatus childGroupStatus : status.getProcessGroupStatus()) {
        nanos += calculateProcessingNanos(childGroupStatus);
    }

    return nanos;
}
 
Example #23
Source File: MetricsService.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected long calculateProcessingNanos(final ProcessGroupStatus status) {
    long nanos = 0L;

    for (final ProcessorStatus procStats : status.getProcessorStatus()) {
        nanos += procStats.getProcessingNanos();
    }

    for (final ProcessGroupStatus childGroupStatus : status.getProcessGroupStatus()) {
        nanos += calculateProcessingNanos(childGroupStatus);
    }

    return nanos;
}
 
Example #24
Source File: ComponentMetrics.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static StatusSnapshot createSnapshot(final ProcessorStatus status, final Date timestamp) {
    if (isEmpty(status)) {
        return null;
    }

    final StandardStatusSnapshot snapshot = new StandardStatusSnapshot(PROCESSOR_METRICS);
    snapshot.setTimestamp(timestamp);

    for (final ProcessorStatusDescriptor descriptor : ProcessorStatusDescriptor.values()) {
        snapshot.addStatusMetric(descriptor.getDescriptor(), descriptor.getDescriptor().getValueFunction().getValue(status));
    }

    final Map<String, Long> counters = status.getCounters();
    if (counters != null) {
        for (final Map.Entry<String, Long> entry : counters.entrySet()) {
            final String counterName = entry.getKey();

            final String label = entry.getKey() + " (5 mins)";
            final MetricDescriptor<ProcessorStatus> metricDescriptor = new CounterMetricDescriptor<>(entry.getKey(), label, label, MetricDescriptor.Formatter.COUNT,
                    s -> s.getCounters() == null ? null : s.getCounters().get(counterName));

            snapshot.addStatusMetric(metricDescriptor, entry.getValue());
        }
    }

    return snapshot;
}
 
Example #25
Source File: TestSiteToSiteStatusReportingTask.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static ProcessorStatus generateProcessorStatus(String id, String namePrefix) {
    ProcessorStatus pStatus = new ProcessorStatus();
    pStatus.setId(id);
    pStatus.setName(namePrefix + "-" + UUID.randomUUID().toString());
    pStatus.setActiveThreadCount(0);
    pStatus.setAverageLineageDuration(1l);
    pStatus.setBytesRead(2l);
    pStatus.setBytesReceived(3l);
    pStatus.setBytesSent(4l);
    pStatus.setBytesWritten(5l);
    pStatus.setFlowFilesReceived(6);
    pStatus.setFlowFilesRemoved(7);
    pStatus.setFlowFilesSent(8);
    pStatus.setInputBytes(9l);
    pStatus.setInputCount(10);
    pStatus.setInvocations(11);
    pStatus.setOutputBytes(12l);
    pStatus.setOutputCount(13);
    pStatus.setProcessingNanos(14l);
    pStatus.setType(null);
    pStatus.setTerminatedThreadCount(1);
    pStatus.setRunStatus(RunStatus.Running);
    pStatus.setCounters(new HashMap<String, Long>() {{
        put("counter1", 10L);
        put("counter2", 5L);
    }});

    return pStatus;
}
 
Example #26
Source File: TestSiteToSiteMetricsReportingTask.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    status = new ProcessGroupStatus();
    status.setId("1234");
    status.setFlowFilesReceived(5);
    status.setBytesReceived(10000);
    status.setFlowFilesSent(10);
    status.setBytesSent(20000);
    status.setQueuedCount(100);
    status.setQueuedContentSize(1024L);
    status.setBytesRead(null);
    status.setBytesWritten(80000L);
    status.setActiveThreadCount(5);

    // create a processor status with processing time
    ProcessorStatus procStatus = new ProcessorStatus();
    procStatus.setProcessingNanos(123456789);

    Collection<ProcessorStatus> processorStatuses = new ArrayList<>();
    processorStatuses.add(procStatus);
    status.setProcessorStatus(processorStatuses);

    // create a group status with processing time
    ProcessGroupStatus groupStatus = new ProcessGroupStatus();
    groupStatus.setProcessorStatus(processorStatuses);

    Collection<ProcessGroupStatus> groupStatuses = new ArrayList<>();
    groupStatuses.add(groupStatus);
    status.setProcessGroupStatus(groupStatuses);
}
 
Example #27
Source File: SiteToSiteStatusReportingTask.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void serializeProcessorStatus(final JsonArrayBuilder arrayBuilder, final JsonBuilderFactory factory, final ProcessorStatus status, final DateFormat df,
        final String hostname, final String applicationName, final String platform, final ProcessGroupStatus parent, final Date currentDate, final Boolean allowNullValues) {
    final JsonObjectBuilder builder = factory.createObjectBuilder();
    final String componentType = "Processor";
    final String componentName = status.getName();

    if (componentMatchesFilters(componentType, componentName)) {
        addCommonFields(builder, df, hostname, applicationName, platform, parent, currentDate, componentType, componentName, allowNullValues);

        addField(builder, "componentId", status.getId(), allowNullValues);
        addField(builder, "processorType", status.getType(), allowNullValues);
        addField(builder, "averageLineageDurationMS", status.getAverageLineageDuration(), allowNullValues);
        addField(builder, "bytesRead", status.getBytesRead(), allowNullValues);
        addField(builder, "bytesWritten", status.getBytesWritten(), allowNullValues);
        addField(builder, "bytesReceived", status.getBytesReceived(), allowNullValues);
        addField(builder, "bytesSent", status.getBytesSent(), allowNullValues);
        addField(builder, "flowFilesRemoved", status.getFlowFilesRemoved(), allowNullValues);
        addField(builder, "flowFilesReceived", status.getFlowFilesReceived(), allowNullValues);
        addField(builder, "flowFilesSent", status.getFlowFilesSent(), allowNullValues);
        addField(builder, "inputCount", status.getInputCount(), allowNullValues);
        addField(builder, "inputBytes", status.getInputBytes(), allowNullValues);
        addField(builder, "outputCount", status.getOutputCount(), allowNullValues);
        addField(builder, "outputBytes", status.getOutputBytes(), allowNullValues);
        addField(builder, "activeThreadCount", status.getActiveThreadCount(), allowNullValues);
        addField(builder, "terminatedThreadCount", status.getTerminatedThreadCount(), allowNullValues);
        addField(builder, "invocations", status.getInvocations(), allowNullValues);
        addField(builder, "processingNanos", status.getProcessingNanos(), allowNullValues);
        addField(builder, "runStatus", status.getRunStatus() == null ? null : status.getRunStatus().name(), allowNullValues);
        addField(builder, "executionNode", status.getExecutionNode() == null ? null : status.getExecutionNode().name(), allowNullValues);
        addField(builder, factory, "counters", status.getCounters(), allowNullValues);

        arrayBuilder.add(builder.build());
    }
}
 
Example #28
Source File: TestMetricsFactory.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetDataFlowMetrics() {
    ProcessorStatus procStatus = new ProcessorStatus();
    List<ProcessorStatus> processorStatuses = new ArrayList<>();
    processorStatuses.add(procStatus);
    status.setProcessorStatus(processorStatuses);

    List<Metric> metrics = AzureLogAnalyticsMetricsFactory.getDataFlowMetrics(status, "testcase");
    TestVerification.assertDatatFlowMetrics(metrics);
}
 
Example #29
Source File: ComponentMetrics.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static boolean isEmpty(final ProcessorStatus status) {
    for (final ProcessorStatusDescriptor descriptor : ProcessorStatusDescriptor.values()) {
        if (descriptor.isVisible()) {
            final Long value = descriptor.getDescriptor().getValueFunction().getValue(status);
            if (value != null && value > 0) {
                return false;
            }
        }
    }

    return true;
}
 
Example #30
Source File: StandardGangliaReporter.java    From nifi with Apache License 2.0 5 votes vote down vote up
private long calculateProcessingNanos(final ProcessGroupStatus status) {
    long nanos = 0L;

    for (final ProcessorStatus procStats : status.getProcessorStatus()) {
        nanos += procStats.getProcessingNanos();
    }

    for (final ProcessGroupStatus childGroupStatus : status.getProcessGroupStatus()) {
        nanos += calculateProcessingNanos(childGroupStatus);
    }

    return nanos;
}