当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.Sysinfo函数代码示例

本文整理汇总了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
}
开发者ID:toorop,项目名称:telegraf,代码行数:7,代码来源:host_linux.go

示例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
}
开发者ID:jmptrader,项目名称:interlock,代码行数:27,代码来源:status.go

示例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
}
开发者ID:picmonkey,项目名称:gnatsd,代码行数:29,代码来源:pse_linux.go

示例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)
}
开发者ID:qeedquan,项目名称:misc_utilities,代码行数:33,代码来源:uptime.go

示例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)
	}
}
开发者ID:marcelom,项目名称:gocollector,代码行数:29,代码来源:collector.go

示例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
}
开发者ID:juju,项目名称:utils,代码行数:9,代码来源:uptime_nix.go

示例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)
	}
}
开发者ID:pwaller,项目名称:go-memhelper,代码行数:8,代码来源:memhelper.go

示例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
}
开发者ID:HarryBird,项目名称:go-gnulib,代码行数:9,代码来源:info_linux.go

示例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
	}
}
开发者ID:DrItanium,项目名称:moo,代码行数:9,代码来源:mac-emulation.go

示例10: Load

func Load() int64 {
	info := &syscall.Sysinfo_t{}
	err := syscall.Sysinfo(info)
	if err != nil {
		fmt.Printf("%s\n", err)
	}

	return info.Uptime
}
开发者ID:setkeh,项目名称:fluffy-fibula,代码行数:9,代码来源:uptime.go

示例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
	}
}
开发者ID:KunBetter,项目名称:GridSearch,代码行数:10,代码来源:memory_supported.go

示例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
}
开发者ID:richardliao,项目名称:swarmstorage,代码行数:12,代码来源:sysstat.go

示例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}
}
开发者ID:0xef53,项目名称:phoenix-guest-agent,代码行数:54,代码来源:sysinfo.go

示例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
}
开发者ID:rasputnik,项目名称:gosigar,代码行数:11,代码来源:sigar_linux.go

示例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
}
开发者ID:hugb,项目名称:beegecluster,代码行数:11,代码来源:systeminfo.go


注:本文中的syscall.Sysinfo函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。