當前位置: 首頁>>代碼示例>>Golang>>正文


Golang host.HostInfo函數代碼示例

本文整理匯總了Golang中github.com/shirou/gopsutil/host.HostInfo函數的典型用法代碼示例。如果您正苦於以下問題:Golang HostInfo函數的具體用法?Golang HostInfo怎麽用?Golang HostInfo使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了HostInfo函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: osName

// osName returns the name of the OS.
func osName() string {
	h, err := host.HostInfo()
	if err != nil || h.OS == "" {
		return "Linux"
	}
	return h.OS
}
開發者ID:haruyama,項目名稱:surf,代碼行數:8,代碼來源:agent.go

示例2: main

func main() {
	v, _ := mem.VirtualMemory()

	// almost every return value is a struct
	fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent)

	// convert to JSON. String() is also implemented
	fmt.Println(v)

	h, err := host.HostInfo()
	if err != nil {
		fmt.Println("err:", err)
	} else {

		fmt.Printf("hostname %v", h)
	}

	c, err := cpu.CPUInfo()
	if err != nil {
		fmt.Println("err:", err)
	}
	for _, v := range c {
		fmt.Printf("cpu info %v \n ", v)
	}

}
開發者ID:ohlinux,項目名稱:golang-snippet-cn,代碼行數:26,代碼來源:gopsutil-serverinfo.go

示例3: Gather

func (_ *SystemStats) Gather(acc telegraf.Accumulator) error {
	loadavg, err := load.LoadAvg()
	if err != nil {
		return err
	}

	hostinfo, err := host.HostInfo()
	if err != nil {
		return err
	}

	users, err := host.Users()
	if err != nil {
		return err
	}

	fields := map[string]interface{}{
		"load1":         loadavg.Load1,
		"load5":         loadavg.Load5,
		"load15":        loadavg.Load15,
		"uptime":        hostinfo.Uptime,
		"n_users":       len(users),
		"uptime_format": format_uptime(hostinfo.Uptime),
		"n_cpus":        runtime.NumCPU(),
	}
	acc.AddFields("system", fields, nil)

	return nil
}
開發者ID:adithyabenny,項目名稱:telegraf,代碼行數:29,代碼來源:system.go

示例4: Fingerprint

func (f *HostFingerprint) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) {
	hostInfo, err := host.HostInfo()
	if err != nil {
		f.logger.Println("[WARN] Error retrieving host information: ", err)
		return false, err
	}

	node.Attributes["os.name"] = hostInfo.Platform
	node.Attributes["os.version"] = hostInfo.PlatformVersion

	node.Attributes["kernel.name"] = runtime.GOOS
	node.Attributes["kernel.version"] = ""

	if runtime.GOOS != "windows" {
		out, err := exec.Command("uname", "-r").Output()
		if err != nil {
			return false, fmt.Errorf("Failed to run uname: %s", err)
		}
		node.Attributes["kernel.version"] = strings.Trim(string(out), "\n")
	}

	node.Attributes["hostname"] = hostInfo.Hostname

	return true, nil
}
開發者ID:bastiaanb,項目名稱:nomad,代碼行數:25,代碼來源:host.go

示例5: osVersion

// osVersion returns the OS version.
func osVersion() string {
	h, err := host.HostInfo()
	if err != nil || h.PlatformVersion == "" {
		return "0.0"
	}
	return h.PlatformVersion
}
開發者ID:haruyama,項目名稱:surf,代碼行數:8,代碼來源:agent.go

示例6: hostInfo

func hostInfo(ctx *gin.Context) {
	// For static
	info, err := host.HostInfo()
	if err != nil {
		ctx.AbortWithError(http.StatusInternalServerError, err)
		return
	}
	ctx.JSON(http.StatusOK, info)
}
開發者ID:theaidem,項目名稱:ginplate,代碼行數:9,代碼來源:main.go

示例7: handleHostCommand

func handleHostCommand(w http.ResponseWriter) {
	var buffer bytes.Buffer

	info, _ := host.HostInfo()
	buffer.WriteString(fmt.Sprintf("Boottime: %v\n", info.BootTime))
	buffer.WriteString(fmt.Sprintf("Hostname: %v\n", info.Hostname))
	buffer.WriteString(fmt.Sprintf("Uptime: %v\n", info.Uptime))

	io.WriteString(w, buffer.String())
}
開發者ID:josdirksen,項目名稱:slack-proxy,代碼行數:10,代碼來源:systemCommandHandlers.go

示例8: Distro

// Distro - gets distro info
// {'version': '14.04', 'name': 'Ubuntu'}
func Distro() DistroStruct {
	host, _ := pshost.HostInfo()

	d := DistroStruct{
		Version: host.PlatformVersion,
		Name:    host.Platform,
	}

	return d
}
開發者ID:0-T-0,項目名稱:amonagent,代碼行數:12,代碼來源:host.go

示例9: NewTextDetail

func NewTextDetail(alert string) (*TextDetail, error) {
	hostinfo, err := host.HostInfo()

	if err != nil {
		return nil, err
	}

	return &TextDetail{
		Alert:    alert,
		HostName: hostinfo.Hostname,
	}, nil
}
開發者ID:ngc224,項目名稱:loose-watcher,代碼行數:12,代碼來源:main.go

