commit 41ae609accd114bc5d4a05a74a80d3213d217373 Author: Dejan Muhamedagic Date: Fri Nov 25 13:11:15 2011 +0100 Medium: RA: add NodeUtilization RA Index: pacemaker/extra/resources/Makefile.am =================================================================== --- pacemaker.orig/extra/resources/Makefile.am +++ pacemaker/extra/resources/Makefile.am @@ -33,7 +33,8 @@ ocf_SCRIPTS = ClusterMon \ Stateful \ SysInfo \ SystemHealth \ - remote + remote \ + NodeUtilization if BUILD_XML_HELP man7_MANS = $(ocf_SCRIPTS:%=ocf_pacemaker_%.7) Index: pacemaker/extra/resources/NodeUtilization =================================================================== --- /dev/null +++ pacemaker/extra/resources/NodeUtilization @@ -0,0 +1,230 @@ +#!/bin/sh +# +# +# NodeUtilization OCF Resource Agent +# +# Copyright (c) 2011 SUSE LINUX, John Shi +# All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of version 2 of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# Further, this software is distributed without any warranty that it is +# free of the rightful claim of any third person regarding infringement +# or the like. Any license provided herein, whether implied or +# otherwise, applies only to this software file. Patent licenses, if +# any, provided herein do not apply to combinations of this program with +# other software, or any other product whatsoever. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. +# +####################################################################### +# Initialization: + +: ${OCF_FUNCTIONS=${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs} +. ${OCF_FUNCTIONS} +: ${__OCF_ACTION=$1} + +####################################################################### + +meta_data() { + cat < + + +1.0 + + +This is an NodeUtilization Resource Agent. +This agent detects system parameters and put them into CIB by crm_attribute, +and it runs on every node as clone resource. + +NodeUtilization resource agent + + + + +If set, some of the HA parameters will be reset if there are +difference between HA parameters and system parameters when HA monitor. +Otherwise, the HA parameters will be set once when the resource instance starts. + +Set HA parameters when start or monitor + + + + +Enable setting cpu utilization. +Enable setting cpu utilization. + + + + +CPU reserved for non-HA related usage. +CPU reserved for non-HA related usage. + + + + +Enable setting memory utilization of host. +Enable setting memory utilization of host. + + + + +Memory reserved for other services inside host, in MB. +Memory reserved for other services inside host, in MB. + + + + +Enable setting the memory utilization of hypervisor. +Enable setting the memory utilization of hypervisor. + + + + +Memory reserved for the hypervisor, in MB. +Memory reserved for the hypervisor, in MB. + + + + + + + + + + + + +END +} + +set_utilization() { + host_name="$(hostname)" + + if ocf_is_true "$OCF_RESKEY_utilization_cpu"; then + sys_cpu=$(( $(grep -c processor /proc/cpuinfo) - $OCF_RESKEY_utilization_cpu_reservation )) + uti_cpu=$(crm_attribute -Q -t nodes -U "$host_name" -z -n cpu 2>/dev/null) + + if [ "$sys_cpu" != "$uti_cpu" ]; then + if ! crm_attribute -t nodes -U "$host_name" -z -n cpu -v $sys_cpu; then + ocf_log err "Failed to set cpu of utilization by crm_attribute." + return 1 + fi + fi + fi + + if ocf_is_true "$OCF_RESKEY_utilization_host_memory"; then + sys_mem=$(( $(awk '/MemTotal/{printf("%d\n",$2/1024);exit(0)}' /proc/meminfo) - $OCF_RESKEY_utilization_host_memory_reservation )) + uti_mem=$(crm_attribute -Q -t nodes -U "$host_name" -z -n host_memory 2>/dev/null) + + if [ "$sys_mem" != "$uti_mem" ]; then + if ! crm_attribute -t nodes -U "$host_name" -z -n host_memory -v $sys_mem; then + ocf_log err "Failed to set host_memory of utilization by crm_attribute." + return 1 + fi + fi + fi + + if [ -x /usr/sbin/xm ]; then + if ocf_is_true "$OCF_RESKEY_utilization_hv_memory"; then + hv_mem=$(( $(xm info | awk '/total_memory/{printf("%d\n",$3);exit(0)}') - $OCF_RESKEY_utilization_hv_memory_reservation )) + uti_mem=$(crm_attribute -Q -t nodes -U "$host_name" -z -n hv_memory 2>/dev/null) + + if [ "$hv_mem" != "$uti_mem" ]; then + if ! crm_attribute -t nodes -U "$host_name" -z -n hv_memory -v $hv_mem; then + ocf_log err "Failed to set hv_memory of utilization by crm_attribute." + return 1 + fi + fi + fi + fi +} + +NodeUtilization_usage() { + cat <