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


Golang gosigar.Mem類代碼示例

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


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

示例1: TestUbuntuCalculateEphemeralDiskPartitionSizesWhenDiskTwiceTheMemoryOrSmaller

func TestUbuntuCalculateEphemeralDiskPartitionSizesWhenDiskTwiceTheMemoryOrSmaller(t *testing.T) {
	memStats := sigar.Mem{}
	memStats.Get()
	totalMemInKb := memStats.Total
	totalMemInBlocks := totalMemInKb * uint64(1024/512)

	diskSizeInBlocks := totalMemInBlocks*2 - 1
	expectedSwap := diskSizeInBlocks / 2
	testUbuntuCalculateEphemeralDiskPartitionSizes(t, diskSizeInBlocks, expectedSwap)
}
開發者ID:simonleung8,項目名稱:bosh,代碼行數:10,代碼來源:ubuntu_test.go

示例2: GetMemStats

func (p ubuntu) GetMemStats() (stats MemStats, err error) {
	mem := sigar.Mem{}
	err = mem.Get()
	if err != nil {
		return
	}

	stats.Total = mem.Total
	stats.Used = mem.Used

	return
}
開發者ID:simonleung8,項目名稱:bosh,代碼行數:12,代碼來源:ubuntu_sys_stats.go

示例3: GetMemStats

func (s sigarStatsCollector) GetMemStats() (stats MemStats, err error) {
	mem := sigar.Mem{}
	err = mem.Get()
	if err != nil {
		return
	}

	stats.Total = mem.Total
	stats.Used = mem.Used

	return
}
開發者ID:joanesespanol,項目名稱:bosh,代碼行數:12,代碼來源:sigar_stats_collector.go

示例4: GetMemStats

func (s sigarStatsCollector) GetMemStats() (stats MemStats, err error) {
	mem := sigar.Mem{}
	err = mem.Get()
	if err != nil {
		err = bosherr.WrapError(err, "Getting Sigar Mem")
		return
	}

	stats.Total = mem.Total
	stats.Used = mem.Used

	return
}
開發者ID:ian-plosker,項目名稱:bosh,代碼行數:13,代碼來源:sigar_stats_collector.go

示例5: 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

示例6:

HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       59328 kB
DirectMap2M:      333824 kB
`
			err := ioutil.WriteFile(meminfoFile, []byte(meminfoContents), 0444)
			Expect(err).ToNot(HaveOccurred())
		})

		It("returns correct memory info", func() {
			mem := sigar.Mem{}
			err := mem.Get()
			Expect(err).ToNot(HaveOccurred())

			Expect(mem.Total).To(BeNumerically("==", 374256*1024))
			Expect(mem.Free).To(BeNumerically("==", 274460*1024))
		})
	})

	Describe("Swap", func() {
		var meminfoFile string
		BeforeEach(func() {
			meminfoFile = procd + "/meminfo"

			meminfoContents := `
MemTotal:         374256 kB
開發者ID:simudream,項目名稱:resourced,代碼行數:31,代碼來源:sigar_linux_test.go

示例7: freeMem

func freeMem() uint64 {
	mem := sigar.Mem{}
	mem.Get()
	return (mem.Free / 1024 / 1024)
}
開發者ID:jose-cardoso,項目名稱:packer,代碼行數:5,代碼來源:resources_linux.go


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