forked from mackerelio/mackerel-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
disk.go
55 lines (45 loc) · 1.28 KB
/
disk.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// +build windows
package windows
import (
"fmt"
"time"
"github.com/StackExchange/wmi"
"github.com/mackerelio/golib/logging"
"github.com/mackerelio/mackerel-agent/metrics"
)
// DiskGenerator XXX
type DiskGenerator struct {
Interval time.Duration
}
var diskLogger = logging.GetLogger("metrics.disk")
// NewDiskGenerator XXX
func NewDiskGenerator(interval time.Duration) (*DiskGenerator, error) {
return &DiskGenerator{interval}, nil
}
type win32PerfFormattedDataPerfDiskPhysicalDisk struct {
Name string
DiskReadsPerSec uint64
DiskWritesPerSec uint64
}
// Generate XXX
func (g *DiskGenerator) Generate() (metrics.Values, error) {
time.Sleep(g.Interval)
var records []win32PerfFormattedDataPerfDiskPhysicalDisk
err := wmi.Query("SELECT * FROM Win32_PerfFormattedData_PerfDisk_LogicalDisk ", &records)
if err != nil {
return nil, err
}
results := make(map[string]float64)
for _, record := range records {
name := record.Name
// Collect metrics for only drives
if len(name) != 2 || name[1] != ':' {
continue
}
name = name[:1]
results[fmt.Sprintf(`disk.%s.reads.delta`, name)] = float64(record.DiskReadsPerSec)
results[fmt.Sprintf(`disk.%s.writes.delta`, name)] = float64(record.DiskWritesPerSec)
}
diskLogger.Debugf("%q", results)
return results, nil
}