本文整理匯總了Golang中github.com/elastic/gosigar.Swap類的典型用法代碼示例。如果您正苦於以下問題:Golang Swap類的具體用法?Golang Swap怎麽用?Golang Swap使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Swap類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetSwap
func GetSwap() (*SwapStat, error) {
swap := sigar.Swap{}
err := swap.Get()
if err != nil {
return nil, err
}
return &SwapStat{Swap: swap}, nil
}
示例2: GetSwap
func GetSwap() (*SwapStat, error) {
swap := sigar.Swap{}
err := swap.Get()
if err != nil {
return nil, err
}
return &SwapStat{
Total: swap.Total,
Used: swap.Used,
Free: swap.Free,
}, nil
}
示例3: main
func main() {
mem := gosigar.Mem{}
swap := gosigar.Swap{}
mem.Get()
swap.Get()
fmt.Fprintf(os.Stdout, "%18s %10s %10s\n",
"total", "used", "free")
fmt.Fprintf(os.Stdout, "Mem: %10d %10d %10d\n",
format(mem.Total), format(mem.Used), format(mem.Free))
fmt.Fprintf(os.Stdout, "-/+ buffers/cache: %10d %10d\n",
format(mem.ActualUsed), format(mem.ActualFree))
fmt.Fprintf(os.Stdout, "Swap: %10d %10d %10d\n",
format(swap.Total), format(swap.Used), format(swap.Free))
}
示例4:
WritebackTmp: 0 kB
CommitLimit: 973556 kB
Committed_AS: 55880 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 21428 kB
VmallocChunk: 34359713596 kB
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() {
swap := sigar.Swap{}
err := swap.Get()
Expect(err).ToNot(HaveOccurred())
Expect(swap.Total).To(BeNumerically("==", 786428*1024))
Expect(swap.Free).To(BeNumerically("==", 786428*1024))
})
})
})
示例5: TestLinuxMemAndSwap
func TestLinuxMemAndSwap(t *testing.T) {
setUp(t)
defer tearDown(t)
meminfoContents := `
MemTotal: 374256 kB
MemFree: 274460 kB
Buffers: 9764 kB
Cached: 38648 kB
SwapCached: 0 kB
Active: 33772 kB
Inactive: 31184 kB
Active(anon): 16572 kB
Inactive(anon): 552 kB
Active(file): 17200 kB
Inactive(file): 30632 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 786428 kB
SwapFree: 786428 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 16564 kB
Mapped: 6612 kB
Shmem: 584 kB
Slab: 19092 kB
SReclaimable: 9128 kB
SUnreclaim: 9964 kB
KernelStack: 672 kB
PageTables: 1864 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 973556 kB
Committed_AS: 55880 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 21428 kB
VmallocChunk: 34359713596 kB
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
`
meminfoFile := procd + "/meminfo"
err := ioutil.WriteFile(meminfoFile, []byte(meminfoContents), 0444)
if err != nil {
t.Fatal(err)
}
mem := sigar.Mem{}
if assert.NoError(t, mem.Get()) {
assert.Equal(t, uint64(374256*1024), mem.Total)
assert.Equal(t, uint64(274460*1024), mem.Free)
}
swap := sigar.Swap{}
if assert.NoError(t, swap.Get()) {
assert.Equal(t, uint64(786428*1024), swap.Total)
assert.Equal(t, uint64(786428*1024), swap.Free)
}
}