sigar_windows.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright (c) 2012 VMware, Inc.
  2. package sigar
  3. // #include <stdlib.h>
  4. // #include <windows.h>
  5. import "C"
  6. import (
  7. "fmt"
  8. "unsafe"
  9. )
  10. func init() {
  11. }
  12. func (self *LoadAverage) Get() error {
  13. return nil
  14. }
  15. func (self *Uptime) Get() error {
  16. return nil
  17. }
  18. func (self *Mem) Get() error {
  19. var statex C.MEMORYSTATUSEX
  20. statex.dwLength = C.DWORD(unsafe.Sizeof(statex))
  21. succeeded := C.GlobalMemoryStatusEx(&statex)
  22. if succeeded == C.FALSE {
  23. lastError := C.GetLastError()
  24. return fmt.Errorf("GlobalMemoryStatusEx failed with error: %d", int(lastError))
  25. }
  26. self.Total = uint64(statex.ullTotalPhys)
  27. return nil
  28. }
  29. func (self *Swap) Get() error {
  30. return notImplemented()
  31. }
  32. func (self *Cpu) Get() error {
  33. return notImplemented()
  34. }
  35. func (self *CpuList) Get() error {
  36. return notImplemented()
  37. }
  38. func (self *FileSystemList) Get() error {
  39. return notImplemented()
  40. }
  41. func (self *ProcList) Get() error {
  42. return notImplemented()
  43. }
  44. func (self *ProcState) Get(pid int) error {
  45. return notImplemented()
  46. }
  47. func (self *ProcMem) Get(pid int) error {
  48. return notImplemented()
  49. }
  50. func (self *ProcTime) Get(pid int) error {
  51. return notImplemented()
  52. }
  53. func (self *ProcArgs) Get(pid int) error {
  54. return notImplemented()
  55. }
  56. func (self *ProcExe) Get(pid int) error {
  57. return notImplemented()
  58. }
  59. func (self *FileSystemUsage) Get(path string) error {
  60. var availableBytes C.ULARGE_INTEGER
  61. var totalBytes C.ULARGE_INTEGER
  62. var totalFreeBytes C.ULARGE_INTEGER
  63. pathChars := C.CString(path)
  64. defer C.free(unsafe.Pointer(pathChars))
  65. succeeded := C.GetDiskFreeSpaceEx((*C.CHAR)(pathChars), &availableBytes, &totalBytes, &totalFreeBytes)
  66. if succeeded == C.FALSE {
  67. lastError := C.GetLastError()
  68. return fmt.Errorf("GetDiskFreeSpaceEx failed with error: %d", int(lastError))
  69. }
  70. self.Total = *(*uint64)(unsafe.Pointer(&totalBytes))
  71. return nil
  72. }
  73. func notImplemented() error {
  74. panic("Not Implemented")
  75. return nil
  76. }