本文整理匯總了Golang中github.com/elastic/gosigar.ConcreteSigar.GetLoadAverage方法的典型用法代碼示例。如果您正苦於以下問題:Golang ConcreteSigar.GetLoadAverage方法的具體用法?Golang ConcreteSigar.GetLoadAverage怎麽用?Golang ConcreteSigar.GetLoadAverage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/elastic/gosigar.ConcreteSigar
的用法示例。
在下文中一共展示了ConcreteSigar.GetLoadAverage方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetLoad1
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: GetSystemLoad
func GetSystemLoad() (*SystemLoad, error) {
concreteSigar := sigar.ConcreteSigar{}
avg, err := concreteSigar.GetLoadAverage()
if err != nil {
return nil, err
}
return &SystemLoad{
Load1: avg.One,
Load5: avg.Five,
Load15: avg.Fifteen,
}, nil
}
示例3: main
func main() {
concreteSigar := gosigar.ConcreteSigar{}
uptime := gosigar.Uptime{}
uptime.Get()
avg, err := concreteSigar.GetLoadAverage()
if err != nil {
fmt.Printf("Failed to get load average")
return
}
fmt.Fprintf(os.Stdout, " %s up %s load average: %.2f, %.2f, %.2f\n",
time.Now().Format("15:04:05"),
uptime.Format(),
avg.One, avg.Five, avg.Fifteen)
}
示例4: GetSystemLoad
func GetSystemLoad() (*SystemLoad, error) {
concreteSigar := sigar.ConcreteSigar{}
avg, err := concreteSigar.GetLoadAverage()
if err != nil {
return nil, err
}
cpuList := sigar.CpuList{}
cpuList.Get()
numCore := len(cpuList.List)
return &SystemLoad{
Load1: avg.One,
Load5: avg.Five,
Load15: avg.Fifteen,
LoadNorm1: avg.One / float64(numCore),
LoadNorm5: avg.Five / float64(numCore),
LoadNorm15: avg.Fifteen / float64(numCore),
}, nil
}
示例5:
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))
})