rollback vDisk parsing for now

This commit is contained in:
Adrian Todorov 2018-09-16 15:39:38 +02:00
parent 23505fb8d3
commit 9094700d21
2 changed files with 54 additions and 21 deletions

39
Gopkg.lock generated
View File

@ -2,32 +2,65 @@
[[projects]] [[projects]]
digest = "1:56c130d885a4aacae1dd9c7b71cfe39912c7ebc1ff7d2b46083c8812996dc43b"
name = "github.com/davecgh/go-spew" name = "github.com/davecgh/go-spew"
packages = ["spew"] packages = ["spew"]
pruneopts = ""
revision = "346938d642f2ec3594ed81d874461961cd0faa76" revision = "346938d642f2ec3594ed81d874461961cd0faa76"
version = "v1.1.0" version = "v1.1.0"
[[projects]] [[projects]]
digest = "1:ec837623c12abf4f44837163ad32274dd0c9dfa29f0d65068c60897bce34bb75"
name = "github.com/influxdata/influxdb" name = "github.com/influxdata/influxdb"
packages = ["client/v2","models","pkg/escape"] packages = [
"client/v2",
"models",
"pkg/escape",
]
pruneopts = ""
revision = "a7c3d3c0f7b74f71919047adbc4933460967a576" revision = "a7c3d3c0f7b74f71919047adbc4933460967a576"
version = "v1.3.6" version = "v1.3.6"
[[projects]] [[projects]]
digest = "1:c5342f3ddefc1644d1a3ed028e739bfabe5b457978084b9a28d42ed235c8bb4d"
name = "github.com/vmware/govmomi" name = "github.com/vmware/govmomi"
packages = [".","property","session","vim25","vim25/debug","vim25/methods","vim25/mo","vim25/progress","vim25/soap","vim25/types","vim25/xml"] packages = [
".",
"property",
"session",
"vim25",
"vim25/debug",
"vim25/methods",
"vim25/mo",
"vim25/progress",
"vim25/soap",
"vim25/types",
"vim25/xml",
]
pruneopts = ""
revision = "b63044e5f833781eb7b305bc035392480ee06a82" revision = "b63044e5f833781eb7b305bc035392480ee06a82"
version = "v0.15.0" version = "v0.15.0"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:70ca15641aa31be55859a7f75ddef3ae384ae18068deab8274668a1a77d1e84a"
name = "golang.org/x/net" name = "golang.org/x/net"
packages = ["context"] packages = ["context"]
pruneopts = ""
revision = "4b14673ba32bee7f5ac0f990a48f033919fd418b" revision = "4b14673ba32bee7f5ac0f990a48f033919fd418b"
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
inputs-digest = "0b7718e6a338978c4ea1efca3255565c667967ddd6ff68999a1d1cea5112209e" input-imports = [
"github.com/davecgh/go-spew/spew",
"github.com/influxdata/influxdb/client/v2",
"github.com/vmware/govmomi",
"github.com/vmware/govmomi/property",
"github.com/vmware/govmomi/vim25/methods",
"github.com/vmware/govmomi/vim25/mo",
"github.com/vmware/govmomi/vim25/types",
"golang.org/x/net/context",
]
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

View File

