-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdisk.go
More file actions
111 lines (89 loc) · 2.01 KB
/
disk.go
File metadata and controls
111 lines (89 loc) · 2.01 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package ontap
import (
"bytes"
"encoding/xml"
"fmt"
"github.com/go-xmlfmt/xmlfmt"
"net/http"
"strings"
)
type DiskInfo struct {
Name string
DiskType string
Model string
Online bool
Prefailed bool
Spare bool
}
func (c *Client) GetDiskInfo() ([]DiskInfo, error) {
ixml := &DiskInfoRequest{}
ixml.Version = apiVersion
ixml.Xmlns = XMLns
output, err := xml.MarshalIndent(ixml, "", "\t")
payload := bytes.NewReader(output)
req, err := http.NewRequest("POST", c.Url, payload)
if err != nil {
return nil, err
}
response, err := c.doRequest(req)
if err != nil {
return nil, err
}
if c.Debug {
x := xmlfmt.FormatXML(string(response), "\t", " ")
println(x)
}
var result DiskInfoResponse
err = xml.Unmarshal(response, &result)
if err != nil {
return nil, err
}
if strings.Compare(result.Results.Status, "passed") != 0 {
return nil, fmt.Errorf("%s", xmlError)
}
var ail []DiskInfo
for _, v := range result.Results.AttributesList.StorageDiskInfo {
online := true
if v.DiskRaidInfo.DiskAggregateInfo.IsOffline == "true" {
online = false
}
prefailed := false
if v.DiskRaidInfo.DiskAggregateInfo.IsPrefailed == "true" {
prefailed = true
}
spare := false
if v.DiskRaidInfo.ContainerType == "spare" {
spare = true
}
ai := DiskInfo{
Name: v.DiskName,
DiskType: v.DiskInventoryInfo.DiskType,
Model: v.DiskInventoryInfo.Model,
Online: online,
Prefailed: prefailed,
Spare: spare,
}
ail = append(ail, ai)
}
return ail, nil
}
func (c *Client) GetDiskPerf() ([]PerfCounter, error) {
// Performance counters of interest
var counters []string
counters = append(counters, "base_for_disk_busy")
counters = append(counters, "disk_busy")
counters = append(counters, "name")
var inst []string
agi, err := c.GetDiskInfo()
if err != nil {
return nil, err
}
for _, v := range agi {
inst = append(inst, v.Name)
}
pc, err := c.getPerformanceData("disk", counters, inst)
if err != nil {
return nil, err
}
return pc, nil
}