diff -uNr a/doc/man/Makefile.am b/doc/man/Makefile.am --- a/doc/man/Makefile.am 2017-03-15 14:11:58.136058131 +0100 +++ b/doc/man/Makefile.am 2017-03-15 14:31:58.181539045 +0100 @@ -73,6 +73,7 @@ ocf_heartbeat_MailTo.7 \ ocf_heartbeat_ManageRAID.7 \ ocf_heartbeat_ManageVE.7 \ + ocf_heartbeat_NodeUtilization.7 \ ocf_heartbeat_nova-compute-wait.7 \ ocf_heartbeat_NovaEvacuate.7 \ ocf_heartbeat_Pure-FTPd.7 \ diff -uNr a/heartbeat/Makefile.am b/heartbeat/Makefile.am --- a/heartbeat/Makefile.am 2017-03-15 14:11:58.136058131 +0100 +++ b/heartbeat/Makefile.am 2017-03-15 14:32:45.554873187 +0100 @@ -95,6 +95,7 @@ MailTo \ ManageRAID \ ManageVE \ + NodeUtilization \ mysql \ mysql-proxy \ nagios \ diff -uNr a/heartbeat/NodeUtilization b/heartbeat/NodeUtilization --- a/heartbeat/NodeUtilization 1970-01-01 01:00:00.000000000 +0100 +++ b/heartbeat/NodeUtilization 2017-03-15 14:29:18.141788491 +0100 @@ -0,0 +1,226 @@ +#!/bin/sh +# +# +# NodeUtilization OCF Resource Agent +# +# Copyright (c) 2011 SUSE LINUX, John Shi +# Copyright (c) 2016 SUSE LINUX, Kristoffer Gronlund +# 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_DIR=${OCF_ROOT}/lib/heartbeat} +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs + +####################################################################### + +NodeUtilization_meta_data() { + cat < + + +1.0 + + +The Node Utilization agent detects system parameters like available CPU, host +memory and hypervisor memory availability, and adds them into the CIB for each +node using crm_attribute. Run the agent as a clone resource to have it populate +these parameters on each node. +Note: Setting hv_memory only works with Xen at the moment, using the xl or xm +command line tools. + +Node Utilization + + + + +If set, parameters will be updated if there are differences between the HA +parameters and the system values when running the monitor action. +If not set, the parameters will be set once when the resource instance starts. + +Dynamically update parameters in monitor + + + + +Enable setting node CPU utilization limit. +Set node CPU utilization limit. + + + + +Subtract this value when setting the CPU utilization parameter. +CPU reservation. + + + + +Enable setting available host memory. +Set available host memory. + + + + +Subtract this value when setting host memory utilization, in MB. +Host memory reservation, in MB. + + + + +Enable setting available hypervisor memory. +Set available hypervisor memory. + + + + +Subtract this value when setting hypervisor memory utilization, in MB. +Hypervisor memory reservation, in MB. + + + + + + + + + + + + +END +} + +Host_Total_Memory() { + local xentool + + xentool=$(which xl 2> /dev/null || which xm 2> /dev/null) + + if [ -x $xentool ]; then + $xentool info | awk '/total_memory/{printf("%d\n",$3);exit(0)}' + else + ocf_log warn "Can only set hv_memory for Xen hypervisor" + echo "0" + fi +} + + +set_utilization() { + host_name="$(ocf_local_nodename)" + + 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 the cpu utilization attribute for $host_name using 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 the host_memory utilization attribute for $host_name using crm_attribute." + return 1 + fi + fi + fi + + if ocf_is_true "$OCF_RESKEY_utilization_hv_memory"; then + hv_mem=$(( $(Host_Total_Memory) - OCF_RESKEY_utilization_hv_memory_reservation )) + uti_mem=$(crm_attribute -Q -t nodes -U "$host_name" -z -n hv_memory 2>/dev/null) + + [ $hv_mem -lt 0 ] && hv_mem=0 + + 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 the hv_memory utilization attribute for $host_name using crm_attribute." + return 1 + fi + fi + fi +} + +NodeUtilization_usage() { + cat <