Added system module, GetUptimeSeconds and GetUptimeFormatted funcs, taskGetSystemUptime

This commit is contained in:
Paulo Truta
2021-05-31 11:21:14 +00:00
parent 770e814b6e
commit df3f8fe904
4 changed files with 77 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
package system
import (
"fmt"
"strconv"
"github.com/shirou/gopsutil/host"
)
func GetUptimeInSeconds() string {
uptime, _ := host.Uptime()
return strconv.FormatUint(uptime, 10)
}
func GetUptimeFormatted() string {
uptime, _ := host.Uptime()
days := uptime / (60 * 60 * 24)
hours := (uptime - (days * 60 * 60 * 24)) / (60 * 60)
minutes := ((uptime - (days * 60 * 60 * 24)) - (hours * 60 * 60)) / 60
return fmt.Sprintf("%d days, %d hours, %d minutes", days, hours, minutes)
}