mirror of
https://code.dumpstack.io/tools/appvm.git
synced 2024-11-23 04:33:02 +00:00
Set memory params of memory autoballoning through arguments
This commit is contained in:
parent
0cef401cb5
commit
02f4eab277
12
appvm.go
12
appvm.go
@ -241,14 +241,12 @@ func drop(name string) {
|
|||||||
os.RemoveAll(appDataPath)
|
os.RemoveAll(appDataPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func autoBalloon(l *libvirt.Libvirt) {
|
func autoBalloon(l *libvirt.Libvirt, memoryMin, adjustPercent uint64) {
|
||||||
domains, err := l.Domains()
|
domains, err := l.Domains()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
const memoryMin = 512 * 1024 // 512 MiB
|
|
||||||
|
|
||||||
table := tablewriter.NewWriter(os.Stdout)
|
table := tablewriter.NewWriter(os.Stdout)
|
||||||
table.SetHeader([]string{"Application VM", "Used memory", "Current memory", "Max memory", "New memory"})
|
table.SetHeader([]string{"Application VM", "Used memory", "Current memory", "Max memory", "New memory"})
|
||||||
for _, d := range domains {
|
for _, d := range domains {
|
||||||
@ -270,7 +268,7 @@ func autoBalloon(l *libvirt.Libvirt) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
memoryNew := uint64(float64(memoryUsed) * 1.2) // +20%
|
memoryNew := uint64(float64(memoryUsed) * (1 + float64(adjustPercent)/100))
|
||||||
|
|
||||||
if memoryNew > memoryMax {
|
if memoryNew > memoryMax {
|
||||||
memoryNew = memoryMax - 1
|
memoryNew = memoryMax - 1
|
||||||
@ -308,7 +306,9 @@ func main() {
|
|||||||
defer l.Disconnect()
|
defer l.Disconnect()
|
||||||
|
|
||||||
kingpin.Command("list", "List applications")
|
kingpin.Command("list", "List applications")
|
||||||
kingpin.Command("autoballoon", "Automatically adjust/reduce app vm memory")
|
autoballonCommand := kingpin.Command("autoballoon", "Automatically adjust/reduce app vm memory")
|
||||||
|
minMemory := autoballonCommand.Flag("min-memory", "Set minimal memory (megabytes)").Default("1024").Uint64()
|
||||||
|
adjustPercent := autoballonCommand.Flag("adj-memory", "Adjust memory ammount (percents)").Default("20").Uint64()
|
||||||
startName := kingpin.Command("start", "Start application").Arg("name", "Application name").Required().String()
|
startName := kingpin.Command("start", "Start application").Arg("name", "Application name").Required().String()
|
||||||
stopName := kingpin.Command("stop", "Stop application").Arg("name", "Application name").Required().String()
|
stopName := kingpin.Command("stop", "Stop application").Arg("name", "Application name").Required().String()
|
||||||
dropName := kingpin.Command("drop", "Remove application data").Arg("name", "Application name").Required().String()
|
dropName := kingpin.Command("drop", "Remove application data").Arg("name", "Application name").Required().String()
|
||||||
@ -323,6 +323,6 @@ func main() {
|
|||||||
case "drop":
|
case "drop":
|
||||||
drop(*dropName)
|
drop(*dropName)
|
||||||
case "autoballoon":
|
case "autoballoon":
|
||||||
autoBalloon(l)
|
autoBalloon(l, *minMemory*1024, *adjustPercent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user