Extend Analytics Builder with custom blocks

Cumulocity offers real-time analytics through its no-code Analytics Builder. It includes several prebuilt, out-of-the-box blocks that allow you to design analytics models using a simple drag-and-drop interface. However, in cases where your specific logic is not supported by the existing blocks, Cumulocity enables you to extend Analytics Builder by creating your own custom blocks.

This article explains the different ways of developing custom Analytics Builder blocks.

Prerequisites

  • :white_check_mark: A Cumulocity tenant with Streaming Analytics service subscribed

  • :white_check_mark: A laptop with Docker installed (latest version)

  • :white_check_mark: Visual Studio Code IDE

  • :white_check_mark: Understanding of Apama EPL, Python, and JavaScript

  • :white_check_mark: Clone your Streaming Analytics app and install this community plugin - Analytics Builder Management that will help manage your custom blocks using a user-friendly interface

Custom Block Development

  1. Clone this Git repository into a folder - Cumulocity Analytics Builder Block

  2. Open VS Code and create a dev container using the folder where the above repository has been cloned
    image

  3. Create a folder with any name (e.g., custom_blocks) and a subfolder within that folder with your block name (e.g., NormBlock)

  4. Add either an EPL monitor file (NormBlock.mon), a Python monitor file, or a Smart Function monitor file with your custom logic

    NormBlock.mon

     package apamax.analyticsbuilder.samples;
     using apama.analyticsbuilder.BlockBase;
     using com.apama.cumulocity.TenantDetails;
     using com.softwareag.connectivity.ExtraFieldsDict;
     using com.softwareag.connectivity.Chain;
     using com.softwareag.connectivity.ConnectivityPlugins;
     using com.apama.exceptions.Exception;
     using com.apama.cumulocity.devices.DeviceService;
     using com.apama.cumulocity.devices.DevicePublisher;
     using com.apama.cumulocity.devices.DeviceMessage;
     using apama.analyticsbuilder.InputParams;
     using apama.analyticsbuilder.InputHandler;
     using apama.analyticsbuilder.Value;
     using apama.analyticsbuilder.Activation;
     
     /** NormBlock
     
       Calculate the root square.
     
       @$blockCategory Calculations
     **/
     event NormBlock {    
         BlockBase $base;
         
         action $process(Activation $activation, float $input_x, float $input_y, optional<float> $input_z) {
         float result := ($input_x * $input_x + $input_y * $input_y).sqrt();
            $setOutput_output($activation, result);
         }
         
         action<Activation, float> $setOutput_output;
     }
    

    Reference Examples:

Build Your Custom Block

Run this command:

/apama-analytics-builder-block-sdk/analytics_builder build extension --input <directory of your custom block> --output <File Name of your custom block>

/apama-analytics-builder-block-sdk/analytics_builder build extension --input ./blocks/custom_block/NormBlock --output ./NormBlock.zip

/apama-analytics-builder-block-sdk/analytics_builder build extension --input ./blocks/custom_block/SmartFunction/ --output ./SmartFunction.zip

image

Deploy Your Custom Block

Option 1: Command Line Deployment

Run the below command to deploy your custom block:

analytics_builder upload extension --input NormBlock.zip --cumulocity_url https://lora-sandbox.eu-latest.cumulocity.com --username <Your tenant User Name> --password <password> --restart --ignoreVersion

Option 2: UI-Based Deployment

  1. Use the built “NormBlock.zip” file and follow these steps in your custom Streaming Analytics application where the Analytics Builder Management plugin is installed.

  2. Download the ZIP file using the Docker command below:

    docker cp ba1094f67c31:/workspaces/c8y-analytics-blocks/NormBlock.zip .
    
  3. Go to Streaming Analytics → Ecosystem → Analytics Extension.

  4. Click Manage Extension → Add Extension.

  5. Select and upload your ZIP file.

  6. Click Restart to deploy extension.

  7. After Apama restarts successfully, you can verify your extension under the Installed Blocks tab.

Conclusion & Next Steps

:sparkles: By the end of this article, you should be able to create your own custom Analytics Builder block and deploy it in your tenant.

Next Steps:

  • :magnifying_glass_tilted_left: Explore the Python or JavaScript logic used inside custom blocks
  • :rocket: Set up CI/CD pipelines for deployment across multiple tenants

References

4 Likes