Skip to main content

Engine Monitor

BACKEND SCRIPT

Monitor the backend engine events. A common use of Engine Monitor scripts is to run periodic tasks. Other typical uses of engine_monitor include

periodic tasks like polling

onbeginflush and onendflush are called every 60 seconds. Add your code here

timer

onmetronome is called roughly every second.

Structure​

Engine Monitor skeleton script

Table engine_monitor​

The Lua table engine_monitor = {..} can contain one or more of the following handler functions.

fieldtypewhen called
onbeginflushFunction( engine , timestamp)streaming window snapshot about to start. By default called every minute on top of the minute
onendflushFunction( engine, timestamp)when a streaming window was snapshotted and closed.
onmetronomeFunction( engine, timestamp, tick_count, tick_interval)Called every second

Threading note​

The backend engine is multi-threaded, the number of threads matches the StatsEngine>Flushers in trisulHubConfig.xml. You can use engine.instanceid() == "0" to run your script on one instance only.

Functions Reference​

Function onbeginflush​

Backend engine about to start summarizing a streaming analytics window. The results will be snapshotted to Trisul Hub database between this and onendflush

Purpose​

Allows you to add code that runs at the beginning of every summarization window (1 minute). Note that each backend engine will call this method once from different instances. If you only want to run your code on instance 0 you can do something like

onbeginflush  = function(engine, timestamp ) {
if engine:instanceid() == 0 then
-- your code here , only runs on instance 0
end
}### When called

This is called every 60 seconds by default. This is the size of the streaming analytics snapshot window. See “Tuning>StreamingWindowMSecs in trisulProbeConfig.xml”:/docs/guide/ref/trisulconfig.html#tuning

Parameters​

engineAn engine objectuse this object to add metrics, resources, or alerts into the Trisul framework. Remember that this is a backend engine.
timestampTimestamp secondsthe current time in Unix epoch time “tv_sec” seconds.

Return value​

Ignored

Example​


Function onendflush​

Backend engine has finished a snapshot window.

Purpose​

Pair this function with onbeginflush – you can use it to release any resources, or summarize and add metrics of your own.

When called​

When a snapshot window is complete.

Parameters​

engineAn engine objectuse this object to add metrics, resources, or alerts into the Trisul framework. Remember that this is a backend engine.
timestampTimestamp secondsthe current time in Unix epoch time “tv_sec” seconds.

Return value​

Ignored

Example​


Function onmetronome​

Purpose​

Plug into a 1-second metronome.

When called​

If you define a onmetronome(..) function you will be plugged into the Trisul metronome heartbeat mechanism. This method will be called every metronome tick(roughly every second). The context in which this method is called is threadsafe and you can add metrics to the Engine from here.

Parameters​

engineAn Engine objectuse this object to add metrics, resources, or alerts into the Trisul framework
timestampNumberCurrent timestamp (tv_sec epoch seconds)
tick_countNumberAn incremeting tick counter
tick_intervalNumberThe tick interval, in seconds.

Return value​

Ignored

Example​