本文整理汇总了Golang中syscall.Sysinfo函数的典型用法代码示例。如果您正苦于以下问题:Golang Sysinfo函数的具体用法?Golang Sysinfo怎么用?Golang Sysinfo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Sysinfo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BootTime
func BootTime() (uint64, error) {
sysinfo := &syscall.Sysinfo_t{}
if err := syscall.Sysinfo(sysinfo); err != nil {
return 0, err
}
return uint64(sysinfo.Uptime), nil
}
示例2: runningStatus
func runningStatus(w http.ResponseWriter) (res jsonObject) {
sys := &syscall.Sysinfo_t{}
_ = syscall.Sysinfo(sys)
log := []statusEntry{}
status.LogBuf.Do(func(v interface{}) {
if v != nil {
log = append(log, v.(statusEntry))
}
})
res = jsonObject{
"status": "OK",
"response": map[string]interface{}{
"uptime": sys.Uptime,
"load_1": sys.Loads[0],
"load_5": sys.Loads[1],
"load_15": sys.Loads[2],
"freeram": sys.Freeram,
"log": log,
"notification": status.Notifications(),
},
}
return
}
示例3: procUsage
func procUsage(pcpu *float64, rss, vss *int64) error {
contents, err := ioutil.ReadFile(procStatFile)
if err != nil {
return err
}
fields := bytes.Fields(contents)
*rss = (parseInt64(fields[rssPos])) << 12
*vss = parseInt64(fields[vssPos])
startTime := parseInt64(fields[startPos])
utime := parseInt64(fields[utimePos])
stime := parseInt64(fields[stimePos])
totalTime := utime + stime
var sysinfo syscall.Sysinfo_t
if err := syscall.Sysinfo(&sysinfo); err != nil {
return err
}
seconds := int64(sysinfo.Uptime) - (startTime / ticks)
if seconds > 0 {
ipcpu := (totalTime * 1000 / ticks) / seconds
*pcpu = float64(ipcpu) / 10.0
}
return nil
}
示例4: main
func main() {
log.SetFlags(0)
log.SetPrefix("uptime: ")
flag.Parse()
var info syscall.Sysinfo_t
var err error
syscall.Sysinfo(&info)
ck(err)
now := time.Now().Format("15:04:05")
fmt.Printf(" %s up ", now)
info.Uptime /= 60
min := info.Uptime % 60
info.Uptime /= 60
hours := info.Uptime % 24
days := info.Uptime / 24
if days != 0 {
fmt.Printf("%d day", days)
if days != 1 {
fmt.Printf("s")
}
fmt.Printf(", ")
}
if hours != 0 {
fmt.Printf("%2d:%02d, ", hours, min)
} else {
fmt.Printf("%d min,", min)
}
fmt.Printf(" load average: %.02f, %.02f, %.02f\n",
float64(info.Loads[0])/65536, float64(info.Loads[1])/65536, float64(info.Loads[2])/65536)
}
示例5: main
func main() {
client := http.Client{}
for {
si := syscall.Sysinfo_t{}
syscall.Sysinfo(&si)
l := strconv.FormatFloat(float64(si.Loads[0])/65536, 'f', 2)
fmt.Println(l, si.Loads[0]/65536.0, si.Loads[0])
time.Sleep(1 * time.Second)
continue
resp, err := client.PostForm("https://api.stathat.com/ez", url.Values{
"stat": {"loadavg"},
"ezkey": {"YLJRun7adtSFKR2u"},
"value": {l},
})
if err != nil {
// Problems...
fmt.Println("Error sending stat... : %v", err)
os.Exit(1)
}
fmt.Println(resp)
resp.Body.Close()
time.Sleep(1 * time.Second)
}
}
示例6: Uptime
// Uptime returns the number of seconds since the system has booted
func Uptime() (int64, error) {
info := &syscall.Sysinfo_t{}
err := syscall.Sysinfo(info)
if err != nil {
return 0, err
}
return int64(info.Uptime), nil
}
示例7: update_sysinfo
func update_sysinfo() {
sysinfo_mutex.Lock()
defer sysinfo_mutex.Unlock()
err := syscall.Sysinfo(sysinfo)
if err != nil {
log.Panic("syscall.Sysinfo failed: ", err)
}
}
示例8: PhysmemAvail
// Returns available physical memory
func PhysmemAvail() uint64 {
info := syscall.Sysinfo_t{}
err := syscall.Sysinfo(&info)
if err != nil {
return 0
}
return info.Freeram
}
示例9: uptime
func uptime() (int64, error) {
sysinfo := syscall.Sysinfo_t{}
if err := syscall.Sysinfo(&sysinfo); err != nil {
return 0.0, err
} else {
return sysinfo.Uptime, nil
}
}
示例10: Load
func Load() int64 {
info := &syscall.Sysinfo_t{}
err := syscall.Sysinfo(info)
if err != nil {
fmt.Printf("%s\n", err)
}
return info.Uptime
}
示例11: fillInStatus
func (mem *MemStatus) fillInStatus() {
//system memory usage
sysInfo := new(syscall.Sysinfo_t)
err := syscall.Sysinfo(sysInfo)
if err == nil {
mem.All = uint64(sysInfo.Totalram)
mem.Free = uint64(sysInfo.Freeram)
mem.Used = mem.All - mem.Free
}
}
示例12: GetSysinfo
// Get sysinfo
func GetSysinfo() (sysinfo *syscall.Sysinfo_t, err error) {
sysinfo = new(syscall.Sysinfo_t)
err = syscall.Sysinfo(sysinfo)
if err != nil {
ALARM_MANAGER.Add(ALARM_SYSCALL, err, "Sysinfo failed")
logger.Debug("Failed in syscall sysinfo, error: %s", err.Error())
return
}
return sysinfo, nil
}
示例13: GetSystemInfo
func GetSystemInfo(cResp chan<- *Response, rawArgs *json.RawMessage, tag string) {
st := &syscall.Sysinfo_t{}
if err := syscall.Sysinfo(st); err != nil {
cResp <- &Response{nil, tag, err}
return
}
sinfo := &SysInfo{}
sinfo.Uptime = time.Duration(st.Uptime)
// float64(1<<SI_LOAD_SHIFT) == 65536.0
scale := 65536.0
sinfo.Loadavg.One = float64(st.Loads[0]) / scale
sinfo.Loadavg.Five = float64(st.Loads[1]) / scale
sinfo.Loadavg.Fifteen = float64(st.Loads[2]) / scale
unit := uint64(st.Unit) * 1024 // kB
sinfo.Ram.Total = uint64(st.Totalram) / unit
sinfo.Ram.Free = uint64(st.Freeram) / unit
sinfo.Ram.Buffer = uint64(st.Bufferram) / unit
sinfo.Swap.Total = uint64(st.Totalswap) / unit
sinfo.Swap.Free = uint64(st.Freeswap) / unit
sinfo.LongBit = getLongBit()
switch u, err := getUname(); {
case err == nil:
sinfo.Uname = u
default:
cResp <- &Response{nil, tag, err}
return
}
switch u, err := getLoggedUsers(); {
case err == nil:
sinfo.Users = u
default:
cResp <- &Response{nil, tag, err}
return
}
switch d, err := getDisksInfo(); {
case err == nil:
sinfo.Disks = d
default:
cResp <- &Response{nil, tag, err}
return
}
cResp <- &Response{sinfo, tag, nil}
}
示例14: Get
func (self *Uptime) Get() error {
sysinfo := syscall.Sysinfo_t{}
if err := syscall.Sysinfo(&sysinfo); err != nil {
return err
}
self.Length = float64(sysinfo.Uptime)
return nil
}
示例15: GetSwap
func GetSwap() (*Swap, error) {
swap := &Swap{}
sysinfo := syscall.Sysinfo_t{}
if err := syscall.Sysinfo(&sysinfo); err != nil {
return swap, err
}
swap.Total = uint64(sysinfo.Totalswap)
swap.Free = uint64(sysinfo.Freeswap)
swap.Used = swap.Total - swap.Free
return swap, nil
}