Peter, GitHub
Active open source contributor
Speaker
COSCUP, MOPCON and so on
An Senior Engineer
DevOps
Back-end
System Architecture Researching
Web Application Security
PHP, Python and JavaScript
Industrial Technology Research Institute
Smart Grid Technology (2017~2021)
Institute for Information Industry
Database, Data platform architecture (2021~)
Tricky requirements. E.g. Using ICMP ping to collect network metric.
| Processor Name | Pros | Cons |
|---|---|---|
| ExecuteStreamCommand | Universal programming language | Performance |
| ExecuteGroovyScript | Easy and running script in JVM | Version Control Issue |
| Python Processor (NiFi 2.0+) | Completed CPython Support | Customized NiFi Image |
FROM apache/nifi:2.8.0
USER root
RUN apt-get update && \
apt-get -y install iputils-ping python3 python3-pip && \
PIP_BREAK_SYSTEM_PACKAGES=1 pip3 install pymongo pandas
USER nifi#####################
# Python Extensions #
#####################
# Uncomment in order to enable Python Extensions.
nifi.python.command=python3
nifi.python.framework.source.directory=./python/framework
nifi.python.extensions.source.directory.default=/opt/nifi/nifi-current/python_extensions
nifi.python.working.directory=./work/python
nifi.python.max.processes=100
nifi.python.max.processes.per.extension.type=1Create the PingHost.py (FlowFileSource V.S. FlowFileTransform)
docker compose cp PingHost.py nifi:/opt/nifi/nifi-current/python_extensions
import re
import json
import platform
import subprocess
from datetime import datetime, timezone
from nifiapi.flowfiletransform import FlowFileTransform, FlowFileTransformResult
from nifiapi.properties import PropertyDescriptor, StandardValidators, ExpressionLanguageScope
class PingHost(FlowFileTransform):
# ↓↓↓ 關鍵:必須是 FlowFileTransform,不能是 FlowFileSource ↓↓↓
class Java:
implements = ['org.apache.nifi.python.processor.FlowFileTransform']
class ProcessorDetails:
version = '0.0.2-SNAPSHOT'
description = '讀取 FlowFile 屬性中的 IP 與 ping 次數,執行 ping 後將結果以 JSON 輸出。'
tags = ['ping', 'network', 'icmp', 'monitoring', 'python']
dependencies = []
........docker compose cp PingHost.py nifi:/opt/nifi/nifi-current/python_extensions
docker compose exec nifi ls /opt/nifi/nifi-current/work/python/extensions/PingHost/
NiFi will update and load new Python Processor under runtime
'Processor' is invalid because initializing runtime environment for the Processor.
docker compose exec nifi cat /opt/nifi/nifi-current/logs/nifi-app.log | grep PingHost -A5
File "/opt/nifi/nifi-current/python_extensions/PingHost.py", line 33, in __init__
name='Ping Count',
TypeError: FlowFileTransform.__init__() got an unexpected keyword argument 'jvm'
2026-08-06 16:00:36,020 ERROR [Initialize Python Processor d799e116-019f-1000-ffff-ffff89e658e6 (PingHost)] o.a.n.py4j.StandardPythonProcessorBridge Failed to load code for Python Processor d799e116-019f-1000-ffff-ffff89e658e6 (PingHost). Will try again in 600000 millis
py4j.Py4JException: An exception was raised by the Python Proxy. Return Message: Traceback (most recent call last):
File "/opt/nifi/nifi-current/python/framework/py4j/java_gateway.py", line 2506, in _call_proxy
return_value = getattr(self.pool[obj_id], method)(*params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nifi/nifi-current/./python/framework/Controller.py", line 72, in createProcessordocker compose cp postgresql-42.7.13.jar nifi:/opt/nifi/nifi-current/
Configuring Controller Service
Database Driver Class Name: org.postgresql.Driver
jdbc:postgresql://<host>:<port>/<database_name>
Database Driver Locations
CREATE TABLE ping_results (
id BIGSERIAL PRIMARY KEY,
target VARCHAR(255) NOT NULL,
reachable BOOLEAN NOT NULL,
packet_loss_percent NUMERIC(5,2),
rtt_min_ms NUMERIC(10,3),
rtt_avg_ms NUMERIC(10,3),
rtt_max_ms NUMERIC(10,3),
ping_count INTEGER,
checked_at TIMESTAMPTZ
);
CREATE INDEX idx_ping_results_target ON ping_results (target);
CREATE INDEX idx_ping_results_checked_at ON ping_results (checked_at);Recorder Reader, DatabaseType, StatementType, Specific Controller and Table Name
Enabling JsonTreeReader Service and Database Connection Pooling Service
Replace the PingHost Processor with ExecuteGroovyScript or ExecuteScript
docker compose cp PingHost.groovy nifi:/opt/nifi/nifi-current
| Processor Name | Pros | Cons |
|---|---|---|
| ExecuteGroovyScript | Easy and running script in JVM | Version Control Issue |
| Python Processor (NiFi 2.0+) | Completed CPython Support | High Trouble Shooting |
Using the InvokeHTTP to retrieve data firstly.
Using the ConsumeAMQP, ConsumeMQTT or ConsumeKafka to retrieve data firstly.
| Retrieving Data Type | Pros | Cons |
|---|---|---|
| Active (polling or schedule) | Polling and schedule | Scaling and CPU usage |
| Passive (event-driven, IoT) | Throughput and low latency | Mainatining the Broker |
Using the Claude, Gemini or ChatGPT via the web browser to send the prompt
使用Generateflowfile初始化IP位址與ping次數,例如:10.41.0.227
執行前述的Python Processor,嘗試ping後的取得結果
將結果儲存至PostgreSQL
Using the Claude example
Advanced: Using the Claude Desktop or Antigravity
Modify/Create the NiFi Datapipelines automatically.
What about calculating hardware metrics and send alert?
Are these processes suitable for integration into a NiFi data pipelines?
It's up to complex logic or process
It's up to the requirements or scenarios.
It's up to the collecting data mechanism or process.
It should consider using the NiFi to develop IoT Architecture to collect sensor data.
The routine data collecting progress.
The routine and event-driven data collecting progress.