Deploy with Custom UDF#
This guide provides instructions for setting up a custom UDF deployment package (UDFs, TICKscripts, models) and config.json in Time Series Analytics Microservice.
Configuration#
config.json:Review the configuration reference and update it as needed for your custom UDF deployment package.
UDF Deployment Package:udfs/:Contains Python scripts for UDFs.
If additional Python packages are required, list them in
requirements.txtusing pinned versions.For detailed instructions on writing UDFs, see the How to Write a UDF guide.
tick_scripts/:Contains TICKscripts for data processing, analytics, and alerts.
More details on writing TICKscripts are available at https://docs.influxdata.com/kapacitor/v1/reference/tick/introduction/
Example TICKscript:
dbrp "datain"."autogen" var data0 = stream |from() .database('datain') .retentionPolicy('autogen') .measurement('opcua') @windturbine_anomaly_detector() |alert() .crit(lambda: "anomaly_status" > 0) .message('Anomaly detected: Wind Speed: {{ index .Fields "wind_speed" }}, Grid Active Power: {{ index .Fields "grid_active_power" }}, Anomaly Status: {{ index .Fields "anomaly_status" }}') .mqtt('my_mqtt_broker') .topic('alerts/wind_turbine') .qos(1) |log() .level('INFO') |influxDBOut() .buffer(0) .database('datain') .measurement('opcua') .retentionPolicy('autogen')
Key sections:
Input: Fetch data from Telegraf (stream).
Processing: Apply UDFs for analytics.
Alerts: Configuration for publishing alerts (e.g., MQTT). Refer to the document
Logging: Set log levels (
INFO,DEBUG,WARN,ERROR).Output: Publish processed data.
For more details, refer to the Kapacitor TICK Script Documentation.
models/:Contains model files (e.g.,
.pkl) used by UDF Python scripts.
Docker Compose Deployment#
Note
Follow the Get started guide to deploy the Wind Turbine Anomaly Detection sample app.
The UDF deployment package (UDFs, TICKscripts, models) and config.json for each sample app are uploaded into the Time Series Analytics Microservice container via manufacturing-ai-suite/industrial-edge-insights-time-series/Makefile:
Wind Turbine Anomaly Detection:
manufacturing-ai-suite/industrial-edge-insights-time-series/apps/wind-turbine-anomaly-detection/time-series-analytics-config
To apply changes to the UDF deployment package or config.json, update the files at the relevant path above, then follow the steps below to upload the updated package:
Create the UDF deployment package tar file:
export SAMPLE_APP="<wind-turbine-anomaly-detection>" # Navigate to the directory containing your UDF deployment package files cd industrial-edge-insights-time-series/apps/${SAMPLE_APP}/time-series-analytics-config/ rm -f ${SAMPLE_APP}.tar tar cf ${SAMPLE_APP}.tar models/ tick_scripts/ udfs/
Upload the UDF deployment package to the Time Series Analytics Microservice:
curl -X POST https://127.0.0.1:3000/ts-api/udfs/package -F "file=@${SAMPLE_APP}.tar" -k
Upload the
config.jsonto activate the custom UDF:curl -s -X POST https://127.0.0.1:3000/ts-api/config \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d @config.json \ -k
For more details, refer to the Time Series Analytics Microservice API documentation on updating the config.