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


Golang gosigar.Cpu類代碼示例

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


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

示例1: TestLinuxCPU

func TestLinuxCPU(t *testing.T) {
	setUp(t)
	defer tearDown(t)

	tests := []struct {
		stat string
		user uint64
	}{
		{"cpu 25 1 2 3 4 5 6 7", 25},
		// Ignore empty lines
		{"cpu ", 0},
	}

	statFile := procd + "/stat"
	for _, test := range tests {
		func() {
			statContents := []byte(test.stat)
			err := ioutil.WriteFile(statFile, statContents, 0644)
			if err != nil {
				t.Fatal(err)
			}
			defer os.RemoveAll(statFile)

			cpu := sigar.Cpu{}
			if assert.NoError(t, cpu.Get()) {
				assert.Equal(t, uint64(test.user), cpu.User, "cpu.User")
			}
		}()
	}
}
開發者ID:mponton,項目名稱:gosigar,代碼行數:30,代碼來源:sigar_linux_test.go

示例2: GetCpuTimes

func GetCpuTimes() (*CpuTimes, error) {

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

	return &CpuTimes{Cpu: cpu}, nil
}
開發者ID:andrewkroh,項目名稱:beats,代碼行數:10,代碼來源:helper.go

示例3: GetCpuTimes

func GetCpuTimes() (*CpuTimes, error) {

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

	return &CpuTimes{
		User:    cpu.User,
		Nice:    cpu.Nice,
		System:  cpu.Sys,
		Idle:    cpu.Idle,
		IOWait:  cpu.Wait,
		Irq:     cpu.Irq,
		SoftIrq: cpu.SoftIrq,
		Steal:   cpu.Stolen,
	}, nil
}
開發者ID:Ingensi,項目名稱:dockerbeat,代碼行數:19,代碼來源:sigar.go

示例4:

		It("Knows the process name", func() {
			writePidStats(pid, "cron", pidStatFile)
			state.Get(pid)
			Expect(state.Name).To(Equal("cron"))
		})

		It("Can handle spaces in the process name", func() {
			writePidStats(pid, "a very long process name", pidStatFile)
			state.Get(pid)
			Expect(state.Name).To(Equal("a very long process name"))
		})
	})

	Describe("CPU", func() {
		var (
			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())
開發者ID:davidsoloman,項目名稱:beats,代碼行數:32,代碼來源:sigar_linux_test.go


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