diff --git a/vsphere-influxdb-go.json b/vsphere-influxdb-go.json index 411dc9b..84c05ac 100644 --- a/vsphere-influxdb-go.json +++ b/vsphere-influxdb-go.json @@ -16,7 +16,7 @@ }, "Metrics": [ { - "ObjectType": [ "VirtualMachine", "HostSystem" ], + "ObjectType": [ "VirtualMachine", "HostSystem", "ResourcePool" ], "Definition": [ { "Metric": "cpu.usage.average", "Instances": "*" }, { "Metric": "cpu.usage.maximum", "Instances": "*" }, @@ -64,6 +64,13 @@ { "Metric": "disk.numberWriteAveraged.average", "Instances": "*" }, { "Metric": "net.throughput.contention.summation", "Instances": "*" } ] - } + }, + { "ObjectType": [ "ResourcePool" ], + "Definition": [ + { "Metric": "cpu.usagemhz.average", "Instances": "*" }, + { "Metric": "mem.consumed.average", "Instances": "*" } + ] + } + ] } diff --git a/vsphere-influxdb.go b/vsphere-influxdb.go index a338aaa..71f72dd 100644 --- a/vsphere-influxdb.go +++ b/vsphere-influxdb.go @@ -246,6 +246,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient. vm_refs := []types.ManagedObjectReference{} host_refs := []types.ManagedObjectReference{} cluster_refs := []types.ManagedObjectReference{} + resp_refs := []types.ManagedObjectReference{} new_mors := []types.ManagedObjectReference{} @@ -258,9 +259,15 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient. } else if mor.Type == "HostSystem" { host_refs = append(host_refs, mor) new_mors = append(new_mors, mor) - } else if mor.Type == "ClusterComputeResource" { + } + else if mor.Type == "ResourcePool" { + resp_refs = append(resp_refs, mor) + new_mors = append(new_mors, mor) + } + else if mor.Type == "ClusterComputeResource" { cluster_refs = append(cluster_refs, mor) } + } // Copy the mors without the clusters mors = new_mors @@ -282,6 +289,13 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient. fmt.Println(err) return } + // Retrieve properties for all resourcepools + var respmo []mo.ResourcePool + err = pc.Retrieve(ctx, resp_refs, []string{"summary"}, &respmo) + if err != nil { + fmt.Println(err) + return + } // Initialize the map that will hold the VM MOR to cluster reference vmToCluster := make(map[types.ManagedObjectReference]string) @@ -490,8 +504,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient. if special_fields[measurementName] == nil { special_fields[measurementName] = make(map[string]map[string]map[string]interface{}) special_tags[measurementName] = make(map[string]map[string]map[string]string) - - } + } if special_fields[measurementName][tags["name"]] == nil { special_fields[measurementName][tags["name"]] = make(map[string]map[string]interface{}) @@ -651,3 +664,5 @@ func main() { queryVCenter(*vcenter, config, InfluxDBClient) } } + +