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


Golang FileSystemUsage.Get方法代码示例

本文整理汇总了Golang中github.com/cloudfoundry/gosigar.FileSystemUsage.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang FileSystemUsage.Get方法的具体用法?Golang FileSystemUsage.Get怎么用?Golang FileSystemUsage.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cloudfoundry/gosigar.FileSystemUsage的用法示例。


在下文中一共展示了FileSystemUsage.Get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetFileSystemList75

func GetFileSystemList75() []string {
	result := []string{}
	volumes := []sigar.FileSystem{}

	if runtime.GOOS == "windows" {
		volumes = getWindowsDrives()
	} else {
		fslist := sigar.FileSystemList{}
		fslist.Get()
		volumes = fslist.List
	}

	for _, volume := range volumes {
		dirName := volume.DirName
		usage := sigar.FileSystemUsage{}
		usage.Get(dirName)

		if usage.UsePercent() >= 75 {
			result = append(result, fmt.Sprintf("%s (%s)",
				dirName,
				sigar.FormatPercent(usage.UsePercent())))
		}
	}
	return result
}
开发者ID:tfksilent,项目名称:collector-sidecar,代码行数:25,代码来源:sigar.go

示例2: GetDiskStats

func (p ubuntu) GetDiskStats(mountedPath string) (stats DiskStats, err error) {
	fsUsage := sigar.FileSystemUsage{}
	err = fsUsage.Get(mountedPath)
	if err != nil {
		return
	}

	stats.Total = fsUsage.Total
	stats.Used = fsUsage.Used
	stats.InodeTotal = fsUsage.Files
	stats.InodeUsed = fsUsage.Files - fsUsage.FreeFiles

	return
}
开发者ID:simonleung8,项目名称:bosh,代码行数:14,代码来源:ubuntu_sys_stats.go

示例3: GetDiskStats

func (s sigarStatsCollector) GetDiskStats(mountedPath string) (stats DiskStats, err error) {
	fsUsage := sigar.FileSystemUsage{}
	err = fsUsage.Get(mountedPath)
	if err != nil {
		err = bosherr.WrapError(err, "Getting Sigar File System Usage")
		return
	}

	stats.Total = fsUsage.Total
	stats.Used = fsUsage.Used
	stats.InodeTotal = fsUsage.Files
	stats.InodeUsed = fsUsage.Files - fsUsage.FreeFiles

	return
}
开发者ID:ian-plosker,项目名称:bosh,代码行数:15,代码来源:sigar_stats_collector.go

示例4: postMetrics

func postMetrics() error {
	var metrics = make(map[string]interface{})
	// Runtime Info
	metrics["agent.runtime.numcpu"] = runtime.NumCPU()
	metrics["agent.runtime.numgoroutine"] = runtime.NumGoroutine()

	// System Info
	avg := sigar.LoadAverage{}
	mem := sigar.Mem{}
	swap := sigar.Swap{}
	avg.Get()
	mem.Get()
	swap.Get()

	metrics["agent.system.loadavg.one"] = avg.One
	metrics["agent.system.loadavg.five"] = avg.Five
	metrics["agent.system.loadavg.fifteen"] = avg.Fifteen
	metrics["agent.system.mem.total"] = mem.Total
	metrics["agent.system.mem.used"] = mem.Used
	metrics["agent.system.mem.free"] = mem.Free
	metrics["agent.system.mem.actual_used"] = mem.ActualUsed
	metrics["agent.system.mem.actual_free"] = mem.ActualFree
	metrics["agent.system.swap.total"] = swap.Total
	metrics["agent.system.swap.used"] = swap.Used
	metrics["agent.system.swap.free"] = swap.Free

	// Disk Info
	fslist := sigar.FileSystemList{}
	fslist.Get()
	for _, fs := range fslist.List {
		if strings.HasPrefix(fs.DevName, "/") {
			dirname := fs.DirName
			usage := sigar.FileSystemUsage{}
			usage.Get(dirname)
			metrics[fmt.Sprintf("agent.disk.%s.total", dirname)] = usage.Total
			metrics[fmt.Sprintf("agent.disk.%s.used", dirname)] = usage.Used
			metrics[fmt.Sprintf("agent.disk.%s.avail", dirname)] = usage.Avail
			metrics[fmt.Sprintf("agent.disk.%s.used_percent", dirname)] = usage.UsePercent()
		}
	}

	if client, err := models.NewCounterClient(nil); err != nil {
		return err
	} else {
		return client.PostMany("statsd", metrics)
	}
}
开发者ID:speedland,项目名称:agent,代码行数:47,代码来源:statsd.go

示例5: freeDisk

func freeDisk() uint64 {
	disk := sigar.FileSystemUsage{}
	workingDirectory, _ := os.Getwd()
	disk.Get(workingDirectory)
	return (disk.Avail / 1024)
}
开发者ID:jose-cardoso,项目名称:packer,代码行数:6,代码来源:resources_linux.go

示例6:

import (
	"os"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	sigar "github.com/cloudfoundry/gosigar"
)

var _ = Describe("SigarWindows", func() {
	Describe("Memory", func() {
		It("gets the total memory", func() {
			mem := sigar.Mem{}
			err := mem.Get()

			Ω(err).ShouldNot(HaveOccurred())
			Ω(mem.Total).Should(BeNumerically(">", 0))
		})
	})

	Describe("Disk", func() {
		It("gets the total disk space", func() {
			usage := sigar.FileSystemUsage{}
			err := usage.Get(os.TempDir())

			Ω(err).ShouldNot(HaveOccurred())
			Ω(usage.Total).Should(BeNumerically(">", 0))
		})
	})
})
开发者ID:BarthV,项目名称:gosigar,代码行数:30,代码来源:sigar_windows_test.go


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