Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into windows_installer_a…
Browse files Browse the repository at this point in the history
…lpha
  • Loading branch information
mechairoi committed Feb 9, 2015
2 parents 87d30a1 + 44c2773 commit b6a4241
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 31 deletions.
6 changes: 3 additions & 3 deletions metrics/windows/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ func (g *DiskGenerator) Generate() (metrics.Values, error) {

results := make(map[string]float64)
for _, v := range g.counters {
var value windows.PDH_FMT_COUNTERVALUE_ITEM_DOUBLE
r, _, err := windows.PdhGetFormattedCounterValue.Call(uintptr(v.Counter), windows.PDH_FMT_DOUBLE, uintptr(0), uintptr(unsafe.Pointer(&value.FmtValue)))
var fmtValue windows.PDH_FMT_COUNTERVALUE_DOUBLE
r, _, err := windows.PdhGetFormattedCounterValue.Call(uintptr(v.Counter), windows.PDH_FMT_DOUBLE, uintptr(0), uintptr(unsafe.Pointer(&fmtValue)))
if r != 0 && r != windows.PDH_INVALID_DATA {
return nil, err
}
results[v.PostName] = value.FmtValue.DoubleValue
results[v.PostName] = fmtValue.DoubleValue
}

diskLogger.Debugf("%q", results)
Expand Down
6 changes: 3 additions & 3 deletions metrics/windows/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ func (g *InterfaceGenerator) Generate() (metrics.Values, error) {

results := make(map[string]float64)
for _, v := range g.counters {
var value windows.PDH_FMT_COUNTERVALUE_ITEM_DOUBLE
r, _, err := windows.PdhGetFormattedCounterValue.Call(uintptr(v.Counter), windows.PDH_FMT_DOUBLE, uintptr(0), uintptr(unsafe.Pointer(&value.FmtValue)))
var fmtValue windows.PDH_FMT_COUNTERVALUE_DOUBLE
r, _, err := windows.PdhGetFormattedCounterValue.Call(uintptr(v.Counter), windows.PDH_FMT_DOUBLE, uintptr(0), uintptr(unsafe.Pointer(&fmtValue)))
if r != 0 && r != windows.PDH_INVALID_DATA {
return nil, err
}
results[v.PostName] = value.FmtValue.DoubleValue
results[v.PostName] = fmtValue.DoubleValue
}

interfaceLogger.Debugf("%q", results)
Expand Down
6 changes: 3 additions & 3 deletions metrics/windows/loadavg5.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ func (g *Loadavg5Generator) Generate() (metrics.Values, error) {

results := make(map[string]float64)
for _, v := range g.counters {
var value windows.PDH_FMT_COUNTERVALUE_ITEM_DOUBLE
r, _, err := windows.PdhGetFormattedCounterValue.Call(uintptr(v.Counter), windows.PDH_FMT_DOUBLE, uintptr(0), uintptr(unsafe.Pointer(&value.FmtValue)))
var fmtValue windows.PDH_FMT_COUNTERVALUE_DOUBLE
r, _, err := windows.PdhGetFormattedCounterValue.Call(uintptr(v.Counter), windows.PDH_FMT_DOUBLE, uintptr(0), uintptr(unsafe.Pointer(&fmtValue)))
if r != 0 && r != windows.PDH_INVALID_DATA {
return nil, err
}
results[v.PostName] = value.FmtValue.DoubleValue
results[v.PostName] = fmtValue.DoubleValue
}

loadavg5Logger.Debugf("loadavg5: %q", results)
Expand Down
12 changes: 0 additions & 12 deletions util/util_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@ func RunCommand(command string) (string, string, error) {
return string(outBuffer.Bytes()), string(errBuffer.Bytes()), nil
}

// FilesystemInfo XXX
type FilesystemInfo struct {
PercentUsed string
KbUsed float64
KbSize float64
KbAvailable float64
Mount string
Label string
VolumeName string
FsType string
}

// GetWmic XXX
func GetWmic(target string, query string) (string, error) {
cpuGet, err := exec.Command("wmic", target, "get", query).Output()
Expand Down
19 changes: 15 additions & 4 deletions util/windows/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,25 @@ import (
"strings"
"syscall"
"unsafe"
"github.com/mackerelio/mackerel-agent/util"
)

// FilesystemInfo XXX
type FilesystemInfo struct {
PercentUsed string
KbUsed float64
KbSize float64
KbAvailable float64
Mount string
Label string
VolumeName string
FsType string
}

var windowsLogger = logging.GetLogger("windows")

// CollectFilesystemValues XXX
func CollectFilesystemValues() (map[string]util.FilesystemInfo, error) {
filesystems := make(map[string]util.FilesystemInfo)
func CollectFilesystemValues() (map[string]FilesystemInfo, error) {
filesystems := make(map[string]FilesystemInfo)

drivebuf := make([]byte, 256)

Expand Down Expand Up @@ -73,7 +84,7 @@ func CollectFilesystemValues() (map[string]util.FilesystemInfo, error) {
if r == 0 {
continue
}
filesystems[drive] = util.FilesystemInfo{
filesystems[drive] = FilesystemInfo{
PercentUsed: fmt.Sprintf("%d%%", 100*(totalNumberOfBytes-freeBytesAvailable)/totalNumberOfBytes),
KbUsed: float64((totalNumberOfBytes - freeBytesAvailable) / 1024),
KbSize: float64(totalNumberOfBytes / 1024),
Expand Down
6 changes: 0 additions & 6 deletions util/windows/windows_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ type PDH_FMT_COUNTERVALUE_DOUBLE struct {
DoubleValue float64
}

// PDH_FMT_COUNTERVALUE_ITEM_DOUBLE XXX
type PDH_FMT_COUNTERVALUE_ITEM_DOUBLE struct {
Name *uint16
FmtValue PDH_FMT_COUNTERVALUE_DOUBLE
}

// windows system const
const (
ERROR_SUCCESS = 0
Expand Down

0 comments on commit b6a4241

Please sign in to comment.