Working with Counters

What are Counters?

Counters are used to track the number of times an event occurs in the processor, mostly it has been used for monitoring purposes of the workflow. It is useful for debugging and basic counting functions.

You can able to access the existing Counters using the menu:

Counters in menu

Why Counters?

Counters are usually just some processor-specific count that could help debug or monitoring purposes.

Set the counter name in the property field of the UpdateCounter processor. Each time the processor event occurred, it increments the counter’s value.

Counter configuration

And view its overall counters value count in the counters page.

Counters page

Counter Reset

It is possible to reset a counter to 0 from the counters table with the reset button in the last column (only when you have to write access to the counters based on the defined policies).

Counter Reset

How to update Counters using the UpdateCounter processor?

Counters can be updated by using the UpdateCounter processor. It updates the value of the counter when it detects the incoming flow file to the processor according to the specified Delta value.

Sample to show the working of Counters

This sample reads the JSON array file and splits into JSON elements and stores in a file. Here, the UpdateCounter processor is used to monitor the number of JSON elements get stored in the output File.

Counter sample

Note: Single or Multiple UpdateCounter processors can be used at the same time.

Step 1:
Use the GetFile processor to get the input file and configure it by specifying the Input Directory and File Filter as follows:

GetFile configuration

Step 2:
Use the SplitJson processor to split the JSON array into JSON elements using the specified JsonPath Expression as follows:

SplitJson configuration

Step 3:
Use the PutFile processor to store the JSON elements as file and configure it as follows:

PutFile configuration

Step 4:
Set the counter name in the property field of the UpdateCounter processor. The default value of the Delta field is 1. You can also change the value and configure the UpdateCounter processors as follows:

Set counter name

Step 5:
Open the counter page and you can find the Counter value gets updated according to the number of flow files processed and get stored in the output file.

Updated counter value