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.

closed as off-topic by EEAA, mdpc, Katherine Villyard, Andrew Schulman, Ward Jan 12 '15 at 2:53

This question appears to be off-topic. The users who voted to close gave these specific reasons:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • this is hammer approach, if you wan't to script it really you can see my answer – Hrvoje Špoljar Nov 10 '14 at 16:17
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

  • Thank you. I'm unfamiliar with bash scripting. How would I make it kill the process? – user44754 Nov 10 '14 at 16:50
  • if this script is ran inside OpenVZ container as I understood from your question, you adjust load which is too high and restart with 'reboot' command; just add it below echo command in the script. – Hrvoje Špoljar Nov 10 '14 at 16:54
  • I want to run it on the host node to check for containers load. Sorry if I wasn't clear. – user44754 Nov 10 '14 at 17:00
  • I've updated answer with more specific approach to run on system which hosts OpenVZ containers – Hrvoje Špoljar Nov 10 '14 at 17:12
  • Awesome, thank you. I'll give this a try. Would the best way to keep it running is with a cronjob? – user44754 Nov 10 '14 at 17:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.