The Monitor is the heart of the Aware system. Its job is to managar a set of "handlers". Handlers may arrange to recieve alarms, software interrupts or fd notifcations. Handlers may generate events themselves allowing a forward chaining of event/handler actions.
As a simple example of using the monitor, consider an application that generates email alarms based on the free memory of a system. This is implemented as:
The Monitor provides an extensible framework for adding handlers. The hope is that a rich set of probes and condition handlers can be created such that systems can control themselves by adapting to changing conditions.
There are 4 main components to the Monitor:
Events are generated by the Alarm Queue thread and the FD Relay Queue thread and are sent to the Event Relay Queue which acts as a synchronization point. When the Handler thread is ready to process more events it takes them from the Event Relay Queue. Event resource management is the responsibilty of the Event Relay Queue. The Alarm Queue gets new Events from the Event Relay Queue, while the Handler Queue returns processed Events to the Event Relay Queue for reuse by the Alarm Queue and FD Relay Queue, respectively.
Handlers are expected to execute as quickly possible. If processing interferes with the duty cycle it is suggested the developer run them as a "tasklet". Tasklets execute in a seperate thread and are useful for long running codes as well as codes that use blocking system calls. It is up to the implementor to handle synchronization and state.
The duty cycle for the Alarm Queue is:
Define: probe_cycle_time = AW_DEFAULT_ALARM_CYCLE_TIME (can be changed)
The duty cycle for the Handler Queue is:
Handlers can register to match events:
#include "sysnet.h"
#include "util.h"
#include "address.h"
#include "hash.h"
#include "mask.h"
#include "log.h"
#include "monsignals.h"
#include "monthread.h"
#include "event.h"
#include "alarm.h"
#include "handler.h"
#include "tasklet.h"
Go to the source code of this file.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Value: { \
.logger_params = AW_MONITOR_LOGGER_DEFAULT_PARAMS , \
.sched = AW_MONITOR_SCHED_DEFAULT_PARAMS \
}
|
|
|
|
|
|
Value: { \
\
.filename = NULL,\
\
/* stderr */ \
.fd = 2, \
\
.min_level = AW_MONITOR_LOGGER_DEFAULT_MINLEVEL,\
\
.max_level = AW_ERROR_LOG_LEVEL, \
\
.strlevel = NULL, \
\
.flags = AW_LOGGER_DEFAULT_FLAGS, \
\
.error_logger = NULL \
}
|
|
|
Value: {\
\
.policy = SCHED_OTHER, \
.params.sched_priority = 0 \
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
State codes for monitor |
|
||||||||||||
|
Add handler to list of executing handlers. aw_add_handler
|
|
||||||||||||||||||||
|
Register a callback to be called when data is available on fd for a handler. Only executed for RUNNING handler. Relationship is 1-1 for fd to handler. aw_add_handler_fdcallback
|
|
||||||||||||||||||||||||
|
Register a callback to be called for every "interrupt" event.Only executed for RUNNING handler. Relationship is 1-1 for fd to handler. aw_add_handler_irecallback
|
|
|
Malloc , clear, set, init mutex, return object. aw_create_monitor
|
|
|
Cleanup , free resources. aw_destroy_monitor
|
|
||||||||||||
|
Send event to handlers. aw_monitor_append_event
|
|
||||||||||||
|
Dump contents of q to handlers. aw_monitor_append_q
|
|
||||||||||||||||
|
Send float32 event to handlers. aw_monitor_float32_event
|
|
||||||||||||||||
|
Send float64 event to handlers. aw_monitor_float64_event
|
|
||||||||||||||||
|
Send int32 event to handlers. aw_monitor_int32_event
|
|
||||||||||||||||
|
Send int64 event to handlers. aw_monitor_int64_event
|
|
||||||||||||
|
Print monitor stats to logger. aw_monitor_logstats
|
|
||||||||||||||||||||
|
Send string event to handlers, NOTE: this will free the string later! aw_monitor_string_event
|
|
||||||||||||||||
|
Send timestamp event to handlers. aw_monitor_timestamp_event
|
|
|
Increment and return event id. aw_next_event_id
|
|
||||||||||||
|
Remove handler from list of executing handlers. aw_remove_handler
|
|
||||||||||||
|
Unregister a callback to be called when data is available on fd. aw_remove_handler_fdcallback
|
|
||||||||||||
|
Unregister a callback. aw_remove_handler_irecallback
|
|
||||||||||||||||
|
Alter an existing schedule for a handler. aw_reschedule_handler
|
|
|
Returns a mask with 1 bit set guaranteed to be unique. aw_reserve_event_mask_bit
|
|
||||||||||||
|
Sends an interrupt event to cause the handler to run. aw_signal_handler_irecallback
|
|
|
Block until all monitor threads exit. aw_wait_monitor
|