• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang host.HostInfo函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/shirou/gopsutil/host.HostInfo函数的典型用法代码示例。如果您正苦于以下问题:Golang HostInfo函数的具体用法?Golang HostInfo怎么用?Golang HostInfo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了HostInfo函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: Gather

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

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

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

	return nil
}
开发者ID:bahadrix,项目名称:telegraf,代码行数:22,代码来源:system.go


示例17: Run

// Run gathers host information from gopsutil.
func (h *HostInfo) Run() error {
	data, err := gopsutil_host.HostInfo()
	if err != nil {
		return err
	}

	h.Data["Hostname"] = data.Hostname
	h.Data["Uptime"] = data.Uptime
	h.Data["Procs"] = data.Procs
	h.Data["OS"] = data.OS
	h.Data["Platform"] = data.Platform
	h.Data["PlatformFamily"] = data.PlatformFamily
	h.Data["PlatformVersion"] = data.PlatformVersion
	h.Data["VirtualizationSystem"] = data.VirtualizationSystem
	h.Data["VirtualizationRole"] = data.VirtualizationRole

	bootTime, err := gopsutil_host.BootTime()
	if err == nil {
		h.Data["BootTime"] = bootTime
	}

	return nil
}
开发者ID:simudream,项目名称:resourced,代码行数:24,代码来源:host.go


示例18: Main

func (c App) Main(admin *models.Admin) revel.Result {

	title := "首页--GoCMS管理系统"

	UserID := utils.GetSession("UserID", c.Session)

	if len(UserID) > 0 {
		UserID, err := strconv.ParseInt(UserID, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}

		admin_info := admin.GetById(UserID)

		//判断是否是系统的分隔符
		separator := "/"
		if os.IsPathSeparator('\\') {
			separator = "\\"
		} else {
			separator = "/"
		}

		config_file := (revel.BasePath + "/conf/config.conf")
		config_file = strings.Replace(config_file, "/", separator, -1)
		config_conf, _ := config.ReadDefault(config_file)

		system_info := make(map[string]string)

		//版本
		version, _ := config_conf.String("website", "website.version")
		system_info["version"] = version

		//前台网站地址
		sitedomain, _ := config_conf.String("website", "website.sitedomain")
		system_info["sitedomain"] = sitedomain

		//操作系统
		system_info["os"] = strings.ToUpper(runtime.GOOS + " " + runtime.GOARCH)

		//Go版本
		system_info["go_varsion"] = strings.ToUpper(runtime.Version())

		//Revel版本
		system_info["revel_varsion"] = strings.ToUpper("Revel 0.11")

		//MySQL版本
		system_info["mysql_varsion"] = admin.GetMysqlVer()

		//服务器监控
		memory_info, _ := mem.VirtualMemory()
		system_info["main_server_total_memory"] = utils.FileSize(int(memory_info.Total))
		system_info["main_server_free_memory"] = utils.FileSize(int(memory_info.Free))
		system_info["main_server_available_memory"] = utils.FileSize(int(memory_info.Available))
		system_info["main_server_UsedPercent_memory"] = fmt.Sprintf("%10.2f%%", memory_info.UsedPercent)

		host, _ := host.HostInfo()
		system_info["main_server_Hostname"] = host.Hostname
		system_info["main_server_OS"] = host.OS
		system_info["main_server_Platform"] = host.Platform
		system_info["main_server_PlatformVersion"] = host.PlatformVersion
		system_info["main_server_PlatformFamily"] = host.PlatformFamily

		//快捷面板
		admin_panel := new(models.Admin_Panel)
		panel_list := admin_panel.GetPanelList(admin_info)

		c.Render(title, admin_info, system_info, panel_list)
	} else {
		c.Render(title)
	}

	return c.RenderTemplate("App/Main.html")
}
开发者ID:chinanjjohn2012,项目名称:GoCMS,代码行数:73,代码来源:app.go


示例19: psutilHostDump

func psutilHostDump() {
	hostInfo, _ := host.HostInfo()
	Println(JsonPretty(*hostInfo))
}
开发者ID:suffuse,项目名称:go-suffuse,代码行数:4,代码来源:process.go


示例20: main

func main() {

	// DISK INFO

	fmt.Print("\n----Disk Info ----\n\n")
	diskInfo, err := disk.DiskPartitions(true)
	if err != nil {
		panic(err)
	}
	log.Printf("[DEBUG] %#v\n\n", diskInfo)

	for _, diskn := range diskInfo {
		fmt.Printf("%s %s\n", diskn.Device, diskn.Mountpoint)
	}

	// CPU INFO

	fmt.Print("\n----CPU Info ----\n\n")
	cpuInfo, err := cpu.CPUInfo()
	if err != nil {
		panic(err)
	}
	log.Printf("[DEBUG] %#v\n\n", cpuInfo)

	var totalCores int32
	var frequency float64
	var totalCompute float64
	var flags string

	for _, cpu := range cpuInfo {
		totalCores += cpu.Cores
		if frequency == 0 {
			frequency = cpu.Mhz
		} else {
			if frequency != cpu.Mhz {
				log.Printf("A CPU shows inconsistent frequency with other CPUs: baseline %f, abberant %f", frequency, frequency)
			}
		}
		flags = strings.Join(cpu.Flags, " ")
	}
	totalCompute = frequency * float64(totalCores)
	fmt.Printf("%s %d\n", "cpu.totalcores", totalCores)
	fmt.Printf("%s %d\n", "cpu.numcpus", len(cpuInfo))
	fmt.Printf("%s %f\n", "cpu.frequency", frequency)
	fmt.Printf("%s %f\n", "cpu.totalcompute", totalCompute)
	fmt.Printf("%s %s\n", "cpu.flags", flags)

	// MEMORY INFO

	fmt.Print("\n----Memory Info ----\n\n")
	memInfo, err := mem.VirtualMemory()
	if err != nil {
		panic(err)
	}
	log.Printf("[DEBUG] %#v\n\n", memInfo)

	fmt.Printf("%s %d\n", "memory.totalbytes", memInfo.Total)

	// HOST INFO

	fmt.Print("\n----Host Info ----\n\n")
	hostInfo, err := host.HostInfo()
	if err != nil {
		panic(err)
	}

	log.Printf("[DEBUG] %#v\n\n", hostInfo)

	fmt.Printf("%s %s\n", "hostInfo.Hostname       ", hostInfo.Hostname)
	fmt.Printf("%s %s\n", "hostInfo.OS             ", hostInfo.OS)
	fmt.Printf("%s %s\n", "hostInfo.Platform       ", hostInfo.Platform)
	fmt.Printf("%s %s\n", "hostInfo.PlatformVersion", hostInfo.PlatformVersion)
	fmt.Printf("%s %s\n", "hostInfo.PlatformFamily ", hostInfo.PlatformFamily)
}
开发者ID:cbednarski,项目名称:sysinfo,代码行数:74,代码来源:sysinfo.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang common.DoSysctrl函数代码示例发布时间:2022-05-28
下一篇:
Golang disk.DiskUsage函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap