diff --git a/cmd/crowdsec-cli/dashboard.go b/cmd/crowdsec-cli/dashboard.go index a8f08c9a3..8e59ba82c 100644 --- a/cmd/crowdsec-cli/dashboard.go +++ b/cmd/crowdsec-cli/dashboard.go @@ -1,7 +1,9 @@ package main import ( + "errors" "fmt" + "math" "os" "os/exec" "os/user" @@ -13,6 +15,7 @@ import ( "github.com/AlecAivazis/survey/v2" "github.com/crowdsecurity/crowdsec/pkg/metabase" + "github.com/pbnjay/memory" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -109,6 +112,22 @@ cscli dashboard setup -l 0.0.0.0 -p 443 --password } } var answer bool + if valid, err := checkSystemMemory(); err == nil && !valid { + if !forceYes { + prompt := &survey.Confirm{ + Message: "Metabase requires 1-2GB of RAM, your system is below this requirement continue ?", + Default: true, + } + if err := survey.AskOne(prompt, &answer); err != nil { + log.Warnf("unable to ask about RAM check: %s", err) + } + if !answer { + log.Fatal("Unable to continue due to RAM requirement") + } + } else { + log.Warnf("Metabase requires 1-2GB of RAM, your system is below this requirement") + } + } groupExist := false dockerGroup, err := user.LookupGroup(crowdsecGroup) if err == nil { @@ -304,3 +323,14 @@ func passwordIsValid(password string) bool { return true } + +func checkSystemMemory() (bool, error) { + totMem := memory.TotalMemory() + if totMem == 0 { + return true, errors.New("Unable to get system total memory") + } + if uint64(math.Pow(2, 30)) >= totMem { + return false, nil + } + return true, nil +} diff --git a/go.mod b/go.mod index 6352bb2bd..fcd078bbf 100644 --- a/go.mod +++ b/go.mod @@ -144,6 +144,7 @@ require ( github.com/oklog/run v1.0.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/image-spec v1.0.2-0.20211117181255-693428a734f5 // indirect + github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/common v0.30.0 // indirect github.com/prometheus/procfs v0.7.3 // indirect diff --git a/go.sum b/go.sum index 73177a6c2..38ce61327 100644 --- a/go.sum +++ b/go.sum @@ -625,6 +625,8 @@ github.com/oschwald/geoip2-golang v1.4.0/go.mod h1:8QwxJvRImBH+Zl6Aa6MaIcs5YdlZS github.com/oschwald/maxminddb-golang v1.6.0/go.mod h1:DUJFucBg2cvqx42YmDa/+xHvb0elJtOm3o4aFQ/nb/w= github.com/oschwald/maxminddb-golang v1.8.0 h1:Uh/DSnGoxsyp/KYbY1AuP0tYEwfs0sCph9p/UMXK/Hk= github.com/oschwald/maxminddb-golang v1.8.0/go.mod h1:RXZtst0N6+FY/3qCNmZMBApR19cdQj43/NM9VkrNAis= +github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0= +github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-toml v1.4.0/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUruD3k1mMwo= github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=