note description: "RRD node" author: "Patrick Ruckstuhl " date: "$Date$" revision: "$Revision$" class NODE_RRD inherit A_NODE redefine listen_queues, register_message_handlers, aranea_startup end O_NODE O_RRD_CONSTANTS KL_SHARED_FILE_SYSTEM export {NONE} all end create make feature -- Access name: STRING = "Origo RRD node" version: STRING = "$Revision$" feature {NONE} -- Implementation rrd: RRD -- Shared rrd instance. root_path: STRING -- Root path for rrd files. once Result := config_parser.get_default ("rrd_root_path", "/var/lib/origo-rrd/") end feature {NONE} -- Implementation of message handlers listen_queues: DS_LIST [STRING] -- Listen queues. once Result := Precursor Result.put_last (origo_rrd_queue) end register_message_handlers -- Register message handlers. do Precursor register_message_handler (rrd_namespace, rrd_create_type, agent rrd_create) register_message_handler (rrd_namespace, rrd_update_type, agent rrd_update) register_message_handler (rrd_namespace, rrd_batch_update_type, agent rrd_batch_update) end rrd_create (a_msg: A_MESSAGE) -- Create an rrd file based on a_msg. require a_msg_ok: a_msg /= Void local l_msg: O_RRD_CREATE_MESSAGE l_args: DS_ARRAYED_LIST[STRING] l_dirname: STRING l_datasource_definition_list: DS_ARRAYED_LIST[A_STRING_VALUE] l_round_robin_archives_list: DS_ARRAYED_LIST[A_STRING_VALUE] do l_msg ?= a_msg check valid_message: l_msg /= Void end -- get directory part and create directory (if necessary) l_dirname := file_system.dirname (root_path + l_msg.filename.value) node_logger.debugging (l_dirname) file_system.recursive_create_directory (l_dirname) create l_args.make (10) l_args.put_last ("create") l_args.put_last (root_path + l_msg.filename.value + ".rrd") if l_msg.start_time.value > 0 then l_args.put_last ("--start") l_args.put_last (l_msg.start_time.out) end if l_msg.step.value > 0 then l_args.put_last ("--step") l_args.put_last (l_msg.step.out) end l_datasource_definition_list := l_msg.datasource_definition.sequence from l_datasource_definition_list.start until l_datasource_definition_list.after loop l_args.force_last (l_datasource_definition_list.item_for_iteration.value) -- Increment l_datasource_definition_list.forth end l_round_robin_archives_list := l_msg.round_robin_archives.sequence from l_round_robin_archives_list.start until l_round_robin_archives_list.after loop l_args.force_last (l_round_robin_archives_list.item_for_iteration.value) -- Increment l_round_robin_archives_list.forth end if node_logger.is_enabled_for (debug_p) then log_arguments (l_args) end rrd.rrd_create (l_args) end rrd_update (a_msg: A_MESSAGE) -- Update an rrd file based on a_msg. require a_msg_ok: a_msg /= Void local l_msg: O_RRD_UPDATE_MESSAGE do l_msg ?= a_msg check valid_message: l_msg /= Void end process_update ( l_msg.filename, l_msg.template, l_msg.update.sequence) end rrd_batch_update (a_msg: A_MESSAGE) -- Update an rrd file based on a_msg. require a_msg_ok: a_msg /= Void local l_msg: O_RRD_BATCH_UPDATE_MESSAGE l_update_list: DS_ARRAYED_LIST [O_RRD_PROJECT_UPDATE_MESSAGE] l_update: O_RRD_PROJECT_UPDATE_MESSAGE l_template: STRING do l_msg ?= a_msg check valid_message: l_msg /= Void end l_update_list := l_msg.update_list from l_update_list.start until l_update_list.after loop l_update := l_update_list.item_for_iteration -- Template might be void l_template ?= l_update.template process_update ( l_update.filename, l_template, l_update.update.sequence) -- increment l_update_list.forth end end feature {NONE} -- Implementation helpers aranea_startup -- Aranea startup do Precursor create rrd.make end process_update (a_filename: STRING; a_template: STRING; a_update_list: DS_ARRAYED_LIST [A_STRING_VALUE]) -- Process the contents of a single update message require exists: a_filename /= Void and then not a_filename.is_empty exists: a_update_list /= Void local l_args: DS_ARRAYED_LIST[STRING] do create l_args.make (10) l_args.put_last ("update") l_args.put_last (root_path + a_filename + ".rrd") if a_template /= Void and then not a_template.is_empty then l_args.put_last ("--template") l_args.put_last (a_template) end from a_update_list.start until a_update_list.after loop l_args.force_last (a_update_list.item_for_iteration.value) -- Increment a_update_list.forth end if node_logger.is_enabled_for (debug_p) then log_arguments (l_args) end rrd.rrd_update (l_args) end log_arguments (an_arguments: DS_ARRAYED_LIST[STRING]) -- Log the arguments used to call an rrd function. require an_arguments_ok: an_arguments /= Void local l_args: STRING do create l_args.make (100) from an_arguments.start until an_arguments.after loop l_args.append (an_arguments.item_for_iteration) l_args.append (" ") an_arguments.forth end l_args.remove_tail (1) node_logger.debugging (l_args) end end