forked from jirs5/gosigar-freebsd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix sigar_unix file to not compile on windows - Start work on windows implementation
- Loading branch information
Brannon
authored and
Max Brunsfeld
committed
Jun 25, 2014
1 parent
3641d81
commit 7f596b5
Showing
3 changed files
with
134 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright (c) 2012 VMware, Inc. | ||
|
||
package sigar | ||
|
||
// #include <stdlib.h> | ||
// #include <windows.h> | ||
import "C" | ||
|
||
import ( | ||
"fmt" | ||
"unsafe" | ||
) | ||
|
||
func init() { | ||
} | ||
|
||
func (self *LoadAverage) Get() error { | ||
return nil | ||
} | ||
|
||
func (self *Uptime) Get() error { | ||
return nil | ||
} | ||
|
||
func (self *Mem) Get() error { | ||
var statex C.MEMORYSTATUSEX | ||
statex.dwLength = C.DWORD(unsafe.Sizeof(statex)) | ||
|
||
succeeded := C.GlobalMemoryStatusEx(&statex) | ||
if succeeded == C.FALSE { | ||
lastError := C.GetLastError() | ||
return fmt.Errorf("GlobalMemoryStatusEx failed with error: %d", int(lastError)) | ||
} | ||
|
||
self.Total = uint64(statex.ullTotalPhys) | ||
return nil | ||
} | ||
|
||
func (self *Swap) Get() error { | ||
return notImplemented() | ||
} | ||
|
||
func (self *Cpu) Get() error { | ||
return notImplemented() | ||
} | ||
|
||
func (self *CpuList) Get() error { | ||
return notImplemented() | ||
} | ||
|
||
func (self *FileSystemList) Get() error { | ||
return notImplemented() | ||
} | ||
|
||
func (self *ProcList) Get() error { | ||
return notImplemented() | ||
} | ||
|
||
func (self *ProcState) Get(pid int) error { | ||
return notImplemented() | ||
} | ||
|
||
func (self *ProcMem) Get(pid int) error { | ||
return notImplemented() | ||
} | ||
|
||
func (self *ProcTime) Get(pid int) error { | ||
return notImplemented() | ||
} | ||
|
||
func (self *ProcArgs) Get(pid int) error { | ||
return notImplemented() | ||
} | ||
|
||
func (self *ProcExe) Get(pid int) error { | ||
return notImplemented() | ||
} | ||
|
||
func (self *FileSystemUsage) Get(path string) error { | ||
var availableBytes C.ULARGE_INTEGER | ||
var totalBytes C.ULARGE_INTEGER | ||
var totalFreeBytes C.ULARGE_INTEGER | ||
|
||
pathChars := C.CString(path) | ||
defer C.free(unsafe.Pointer(pathChars)) | ||
|
||
succeeded := C.GetDiskFreeSpaceEx((*C.CHAR)(pathChars), &availableBytes, &totalBytes, &totalFreeBytes) | ||
if succeeded == C.FALSE { | ||
lastError := C.GetLastError() | ||
return fmt.Errorf("GetDiskFreeSpaceEx failed with error: %d", int(lastError)) | ||
} | ||
|
||
self.Total = *(*uint64)(unsafe.Pointer(&totalBytes)) | ||
return nil | ||
} | ||
|
||
func notImplemented() error { | ||
panic("Not Implemented") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package sigar_test | ||
|
||
import ( | ||
"os" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
sigar "github.com/cloudfoundry/gosigar" | ||
) | ||
|
||
var _ = Describe("SigarWindows", func() { | ||
Describe("Memory", func() { | ||
It("gets the total memory", func() { | ||
mem := sigar.Mem{} | ||
err := mem.Get() | ||
|
||
Ω(err).ShouldNot(HaveOccurred()) | ||
Ω(mem.Total).Should(BeNumerically(">", 0)) | ||
}) | ||
}) | ||
|
||
Describe("Disk", func() { | ||
It("gets the total disk space", func() { | ||
usage := sigar.FileSystemUsage{} | ||
err := usage.Get(os.TempDir()) | ||
|
||
Ω(err).ShouldNot(HaveOccurred()) | ||
Ω(usage.Total).Should(BeNumerically(">", 0)) | ||
}) | ||
}) | ||
}) |