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 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.
And view its overall counters value count in the counters page.
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).
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.
Note: Single or Multiple UpdateCounter processors can be used at the same time.
Use the GetFile processor to get the input file and configure it by specifying the Input Directory and File Filter as follows:
Use the SplitJson processor to split the JSON array into JSON elements using the specified JsonPath Expression as follows:
Use the PutFile processor to store the JSON elements as file and configure it as follows:
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:
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.