示例10: main

func main() {
	uname, err := getUname()
	if err != nil {
		fmt.Println("error: ", err)
	}

	fmt.Println("uname: ", uname)

	hostinfo := host.HostInfo()

	fmt.Println(hostinfo.String())
}
開發者ID:upccup,項目名稱:cuplearn,代碼行數:12,代碼來源:uname.go

示例11: ajax

func ajax(c web.C, w http.ResponseWriter, r *http.Request) {
	sys, _ := host.HostInfo()
	action := r.FormValue("action")
	if action == "time" {
		now := time.Now()
		past := now.Add(-1 * time.Duration(sys.Uptime) * time.Second)
		fmt.Fprintf(w, "%s;%s;%s", now.Format("January 2, 2006"), now.Format("3:04 pm"), past.Format("January 2, 2006"))
	}
	if action == "uptime" {
		uptimeDuration := time.Duration(sys.Uptime) * time.Second
		days := int(uptimeDuration.Hours() / 24)
		hours := int(uptimeDuration.Hours()) % 24
		minutes := int(uptimeDuration.Minutes()) % 60
		fmt.Fprintf(w, "%d;%d;%d", days, hours, minutes)
	}
	if action == "image" {
		bingResponse, err := http.Get("http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US")
		if err != nil {
			fmt.Printf("%s", err)
			os.Exit(1)
		} else {
			defer bingResponse.Body.Close()
			contents, err := ioutil.ReadAll(bingResponse.Body)
			if err != nil {
				fmt.Printf("%s", err)
				os.Exit(1)
			}

			var animals BingImage
			err = json.Unmarshal(contents, &animals)
			if err != nil {
				fmt.Println("error:", err)
			}
			fmt.Fprintf(w, "%s;%s", "https://www.bing.com/"+animals.Images[0].URL, animals.Images[0].Copyright)
		}
	}
	if action == "location" {
		ipResponse, err := http.Get("http://icanhazip.com")
		if err != nil {
			fmt.Printf("%s", err)
			os.Exit(1)
		} else {
			defer ipResponse.Body.Close()
			contents, err := ioutil.ReadAll(ipResponse.Body)
			if err != nil {
				fmt.Printf("%s", err)
				os.Exit(1)
			}
			fmt.Fprintf(w, "%s", string(contents))
		}
	}
}
開發者ID:dplesca,項目名稱:uptimey,代碼行數:52,代碼來源:uptimey.go

示例12: initHostInfo

func initHostInfo(monitorData *monitoringData) error {
	hostInfo, err := host.HostInfo()

	if hostInfo != nil {
		monitorData.ComputerName = hostInfo.Hostname
		monitorData.OperatingSystem = hostInfo.OS
		monitorData.Platform = hostInfo.Platform
		monitorData.PlatformFamily = hostInfo.PlatformFamily
		monitorData.ProcessNumber = hostInfo.Procs
	}

	return err
}
開發者ID:VALERE91,項目名稱:monitoring,代碼行數:13,代碼來源:systemMonitoring.go

示例13: home

func home(c web.C, w http.ResponseWriter, r *http.Request) {
	p := &Page{Title: "Uptimey"}
	sys, _ := host.HostInfo()

	now := time.Now()
	past := now.Add(-1 * time.Duration(sys.Uptime) * time.Second)

	p.StartDate = past
	tmpl, err := FSString(false, "/assets/index.html")
	if err != nil {
		fmt.Println(err.Error())
	}

	t, _ := template.New("index").Parse(tmpl)
	t.Execute(w, p)
}
開發者ID:dplesca,項目名稱:uptimey,代碼行數:16,代碼來源:uptimey.go

示例14: printStatus

func printStatus() {
	h, err := host.HostInfo()
	if err != nil {
		log.Println("Could not get host info", err)
	}
	log.Println(h.String())

	procs, err := ps.Processes()
	if err != nil {
		log.Println("Could not get processes")
	}

	log.Println(len(procs))

	for _, e := range procs {
		log.Println(e.Executable(), e.Pid(), e.PPid())
	}
}
開發者ID:mustafaakin,項目名稱:gonit,代碼行數:18,代碼來源:services.go

示例15: Gather

func (_ *SystemStats) Gather(acc plugins.Accumulator) error {
	loadavg, err := load.LoadAvg()
	if err != nil {
		return err
	}

	hostinfo, err := host.HostInfo()
	if err != nil {
		return err
	}

	acc.Add("load1", loadavg.Load1, nil)
	acc.Add("load5", loadavg.Load5, nil)
	acc.Add("load15", loadavg.Load15, nil)
	acc.Add("uptime", hostinfo.Uptime, nil)
	acc.Add("uptime_format", format_uptime(hostinfo.Uptime), nil)

	return nil
}
開發者ID:rzagabe,項目名稱:telegraf,代碼行數:19,代碼來源:system.go


注:本文中的github.com/shirou/gopsutil/host.HostInfo函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。