Пример #1
0
func GetLoad1() float64 {
	concreteSigar := sigar.ConcreteSigar{}

	avg, err := concreteSigar.GetLoadAverage()
	if err != nil {
		log.Debug("Failed to get load average")
		return -1
	}

	return avg.One
}
Пример #2
0
		It("does not block", func() {
			_, stop := concreteSigar.CollectCPUStats(10 * time.Millisecond)

			// Sleep long enough for samplesCh to fill at least 2 values
			time.Sleep(20 * time.Millisecond)

			stop <- struct{}{}

			// If CollectCPUStats blocks it will never get here
			Expect(true).To(BeTrue())
		})
	})

	It("GetLoadAverage", func() {
		avg, err := concreteSigar.GetLoadAverage()
		Expect(avg.One).ToNot(BeNil())
		Expect(avg.Five).ToNot(BeNil())
		Expect(avg.Fifteen).ToNot(BeNil())

		Expect(err).ToNot(HaveOccurred())
	})

	It("GetMem", func() {
		mem, err := concreteSigar.GetMem()
		Expect(err).ToNot(HaveOccurred())

		Expect(mem.Total).To(BeNumerically(">", 0))
		Expect(mem.Used + mem.Free).To(BeNumerically("<=", mem.Total))
	})