import "golang" import "sys" file "/tmp/mgmt/systemload" { state => $const.res.file.state.exists, content => golang.template("load average: {{ .load }} threshold: {{ .threshold }}\n", $tmplvalues), } $tmplvalues = struct{load => $theload, threshold => $threshold,} $theload = sys.load()->x1 $threshold = 1.5 # change me if you like # simple hysteresis implementation $h1 = $theload > $threshold $h2 = history($theload, 1000) > $threshold $h3 = history($theload, 2000) > $threshold $unload = $h1 or $h2 or $h3 virt "mgmt1" { uri => "qemu:///session", cpus => 1, memory => 524288, state => "running", transient => true, } # this vm shuts down under load... virt "mgmt2" { uri => "qemu:///session", cpus => 1, memory => 524288, state => if $unload { "shutoff" } else { "running" }, transient => true, }