diff --git a/vsphere-influxdb.go b/vsphere-influxdb.go index aee6333..f5d2226 100644 --- a/vsphere-influxdb.go +++ b/vsphere-influxdb.go @@ -288,11 +288,19 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient. return } + //Retrieve properties for ResourcePool + var rpmo []mo.ResourcePool + err = pc.Retrieve(ctx, respool_refs, []string{"summary"}, &rpmo) + if err != nil { + fmt.Println(err) + return + } + // Initialize the map that will hold the VM MOR to ResourcePool reference vmToPool := make(map[types.ManagedObjectReference]string) // Retrieve properties for ResourcePools - if len(cluster_refs) > 0 { + if len(respool_refs) > 0 { if debug == true { stdlog.Println("going inside ResourcePools") } @@ -351,6 +359,13 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient. } } + // Retrieve properties for the pools + respool_summary := make(map[types.ManagedObjectReference]map[string]string) + for _, pools := range rpmo { + respool_summary[pools.Self] = make(map[string]string) + respool_summary[pools.Self]["name"] = pools.Summary.GetResourcePoolSummary().Name + } + // Retrieve properties for the hosts host_summary := make(map[types.ManagedObjectReference]map[string]string) host_extra_metrics := make(map[types.ManagedObjectReference]map[string]int64) @@ -493,6 +508,12 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient. } } + if summary, ok := respool_summary[pem.Entity]; ok { + for key, tag := range summary { + tags[key] = tag + } + } + special_fields := make(map[string]map[string]map[string]map[string]interface{}) special_tags := make(map[string]map[string]map[string]map[string]string) nowTime := time.Now() @@ -575,6 +596,26 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient. } } } + + 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 { + respoolFields := map[string]interface{}{ + "cpu_limit": pool.Config.CpuAllocation.GetResourceAllocationInfo().Limit, + "memory_limit": pool.Config.MemoryAllocation.GetResourceAllocationInfo().Limit, + } + respoolTags := map[string]string{"pool_name": pool.Name} + pt3, err := influxclient.NewPoint("resourcepool", respoolTags, respoolFields, time.Now()) + if err != nil { + errlog.Println(err) + } + bp.AddPoint(pt3) + } + } //InfluxDB send err = InfluxDBClient.Write(bp) @@ -649,7 +690,8 @@ func queryVCenter(vcenter VCenter, config Configuration, InfluxDBClient influxcl func main() { - flag.BoolVar(&debug, "debug", true, "Debug mode") + flag.BoolVar(&debug, "debug", false, "Debug mode") + var cfgFile = flag.String("config", "/etc/"+path.Base(os.Args[0])+".json", "Config file to use. Default is /etc/"+path.Base(os.Args[0])+".json") flag.Parse() stdlog = log.New(os.Stdout, "", log.Ldate|log.Ltime) @@ -657,16 +699,16 @@ func main() { stdlog.Println("Starting :", path.Base(os.Args[0])) // read the configuration - file, err := os.Open(path.Base(os.Args[0]) + ".json") + file, err := os.Open(*cfgFile) if err != nil { - errlog.Println("Could not open configuration file") + errlog.Println("Could not open configuration file " + *cfgFile) errlog.Println(err) } jsondec := json.NewDecoder(file) config := Configuration{} err = jsondec.Decode(&config) if err != nil { - errlog.Println("Could not decode configuration file") + errlog.Println("Could not decode configuration file " + *cfgFile) errlog.Println(err) }