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


Golang Cpu.Get方法代碼示例

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


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

示例1: GetCpuTimes

func GetCpuTimes() (*CpuTimes, error) {

	cpu := sigar.Cpu{}
	err := cpu.Get()
	if err != nil {
		return nil, err
	}

	return &CpuTimes{Cpu: cpu}, nil
}
開發者ID:tfksilent,項目名稱:collector-sidecar,代碼行數:10,代碼來源:sigar.go

示例2: GetCpuStats

func (p ubuntu) GetCpuStats() (stats CpuStats, err error) {
	cpu := sigar.Cpu{}
	err = cpu.Get()
	if err != nil {
		return
	}

	stats.User = cpu.User
	stats.Sys = cpu.Sys
	stats.Wait = cpu.Wait
	stats.Total = cpu.Total()

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

示例3: GetCpuStats

func (s sigarStatsCollector) GetCpuStats() (stats CpuStats, err error) {
	cpu := sigar.Cpu{}
	err = cpu.Get()
	if err != nil {
		err = bosherr.WrapError(err, "Getting Sigar Cpu")
		return
	}

	stats.User = cpu.User
	stats.Sys = cpu.Sys
	stats.Wait = cpu.Wait
	stats.Total = cpu.Total()

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

示例4:

			statFile = procd + "/stat"

			cpu = sigar.Cpu{}

			statContents := []byte("cpu 25 1 2 3 4 5 6 7")
			err = ioutil.WriteFile(statFile, statContents, 0644)
			Expect(err).ToNot(HaveOccurred())
		})

		AfterEach(func() {
			sigar.Procd = "/proc"
		})

		Describe("Get", func() {
			It("gets CPU usage", func() {
				err := cpu.Get()
				Expect(err).ToNot(HaveOccurred())
				Expect(cpu.User).To(Equal(uint64(25)))
			})
		})

		Describe("CollectCpuStats", func() {
			It("collects CPU usage over time", func() {
				concreteSigar := &sigar.ConcreteSigar{}
				cpuUsages, stop := concreteSigar.CollectCpuStats(500 * time.Millisecond)

				Expect(<-cpuUsages).To(Equal(sigar.Cpu{
					User:    uint64(25),
					Nice:    uint64(1),
					Sys:     uint64(2),
					Idle:    uint64(3),
開發者ID:BarthV,項目名稱:gosigar,代碼行數:31,代碼來源:sigar_linux_test.go

示例5:

			statFile string
			cpu      sigar.Cpu
		)

		BeforeEach(func() {
			statFile = procd + "/stat"
			cpu = sigar.Cpu{}
		})

		Describe("Get", func() {
			It("gets CPU usage", func() {
				statContents := []byte("cpu 25 1 2 3 4 5 6 7")
				err := ioutil.WriteFile(statFile, statContents, 0644)
				Expect(err).ToNot(HaveOccurred())

				err = cpu.Get()
				Expect(err).ToNot(HaveOccurred())
				Expect(cpu.User).To(Equal(uint64(25)))
			})

			It("ignores empty lines", func() {
				statContents := []byte("cpu ")
				err := ioutil.WriteFile(statFile, statContents, 0644)
				Expect(err).ToNot(HaveOccurred())

				err = cpu.Get()
				Expect(err).ToNot(HaveOccurred())
				Expect(cpu.User).To(Equal(uint64(0)))
			})
		})
開發者ID:msempere,項目名稱:gosigar,代碼行數:30,代碼來源:sigar_linux_test.go


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