mirror of
https://github.com/Oxalide/vsphere-influxdb-go.git
synced 2023-10-10 11:36:51 +00:00
"Final Version with ResourcePool"
This commit is contained in:
parent
84d9145c93
commit
893e1fead9
@ -16,7 +16,7 @@
|
|||||||
},
|
},
|
||||||
"Metrics": [
|
"Metrics": [
|
||||||
{
|
{
|
||||||
"ObjectType": [ "VirtualMachine", "HostSystem", "ResourcePool" ],
|
"ObjectType": [ "VirtualMachine", "HostSystem" ],
|
||||||
"Definition": [
|
"Definition": [
|
||||||
{ "Metric": "cpu.usage.average", "Instances": "*" },
|
{ "Metric": "cpu.usage.average", "Instances": "*" },
|
||||||
{ "Metric": "cpu.usage.maximum", "Instances": "*" },
|
{ "Metric": "cpu.usage.maximum", "Instances": "*" },
|
||||||
@ -64,18 +64,6 @@
|
|||||||
{ "Metric": "disk.numberWriteAveraged.average", "Instances": "*" },
|
{ "Metric": "disk.numberWriteAveraged.average", "Instances": "*" },
|
||||||
{ "Metric": "net.throughput.contention.summation", "Instances": "*" }
|
{ "Metric": "net.throughput.contention.summation", "Instances": "*" }
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
{
|
|
||||||
"ObjectType": [ "ResourcePool" ],
|
|
||||||
"Definition": [
|
|
||||||
{ "Metric": "cpu.usagemhz.average", "Instances": "*" },
|
|
||||||
{ "Metric": "cpu.cpuentitlement.latest", "Instances": "*" },
|
|
||||||
{ "Metric": "mem.mementitlement.latest", "Instances": "*" },
|
|
||||||
{ "Metric": "mem.consumed.average", "Instances": "*" },
|
|
||||||
{ "Metric": "mem.granted.average", "Instances": "*" },
|
|
||||||
{ "Metric": "mem.active.average", "Instances": "*" }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -220,6 +220,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|||||||
objectTypes = append(objectTypes, group.ObjectType)
|
objectTypes = append(objectTypes, group.ObjectType)
|
||||||
}
|
}
|
||||||
objectTypes = append(objectTypes, "ClusterComputeResource")
|
objectTypes = append(objectTypes, "ClusterComputeResource")
|
||||||
|
objectTypes = append(objectTypes, "ResourcePool")
|
||||||
|
|
||||||
// Loop trought datacenters and create the intersting object reference list
|
// Loop trought datacenters and create the intersting object reference list
|
||||||
mors := []types.ManagedObjectReference{}
|
mors := []types.ManagedObjectReference{}
|
||||||
@ -247,7 +248,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|||||||
vm_refs := []types.ManagedObjectReference{}
|
vm_refs := []types.ManagedObjectReference{}
|
||||||
host_refs := []types.ManagedObjectReference{}
|
host_refs := []types.ManagedObjectReference{}
|
||||||
cluster_refs := []types.ManagedObjectReference{}
|
cluster_refs := []types.ManagedObjectReference{}
|
||||||
//resp_refs := []types.ManagedObjectReference{}
|
respool_refs := []types.ManagedObjectReference{}
|
||||||
|
|
||||||
new_mors := []types.ManagedObjectReference{}
|
new_mors := []types.ManagedObjectReference{}
|
||||||
|
|
||||||
@ -260,13 +261,11 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|||||||
} else if mor.Type == "HostSystem" {
|
} else if mor.Type == "HostSystem" {
|
||||||
host_refs = append(host_refs, mor)
|
host_refs = append(host_refs, mor)
|
||||||
new_mors = append(new_mors, mor)
|
new_mors = append(new_mors, mor)
|
||||||
//} else if mor.Type == "ResourcePool" {
|
|
||||||
// resp_refs = append(resp_refs, mor)
|
|
||||||
// new_mors = append(new_mors, mor)
|
|
||||||
} else if mor.Type == "ClusterComputeResource" {
|
} else if mor.Type == "ClusterComputeResource" {
|
||||||
cluster_refs = append(cluster_refs, mor)
|
cluster_refs = append(cluster_refs, mor)
|
||||||
|
} else if mor.Type == "ResourcePool" {
|
||||||
|
respool_refs = append(respool_refs, mor)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// Copy the mors without the clusters
|
// Copy the mors without the clusters
|
||||||
mors = new_mors
|
mors = new_mors
|
||||||
@ -288,13 +287,35 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Retrieve properties for all resourcepools
|
|
||||||
//var respmo []mo.ResourcePool
|
// Initialize the map that will hold the VM MOR to ResourcePool reference
|
||||||
//err = pc.Retrieve(ctx, resp_refs, []string{"summary"}, &respmo)
|
vmToPool := make(map[types.ManagedObjectReference]string)
|
||||||
//if err != nil {
|
|
||||||
// fmt.Println(err)
|
// Retrieve properties for ResourcePools
|
||||||
//return
|
if len(cluster_refs) > 0 {
|
||||||
//}
|
if debug == true {
|
||||||
|
stdlog.Println("going inside ResourcePools")
|
||||||
|
}
|
||||||
|
var respool []mo.ResourcePool
|
||||||
|
err = pc.Retrieve(ctx, respool_refs, []string{"name", "config", "vm"}, &respool)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, pool := range respool {
|
||||||
|
if debug == true {
|
||||||
|
stdlog.Println("---resourcepool name - you should see every resourcepool here (+VMs inside)----")
|
||||||
|
stdlog.Println(pool.Name)
|
||||||
|
}
|
||||||
|
for _, vm := range pool.Vm {
|
||||||
|
if debug == true {
|
||||||
|
stdlog.Println("--VM ID - you should see every VM ID here--")
|
||||||
|
stdlog.Println(vm)
|
||||||
|
}
|
||||||
|
vmToPool[vm] = pool.Name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize the map that will hold the VM MOR to cluster reference
|
// Initialize the map that will hold the VM MOR to cluster reference
|
||||||
vmToCluster := make(map[types.ManagedObjectReference]string)
|
vmToCluster := make(map[types.ManagedObjectReference]string)
|
||||||
@ -356,6 +377,9 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|||||||
if vmToCluster[vm.Self] != "" {
|
if vmToCluster[vm.Self] != "" {
|
||||||
vm_summary[vm.Self]["cluster"] = vmToCluster[vm.Self]
|
vm_summary[vm.Self]["cluster"] = vmToCluster[vm.Self]
|
||||||
}
|
}
|
||||||
|
if vmToPool[vm.Self] != "" {
|
||||||
|
vm_summary[vm.Self]["respool"] = vmToPool[vm.Self]
|
||||||
|
}
|
||||||
vm_summary[vm.Self]["esx"] = host_summary[*vm.Summary.Runtime.Host]["name"]
|
vm_summary[vm.Self]["esx"] = host_summary[*vm.Summary.Runtime.Host]["name"]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,6 +527,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|||||||
if special_fields[measurementName] == nil {
|
if special_fields[measurementName] == nil {
|
||||||
special_fields[measurementName] = make(map[string]map[string]map[string]interface{})
|
special_fields[measurementName] = make(map[string]map[string]map[string]interface{})
|
||||||
special_tags[measurementName] = make(map[string]map[string]map[string]string)
|
special_tags[measurementName] = make(map[string]map[string]map[string]string)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if special_fields[measurementName][tags["name"]] == nil {
|
if special_fields[measurementName][tags["name"]] == nil {
|
||||||
@ -624,7 +649,7 @@ func queryVCenter(vcenter VCenter, config Configuration, InfluxDBClient influxcl
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
flag.BoolVar(&debug, "debug", false, "Debug mode")
|
flag.BoolVar(&debug, "debug", true, "Debug mode")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
stdlog = log.New(os.Stdout, "", log.Ldate|log.Ltime)
|
stdlog = log.New(os.Stdout, "", log.Ldate|log.Ltime)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user