From b4d666ff63acd269b0acb2c4419643863c683750 Mon Sep 17 00:00:00 2001 From: Vu Tran Date: Tue, 30 Sep 2014 12:22:12 -0400 Subject: add generic monitor framework Instead of having a central file or group of files to describe what data resources should be monitored. The content of these files will depend on what core system monitoring is used ((e.g. Nagios or Monasca). It's desirable to have each recipe describes what it wants be monitored in generic way such that various system monitors can understand and convert these into their format. If a recipe wishes to register itself to system monitor, it inherits monitor bbclass and use MONITOR_SERVICE_PACKAGES and MONITOR_SERVICE_ to indicate what processes should should be monitored. Also MONITOR_CHECKS_ variale can be used to pass list of scripts which will be run on target and if any of these scripts fail then will report. Eventually monitor.bbclass will be expanded to allow recipe to describe more complicated information passed down to system monitor (e.g. Nagios or Monasca) Signed-off-by: Vu Tran Signed-off-by: Bruce Ashfield --- meta-openstack/classes/monitor.bbclass | 107 +++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 meta-openstack/classes/monitor.bbclass (limited to 'meta-openstack/classes') diff --git a/meta-openstack/classes/monitor.bbclass b/meta-openstack/classes/monitor.bbclass new file mode 100644 index 0000000..83aaea2 --- /dev/null +++ b/meta-openstack/classes/monitor.bbclass @@ -0,0 +1,107 @@ +MONITOR_STAGING_DIR="${STAGING_DIR}/monitor" +MONITOR_STAGING_SERVICES_DIR="${MONITOR_STAGING_DIR}/services" +MONITOR_STAGING_CHECKS_DIR="${MONITOR_STAGING_DIR}/checks" +MONITOR_CONFIG_DIR="${IMAGE_ROOTFS}/etc/monitor" +MONITOR_CONFIG_SERVICES_DIR="${MONITOR_CONFIG_DIR}/services" +MONITOR_CONFIG_CHECKS_DIR="${MONITOR_CONFIG_DIR}/checks" + +addtask monitor_install before do_package after do_install +addtask monitor_clean before do_clean + + +def copy_check_files(d, check_var_name, src, dest): + import shutil + + mon_checks = bb.data.getVar(check_var_name, d, 1) + if mon_checks != None: + if not os.path.exists(dest): + os.makedirs(dest) + for check in mon_checks.split(): + if os.path.exists(src + "/" + check): + shutil.copy(src + "/" + check, dest) + os.chmod(dest + "/" + check, 0755) + +python do_monitor_install() { + import shutil + + if base_contains('OPENSTACK_EXTRA_FEATURES', 'monitoring', "0", "1", d) == "1": + bb.debug(1, 'OpenStack monitoring feature is disabled, skipping do_monitor_install') + return + + mon_dir = bb.data.getVar('MONITOR_STAGING_DIR', d, 1) + mon_services_dir = bb.data.getVar('MONITOR_STAGING_SERVICES_DIR', d, 1) + mon_checks_dir = bb.data.getVar('MONITOR_STAGING_CHECKS_DIR', d, 1) + if not os.path.exists(mon_dir): + os.makedirs(mon_dir) + if not os.path.exists(mon_services_dir): + os.makedirs(mon_services_dir) + if not os.path.exists(mon_checks_dir): + os.makedirs(mon_checks_dir) + workdir = d.getVar('WORKDIR', True) + + # Process monitor SERVICE catagory + mon_service_pkgs = bb.data.getVar('MONITOR_SERVICE_PACKAGES', d, 1) + if mon_service_pkgs != None: + for pkg in mon_service_pkgs.split(): + f_name = os.path.join(mon_services_dir, pkg + '.service') + if os.path.exists(f_name): + os.remove(f_name) + data = bb.data.getVar('MONITOR_SERVICE_' + pkg, d, 1) + if data != None: + f = open(f_name, 'w') + f.write(d.getVar('MONITOR_SERVICE_' + pkg)) + + # Process monior CHECKS catagory + packages = (d.getVar('PACKAGES', True) or "").split() + if len(packages) >= 1 and os.path.exists(mon_checks_dir): + for pkg in packages: + copy_check_files(d, 'MONITOR_CHECKS_' + pkg, workdir, mon_checks_dir + '/' + pkg) +} + +python do_monitor_clean() { + import shutil + + mon_dir = bb.data.getVar('MONITOR_STAGING_DIR', d, 1) + mon_services_dir = bb.data.getVar('MONITOR_STAGING_SERVICES_DIR', d, 1) + mon_checks_dir = bb.data.getVar('MONITOR_STAGING_CHECKS_DIR', d, 1) + if not os.path.exists(mon_dir): + return + + # Clean up monitor SERVICE catagory + mon_service_pkgs = bb.data.getVar('MONITOR_SERVICE_PACKAGES', d, 1) + if mon_service_pkgs != None and os.path.exists(mon_services_dir): + for pkg in mon_service_pkgs.split(): + f_name = os.path.join(mon_services_dir, pkg + '.service') + if os.path.exists(f_name): + os.remove(f_name) + + # Process monior CHECKS catagory + packages = (d.getVar('PACKAGES', True) or "").split() + if len(packages) >= 1 and os.path.exists(mon_checks_dir): + for pkg in packages: + if bb.data.getVar('MONITOR_CHECKS_' + pkg, d, 1) != None: + shutil.rmtree(mon_checks_dir + "/" + pkg, True) +} + +monitor_rootfs_postprocess() { + if ${@base_contains('OPENSTACK_EXTRA_FEATURES', 'monitoring', "false", "true", d)}; then + echo "OpenStack monitoring feature is disabled, skipping monitor_rootfs_postprocess" + exit + fi + + mkdir -p ${MONITOR_CONFIG_DIR} > /dev/null 2>&1 + mkdir -p ${MONITOR_CONFIG_SERVICES_DIR} > /dev/null 2>&1 + mkdir -p ${MONITOR_CONFIG_CHECKS_DIR} > /dev/null 2>&1 + + # Process monitor SERVICE catagory + files_list=`find ${MONITOR_STAGING_SERVICES_DIR} -type f` + for f in ${files_list}; do + cat $f >> ${MONITOR_CONFIG_SERVICES_DIR}/service_list.cfg + echo >> ${MONITOR_CONFIG_SERVICES_DIR}/service_list.cfg + done + + # Process monior CHECKS catagory + cp -rf ${MONITOR_STAGING_CHECKS_DIR}/* ${MONITOR_CONFIG_CHECKS_DIR} +} + +ROOTFS_POSTPROCESS_COMMAND += "monitor_rootfs_postprocess ; " -- cgit v1.2.3-54-g00ecf