@ -47,12 +47,12 @@ const (
// Configuration is used to store config data // Configuration is used to store config data
type Configuration struct { type Configuration struct {
VCenters []*VCenter VCenters []*VCenter
Metrics []Metric Metrics []Metric
Interval int Interval int
Domain string Domain string
RemoveHostDomainName bool RemoveHostDomainName bool
InfluxDB InfluxDB InfluxDB InfluxDB
} }
// InfluxDB is used for InfluxDB connections // InfluxDB is used for InfluxDB connections
@ -390,7 +390,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
hostToCluster := make(map[types.ManagedObjectReference]string) hostToCluster := make(map[types.ManagedObjectReference]string)
// Initialize the map that will hold the vDisk UUID per VM MOR to datastore reference // Initialize the map that will hold the vDisk UUID per VM MOR to datastore reference
vDiskToDatastore := make(map[types.ManagedObjectReference]map[string]string) // vDiskToDatastore := make(map[types.ManagedObjectReference]map[string]string)
// Retrieve properties for clusters, if any // Retrieve properties for clusters, if any
if len(clusterRefs) > 0 { if len(clusterRefs) > 0 {
@ -473,15 +473,15 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
vmSummary[vm.Self]["datastore"] = strings.Replace(strings.Replace(re.FindString(fmt.Sprintln(vm.Summary.Config)), "[", "", -1), "]", "", -1) vmSummary[vm.Self]["datastore"] = strings.Replace(strings.Replace(re.FindString(fmt.Sprintln(vm.Summary.Config)), "[", "", -1), "]", "", -1)
// List all devices to get vDisks // List all devices to get vDisks
for _, device := range vm.Config.Hardware.Device { // for _, device := range vm.Config.Hardware.Device {
// Hacky way to check if it's a vDisk and if it's datastore is different than the main one for VM // // Hacky way to check if it's a vDisk and if it's datastore is different than the main one for VM
if device.Backing.FileName != nil && device.Backing.Datastore.Name != vmSummary[vm.Self]["datastore"] { // if device.Backing.FileName != nil && device.Backing.Datastore.Name != vmSummary[vm.Self]["datastore"] {
if vDiskToDatastore[vm.Self] == nil { // if vDiskToDatastore[vm.Self] == nil {
vDiskToDatastore[vm.Self] = make(map[string]string) // vDiskToDatastore[vm.Self] = make(map[string]string)
} // }
vDiskToDatastore[vm.Self][device.diskObjectId] = device.Backing.Datastore.Name // vDiskToDatastore[vm.Self][device.diskObjectId] = device.Backing.Datastore.Name
} // }
} // }
if vmToCluster[vm.Self] != "" { if vmToCluster[vm.Self] != "" {
vmSummary[vm.Self]["cluster"] = vmToCluster[vm.Self] vmSummary[vm.Self]["cluster"] = vmToCluster[vm.Self]
@ -497,8 +497,8 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
vmExtraMetrics[vm.Self] = make(map[string]int64) vmExtraMetrics[vm.Self] = make(map[string]int64)
vmExtraMetrics[vm.Self]["uptime"] = int64(vm.Summary.QuickStats.UptimeSeconds) vmExtraMetrics[vm.Self]["uptime"] = int64(vm.Summary.QuickStats.UptimeSeconds)
} }
fmt.Println("vDiskDatastore:") // fmt.Println("vDiskDatastore:")
spew.Dump(vDiskToDatastore) // spew.Dump(vDiskToDatastore)
// get object names // get object names
objects := []mo.ManagedEntity{} objects := []mo.ManagedEntity{}
@ -724,7 +724,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
datastoreFields := map[string]interface{}{ datastoreFields := map[string]interface{}{
"capacity": datastore.Summary.Capacity, "capacity": datastore.Summary.Capacity,
"free_space": datastore.Summary.FreeSpace, "free_space": datastore.Summary.FreeSpace,
"usage": 1.0 - (float64(datastore.Summary.FreeSpace)/float64(datastore.Summary.Capacity)), "usage": 1.0 - (float64(datastore.Summary.FreeSpace) / float64(datastore.Summary.Capacity)),
} }
datastoreTags := map[string]string{"ds_name": datastore.Summary.Name, "host": vcName} datastoreTags := map[string]string{"ds_name": datastore.Summary.Name, "host": vcName}
pt4, err := influxclient.NewPoint(config.InfluxDB.Prefix+"datastore", datastoreTags, datastoreFields, time.Now()) pt4, err := influxclient.NewPoint(config.InfluxDB.Prefix+"datastore", datastoreTags, datastoreFields, time.Now())