|
|
|
@ -21,12 +21,30 @@ import (
|
|
|
|
|
"syscall"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// FdLimits returns the soft and hard limits for file descriptors
|
|
|
|
|
func FdLimits() string {
|
|
|
|
|
flimit := syscall.Rlimit{}
|
|
|
|
|
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &flimit)
|
|
|
|
|
var unlimited int64 = syscall.RLIM_INFINITY
|
|
|
|
|
|
|
|
|
|
func limitToString(v uint64) string {
|
|
|
|
|
if v == uint64(unlimited) {
|
|
|
|
|
return "unlimited"
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf("%d", v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getLimits(resource int) string {
|
|
|
|
|
rlimit := syscall.Rlimit{}
|
|
|
|
|
err := syscall.Getrlimit(resource, &rlimit)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal("Error!")
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf("(soft=%d, hard=%d)", flimit.Cur, flimit.Max)
|
|
|
|
|
return fmt.Sprintf("(soft=%s, hard=%s)", limitToString(rlimit.Cur), limitToString(rlimit.Max))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FdLimits returns the soft and hard limits for file descriptors.
|
|
|
|
|
func FdLimits() string {
|
|
|
|
|
return getLimits(syscall.RLIMIT_NOFILE)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// VmLimits returns the soft and hard limits for virtual memory.
|
|
|
|
|
func VmLimits() string {
|
|
|
|
|
return getLimits(syscall.RLIMIT_AS)
|
|
|
|
|
}
|