1

I'm wondering if there are any public scripts to automatically restart OpenVZ containers on certain load amount / high cpu. Trying to limit my containers on my personal machine, thanks.

user44754
  • 13
  • 4

1 Answers1

1

As seen on : http://openvz.org/Loadavg ; load average of some container can be acquired with

vzctl exec $CTID cat /proc/loadavg

you can script this easily with something like

#!/bin/bash

# loop over all OpenVZ containers
for container in $(vzlist -o ctid | egrep -o '[0-9]+')
do
  if (( $(bc <<< "$(vzctl exec $container cat /proc/loadavg | cut -d' ' -f1) <= 0.2") == 1 ))
  then
        echo "Load is less than 0.2"
  else
        echo "Load is above 0.2, stopping container $container"
        vzctl stop $container 

  fi
done

It uses the fact that load averages of respective intervals 1 5 and 15 can be read from /proc/loadavg

Hrvoje Špoljar
  • 5,245
  • 26
  • 42