Files
mgmt/examples/lang/hysteresis1.mcl
James Shubin 6cc5adcd25 lang, test, examples: lang: Use new syntax for structlookup
Sugar makes the world go round.
2023-11-04 14:52:19 -04:00

35 lines
789 B
Plaintext

import "sys"
file "/tmp/mgmt/systemload" {
state => $const.res.file.state.exists,
content => 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, 1) > $threshold
$h3 = history($theload, 2) > $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,
}