SQL Reporting Task for Cloudera Flow Management / HDF / Apache NiFi
Tags: apachenifi111, cloudera, hdf350
Published: 2020-04-08 21:23:43

---
title: SQL Reporting Task for Cloudera Flow Management / HDF / Apache NiFi
published: true
date: 2020-04-08 20:46:00 UTC
tags: apache-nifi-1.11,cloudera,hdf3.5.0
canonical_url: 
---

## SQL Reporting Task for Cloudera Flow Management / HDF / Apache NiFi
Would you like to have reporting tasks gathering metrics and sending them to your database or Kafka from NiFi based on a query of NiFi provenance, bulletins, metrics, processor status or other KPI?  
  
Now you can.   If you are using HDF 3.5.0, this Reporting task NAR is pre installed and ready to go.  
  
Let's add some Reporting tasks that use SQL!!!  **QueryNiFiReportingTask.**  
  
[![](https://1.bp.blogspot.com/-hbyISWfExCA/Xo40BCQ3e9I/AAAAAAAAZpE/Zv7EFPyIuMYmZalWOnUrMogE1NdCxy0xwCLcBGAsYHQ/s640/docs.png)](https://1.bp.blogspot.com/-hbyISWfExCA/Xo40BCQ3e9I/AAAAAAAAZpE/Zv7EFPyIuMYmZalWOnUrMogE1NdCxy0xwCLcBGAsYHQ/s1600/docs.png)  
  
The first one that was interesting for me was to write queries against provenance for one processor that consumes from a certain topic, I decided to query it every 10 seconds.   My query and some results are below.  
  
So let's go to **Controller Settings / Reporting Tasks** and then add **QueryNiFiReportingTask** :  
  

[![](https://1.bp.blogspot.com/-4CTUeOWzzw4/Xo4z_hQ-92I/AAAAAAAAZow/avLjE5yxbLoQtsywG7uRL2NbR_O7oClBACLcBGAsYHQ/s640/addreportingtask.png)](https://1.bp.blogspot.com/-4CTUeOWzzw4/Xo4z_hQ-92I/AAAAAAAAZow/avLjE5yxbLoQtsywG7uRL2NbR_O7oClBACLcBGAsYHQ/s1600/addreportingtask.png)

  

We add one per item we want to monitor.   Then for the reporting task we will need a place to send the records (a sink), we can send it to a JDBC Database ( **DatabaseRecordSink, KafkaRecordSink, PrometheusRecordSink, ScriptedRecordSink or SiteToSiteReportingRecordSink** ). **   ** I am going to do Kafka, but Prometheus, Database and S2S are good options.   If you send SiteToSite you can send to another NiFi cluster for processing for that NiFinception processing route,
  

[![](https://1.bp.blogspot.com/-SYltkjWls-s/Xo4z_g8nD8I/AAAAAAAAZo0/KxMXOzN1rGQC0hPj2e7XOefUg2Q4EOVBACLcBGAsYHQ/s640/AddReportingTaskSink.png)](https://1.bp.blogspot.com/-SYltkjWls-s/Xo4z_g8nD8I/AAAAAAAAZo0/KxMXOzN1rGQC0hPj2e7XOefUg2Q4EOVBACLcBGAsYHQ/s1600/AddReportingTaskSink.png)

  

We have to write an Apache Calcite compliant SQL query, set our sink and decide if we want to include zero record results (false is a good idea).
  

[![](https://1.bp.blogspot.com/-ZOTkENEpr2I/Xo4z_xTsFgI/AAAAAAAAZo4/EIE4Yy5f88EF_QvLecMLu2RDgciDWGY8ACLcBGAsYHQ/s640/buildYourQueryReportingTask.png)](https://1.bp.blogspot.com/-ZOTkENEpr2I/Xo4z_xTsFgI/AAAAAAAAZo4/EIE4Yy5f88EF_QvLecMLu2RDgciDWGY8ACLcBGAsYHQ/s1600/buildYourQueryReportingTask.png)

  

  

One option is to query the **BULLETINS** table, which are NiFi Cluster bulletins (warnings/errors).
  

[![](https://1.bp.blogspot.com/-CzVEUQUhjDY/Xo40APL4IBI/AAAAAAAAZo8/XPdYHt0s6GYjfM7PcGB2dJaTu1TqUty0QCLcBGAsYHQ/s640/bulletins.png)](https://1.bp.blogspot.com/-CzVEUQUhjDY/Xo40APL4IBI/AAAAAAAAZo8/XPdYHt0s6GYjfM7PcGB2dJaTu1TqUty0QCLcBGAsYHQ/s1600/bulletins.png)

  

Another option is the **CONNECTION\_STATUS** table.
  

[![](https://1.bp.blogspot.com/-nxQDaGfOB4o/Xo40Ae2169I/AAAAAAAAZpA/YHCKckqdMxQh2DBgAK4uwHHwoTMjXoqygCLcBGAsYHQ/s640/connectionStatus.png)](https://1.bp.blogspot.com/-nxQDaGfOB4o/Xo40Ae2169I/AAAAAAAAZpA/YHCKckqdMxQh2DBgAK4uwHHwoTMjXoqygCLcBGAsYHQ/s1600/connectionStatus.png)

  

  

  

How about NiFi **JVM Metrics?**   That has some good stuff in there.
  

[![](https://1.bp.blogspot.com/-30KT517NntI/Xo40Bmvm6yI/AAAAAAAAZpI/oaulcKZkOUgVDApB6PZsDeknKbVLUQf9QCLcBGAsYHQ/s640/jvmmetrics.png)](https://1.bp.blogspot.com/-30KT517NntI/Xo40Bmvm6yI/AAAAAAAAZpI/oaulcKZkOUgVDApB6PZsDeknKbVLUQf9QCLcBGAsYHQ/s1600/jvmmetrics.png)

  

  

Let's configure some Kafka Record Sinks.  I am using Kafka 2.3, so I'll use the Kafka 2 sink.   I set some brokers (default port of 9092), create a new topic for it, chose the record writer.  I chose JSON, but it could be CSV, AVRO, Parquet, XML or something else.   Stick with JSON or AVRO for Kafka.
  

[![](https://1.bp.blogspot.com/-6bLYrda3vfI/Xo40CI7ZPEI/AAAAAAAAZpM/4vpm_kzNOK0MuWUn_tbnBXz1Tpp3eUmXwCLcBGAsYHQ/s640/kafkarecordsink.png)](https://1.bp.blogspot.com/-6bLYrda3vfI/Xo40CI7ZPEI/AAAAAAAAZpM/4vpm_kzNOK0MuWUn_tbnBXz1Tpp3eUmXwCLcBGAsYHQ/s1600/kafkarecordsink.png)

  

So data starts getting sent, by default the schedule is every 5 minutes.   This can be adjusted, for provenance I set mine to every 10 seconds.

  

 [![](https://1.bp.blogspot.com/-fEm9BA1G6hY/Xo40FrHF56I/AAAAAAAAZpo/pIzbwPwR8lIBYfE_yKaK9a6XqcPXE1V1QCLcBGAsYHQ/s640/reportingtasklist.png)](https://1.bp.blogspot.com/-fEm9BA1G6hY/Xo40FrHF56I/AAAAAAAAZpo/pIzbwPwR8lIBYfE_yKaK9a6XqcPXE1V1QCLcBGAsYHQ/s1600/reportingtasklist.png)  
  
Let's look at data as it passes through Kafka, in the follow up to this article we'll land in Impala/Kudu/Hive/Druid/Phoenix/HBase or HDFS/S3 and query it.   For now, we can examine the data within Kafka via Cloudera Streams Messaging Manager (SMM).  
  

[![](https://1.bp.blogspot.com/-3E4a9EZlojY/Xo40Clat6HI/AAAAAAAAZpQ/pIo3g9SkZ_IdMsbsjQGrKqNQ7jU-FLqhACLcBGAsYHQ/s640/nifibulletinssmm.png)](https://1.bp.blogspot.com/-3E4a9EZlojY/Xo40Clat6HI/AAAAAAAAZpQ/pIo3g9SkZ_IdMsbsjQGrKqNQ7jU-FLqhACLcBGAsYHQ/s1600/nifibulletinssmm.png)
  

[![](https://1.bp.blogspot.com/--pqIyf7gfB4/Xo40DO6exLI/AAAAAAAAZpU/zq7d2l75JL8jnTPP0SQJYs1V2-tGH6rCQCLcBGAsYHQ/s640/nificonnectionstatus.png)](https://1.bp.blogspot.com/--pqIyf7gfB4/Xo40DO6exLI/AAAAAAAAZpU/zq7d2l75JL8jnTPP0SQJYs1V2-tGH6rCQCLcBGAsYHQ/s1600/nificonnectionstatus.png)
  

[![](https://1.bp.blogspot.com/-lFt97NGNRtA/Xo40Ds3wOuI/AAAAAAAAZpY/RS2xa_3ReLwTCHGmgnf4YNsITZPYIxKGgCLcBGAsYHQ/s640/nifijvmmetricskafkamessage.png)](https://1.bp.blogspot.com/-lFt97NGNRtA/Xo40Ds3wOuI/AAAAAAAAZpY/RS2xa_3ReLwTCHGmgnf4YNsITZPYIxKGgCLcBGAsYHQ/s1600/nifijvmmetricskafkamessage.png)
  

[![](https://1.bp.blogspot.com/-tOdpEj-3dGQ/Xo40EKiQGkI/AAAAAAAAZpc/GMyHQrZp1YIRO7cSN_ZFoi87b96TJt4qwCLcBGAsYHQ/s640/nifiprocessgroupssmm.png)](https://1.bp.blogspot.com/-tOdpEj-3dGQ/Xo40EKiQGkI/AAAAAAAAZpc/GMyHQrZp1YIRO7cSN_ZFoi87b96TJt4qwCLcBGAsYHQ/s1600/nifiprocessgroupssmm.png)
  

[![](https://1.bp.blogspot.com/-8ZJyWrRqRhU/Xo40EhXNlgI/AAAAAAAAZpg/X8GmIgX_BU87_o8VJ0Uhu8rpp9ly4WqMACLcBGAsYHQ/s640/nifiprocessorstatuskafkasmm.png)](https://1.bp.blogspot.com/-8ZJyWrRqRhU/Xo40EhXNlgI/AAAAAAAAZpg/X8GmIgX_BU87_o8VJ0Uhu8rpp9ly4WqMACLcBGAsYHQ/s1600/nifiprocessorstatuskafkasmm.png)
  

[![](https://1.bp.blogspot.com/-vhi-rrFlGEg/Xo40FGvKnrI/AAAAAAAAZpk/1IOFvBVR7HkKhgHE3VqvNh-TFcaQpmVWQCLcBGAsYHQ/s640/processgroupstats.png)](https://1.bp.blogspot.com/-vhi-rrFlGEg/Xo40FGvKnrI/AAAAAAAAZpk/1IOFvBVR7HkKhgHE3VqvNh-TFcaQpmVWQCLcBGAsYHQ/s1600/processgroupstats.png)
  

We can examine any of the topics in Kafka with SMM.   We can then start consuming these records and build live metric handling applications or send to live data marts and dashboards powered by Cloudera Data Platform ([CDP](https://www.cloudera.com/products/cloudera-data-platform.html)).
  

[![](https://1.bp.blogspot.com/-MdpuGGxdZ5U/Xo40GBedG6I/AAAAAAAAZps/VA2fT9eQMqQovkENH7UQZhyrmoSAyftTwCLcBGAsYHQ/s640/smmmetricstopics.png)](https://1.bp.blogspot.com/-MdpuGGxdZ5U/Xo40GBedG6I/AAAAAAAAZps/VA2fT9eQMqQovkENH7UQZhyrmoSAyftTwCLcBGAsYHQ/s1600/smmmetricstopics.png)

  

We have a full set of SQL to use for these reporting tasks including selecting columns, doing aggregates like MAX and AVG, ordering, grouping, where clauses and row limits.
  

[![](https://1.bp.blogspot.com/-Z5qdLdEDdsw/Xo40GmHTkcI/AAAAAAAAZpw/nDiGRYBGNKY4OjnS2WdNCt2eXm4JlyEHQCLcBGAsYHQ/s640/sqlquery.png)](https://1.bp.blogspot.com/-Z5qdLdEDdsw/Xo40GmHTkcI/AAAAAAAAZpw/nDiGRYBGNKY4OjnS2WdNCt2eXm4JlyEHQCLcBGAsYHQ/s1600/sqlquery.png)
  
  
**Provenance Query**  
  

> SELECT eventId, durationMillis, lineageStart, timestampMillis,  
> updatedAttributes, entitySize, details  
> FROM PROVENANCE  
> WHERE componentName = 'Consume Kafka iot messages'  
> LIMIT 25

  

**Provenance Results**  
  
  

> [{" **eventId**":2724," **durationMillis**":69," **lineageStart**":1586294707989," **timestampMillis**":1586294708002," **updatedAttributes**":"{path=./, schema.protocol.version=1, filename=be499074-c595-46f5-a03a-482607fb9c8c, schema.identifier=1, **kafka**. **partition** =7, **kafka**. **offset** =36, **schema**. **name** =SensorReading, **kafka**. **timestamp** =1586294707933, **kafka**. **topic** =iot, schema.version=1, **mime**. **type** =application/json, uuid=be499074-c595-46f5-a03a-482607fb9c8c}"," **entitySize**":246,"details":null},{"eventId":2736,"durationMillis":20,"lineageStart":1586294708905,"timestampMillis":1586294708916,"updatedAttributes":"{path=./, schema.protocol.version=1, filename=74c9e28d-82a4-4cea-8331-92b7a4bee1b3, schema.identifier=1, kafka.partition=3, kafka.offset=36, schema.name=SensorReading, kafka.timestamp=1586294708898, kafka.topic=iot, schema.version=1, mime.type=application/json, uuid=74c9e28d-82a4-4cea-8331-92b7a4bee1b3}","entitySize":247,"details":null},..]

  
I have classes on using this technology and some webinars coming to you in the East Coast of the US and virtually at my meetup.  
  
[https://www.meetup.com/futureofdata-princeton/](https://www.meetup.com/futureofdata-princeton/)  
  
**Cloudera HDF 3.5.0 Is Now Available For Download**  
  
[https://docs.cloudera.com/HDPDocuments/HDF3/HDF-3.5.0/release-notes/content/whats-new.html](https://docs.cloudera.com/HDPDocuments/HDF3/HDF-3.5.0/release-notes/content/whats-new.html)  
  
[https://www.cloudera.com/downloads/hdf.html](https://www.cloudera.com/downloads/hdf.html)  
  

HDF 3.5.0 includes the following components:

- 
Apache Ambari 2.7.5
- 
Apache Kafka 2.3.1
- 
Apache NiFi 1.11.1
- 
NiFi Registry 0.5.0
- 
Apache Ranger 1.2.0
- 
Apache Storm 1.2.1
- 
Apache ZooKeeper 3.4.6
- 
Apache MiNiFi Java Agent 0.6.0
- 
Apache MiNiFi C++ 0.6.0
- 
Hortonworks Schema Registry 0.8.1
- 
Hortonworks Streaming Analytics Manager 0.6.0
- Apache Knox 1.0.0
- SmartSense 1.5.0

  

SQL reporting task. The **QueryNiFiReportingTask** allows users to execute SQL queries against tables containing information on Connection Status, Processor Status, Bulletins, Process Group Status, JVM Metrics, Provenance and Connection Status Predictions. In combination with Site to Site, it is particularly useful to define fine-grained monitoring capabilities on top of the running workflows.