|
|
@ -1,4 +1,4 @@
|
|
|
|
/* Copyright 2016 Adrian Todorov, Oxalide ato@oxalide.com
|
|
|
|
/* Copyright 2016-2018 Adrian Todorov, Oxalide ato@oxalide.com
|
|
|
|
Original project author: https://github.com/cblomart
|
|
|
|
Original project author: https://github.com/cblomart
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
@ -51,6 +51,7 @@ type Configuration struct {
|
|
|
|
Metrics []Metric
|
|
|
|
Metrics []Metric
|
|
|
|
Interval int
|
|
|
|
Interval int
|
|
|
|
Domain string
|
|
|
|
Domain string
|
|
|
|
|
|
|
|
RemoveHostDomainName bool
|
|
|
|
InfluxDB InfluxDB
|
|
|
|
InfluxDB InfluxDB
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -60,6 +61,7 @@ type InfluxDB struct {
|
|
|
|
Username string
|
|
|
|
Username string
|
|
|
|
Password string
|
|
|
|
Password string
|
|
|
|
Database string
|
|
|
|
Database string
|
|
|
|
|
|
|
|
Prefix string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// VCenter for VMware vCenter connections
|
|
|
|
// VCenter for VMware vCenter connections
|
|
|
@ -68,6 +70,7 @@ type VCenter struct {
|
|
|
|
Username string
|
|
|
|
Username string
|
|
|
|
Password string
|
|
|
|
Password string
|
|
|
|
MetricGroups []*MetricGroup
|
|
|
|
MetricGroups []*MetricGroup
|
|
|
|
|
|
|
|
client *govmomi.Client
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MetricDef metric definition
|
|
|
|
// MetricDef metric definition
|
|
|
@ -97,52 +100,76 @@ type EntityQuery struct {
|
|
|
|
Metrics []int32
|
|
|
|
Metrics []int32
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var debug bool
|
|
|
|
var getversion, debug, test bool
|
|
|
|
var stdlog, errlog *log.Logger
|
|
|
|
var stdlog, errlog *log.Logger
|
|
|
|
|
|
|
|
var version = "master"
|
|
|
|
|
|
|
|
|
|
|
|
// Connect to the actual vCenter connection used to query data
|
|
|
|
// Connect to the actual vCenter connection used to query data
|
|
|
|
func (vcenter *VCenter) Connect() (*govmomi.Client, error) {
|
|
|
|
func (vcenter *VCenter) Connect() error {
|
|
|
|
// Prepare vCenter Connections
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
|
|
stdlog.Println("connecting to vcenter: " + vcenter.Hostname)
|
|
|
|
stdlog.Println("Connecting to vcenter:", vcenter.Hostname)
|
|
|
|
u, err := url.Parse("https://" + vcenter.Username + ":" + vcenter.Password + "@" + vcenter.Hostname + "/sdk")
|
|
|
|
u, err := url.Parse("https://" + vcenter.Hostname + "/sdk")
|
|
|
|
|
|
|
|
u.User = url.UserPassword(vcenter.Username, vcenter.Password)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
errlog.Println("Could not parse vcenter url:", vcenter.Hostname)
|
|
|
|
errlog.Println("Could not parse vcenter url:", vcenter.Hostname)
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
return nil, err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
client, err := govmomi.NewClient(ctx, u, true)
|
|
|
|
client, err := govmomi.NewClient(ctx, u, true)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
errlog.Println("Could not connect to vcenter:", vcenter.Hostname)
|
|
|
|
errlog.Println("Could not connect to vcenter:", vcenter.Hostname)
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
return nil, err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return client, nil
|
|
|
|
vcenter.client = client
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Init the VCenter connection
|
|
|
|
// Disconnect from the vCenter
|
|
|
|
func (vcenter *VCenter) Init(config Configuration) {
|
|
|
|
func (vcenter *VCenter) Disconnect() error {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
|
|
client, err := vcenter.Connect()
|
|
|
|
if vcenter.client != nil {
|
|
|
|
if err != nil {
|
|
|
|
if err := vcenter.client.Logout(ctx); err != nil {
|
|
|
|
errlog.Println("Could not connect to vcenter: ", vcenter.Hostname)
|
|
|
|
errlog.Println("Could not disconnect properly from vcenter:", vcenter.Hostname, err)
|
|
|
|
errlog.Println("Error: ", err)
|
|
|
|
return err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Init the VCenter connection
|
|
|
|
|
|
|
|
func (vcenter *VCenter) Init(config Configuration) error {
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client := vcenter.client
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Print version
|
|
|
|
|
|
|
|
if debug {
|
|
|
|
|
|
|
|
aboutInfo := client.Client.ServiceContent.About
|
|
|
|
|
|
|
|
stdlog.Println("Version:", aboutInfo.FullName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defer client.Logout(ctx)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var perfmanager mo.PerformanceManager
|
|
|
|
var perfmanager mo.PerformanceManager
|
|
|
|
err = client.RetrieveOne(ctx, *client.ServiceContent.PerfManager, nil, &perfmanager)
|
|
|
|
err := client.RetrieveOne(ctx, *client.ServiceContent.PerfManager, nil, &perfmanager)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
errlog.Println("Could not get performance manager")
|
|
|
|
errlog.Println("Could not get performance manager")
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
return
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Print PerformanceManager interval collection level
|
|
|
|
|
|
|
|
if debug {
|
|
|
|
|
|
|
|
stdlog.Println("PerformanceManager interval collection level")
|
|
|
|
|
|
|
|
spew.Dump(perfmanager.HistoricalInterval)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for _, perf := range perfmanager.PerfCounter {
|
|
|
|
for _, perf := range perfmanager.PerfCounter {
|
|
|
@ -171,10 +198,11 @@ func (vcenter *VCenter) Init(config Configuration) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Query a vcenter
|
|
|
|
// Query a vcenter
|
|
|
|
func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.Client) {
|
|
|
|
func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.Client, nowTime time.Time) {
|
|
|
|
stdlog.Println("Setting up query inventory of vcenter:", vcenter.Hostname)
|
|
|
|
stdlog.Println("Setting up query inventory of vcenter:", vcenter.Hostname)
|
|
|
|
|
|
|
|
|
|
|
|
// Create the contect
|
|
|
|
// Create the contect
|
|
|
@ -182,19 +210,13 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
defer cancel()
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
|
|
// Get the client
|
|
|
|
// Get the client
|
|
|
|
client, err := vcenter.Connect()
|
|
|
|
client := vcenter.client
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
errlog.Println("Could not connect to vcenter: ", vcenter.Hostname)
|
|
|
|
|
|
|
|
errlog.Println("Error: ", err)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
defer client.Logout(ctx)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create the view manager
|
|
|
|
// Create the view manager
|
|
|
|
var viewManager mo.ViewManager
|
|
|
|
var viewManager mo.ViewManager
|
|
|
|
err = client.RetrieveOne(ctx, *client.ServiceContent.ViewManager, nil, &viewManager)
|
|
|
|
err := client.RetrieveOne(ctx, *client.ServiceContent.ViewManager, nil, &viewManager)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
errlog.Println("Could not get view manager from vcenter: " + vcenter.Hostname)
|
|
|
|
errlog.Println("Could not get view manager from vcenter:", vcenter.Hostname)
|
|
|
|
errlog.Println("Error: ", err)
|
|
|
|
errlog.Println("Error: ", err)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -203,16 +225,16 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
var rootFolder mo.Folder
|
|
|
|
var rootFolder mo.Folder
|
|
|
|
err = client.RetrieveOne(ctx, client.ServiceContent.RootFolder, nil, &rootFolder)
|
|
|
|
err = client.RetrieveOne(ctx, client.ServiceContent.RootFolder, nil, &rootFolder)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
errlog.Println("Could not get root folder from vcenter: " + vcenter.Hostname)
|
|
|
|
errlog.Println("Could not get root folder from vcenter:", vcenter.Hostname)
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
datacenters := []types.ManagedObjectReference{}
|
|
|
|
datacenters := []types.ManagedObjectReference{}
|
|
|
|
for _, child := range rootFolder.ChildEntity {
|
|
|
|
for _, child := range rootFolder.ChildEntity {
|
|
|
|
if child.Type == "Datacenter" {
|
|
|
|
//if child.Type == "Datacenter" {
|
|
|
|
datacenters = append(datacenters, child)
|
|
|
|
datacenters = append(datacenters, child)
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Get intresting object types from specified queries
|
|
|
|
// Get intresting object types from specified queries
|
|
|
|
objectTypes := []string{}
|
|
|
|
objectTypes := []string{}
|
|
|
@ -230,7 +252,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
req := types.CreateContainerView{This: viewManager.Reference(), Container: datacenter, Type: objectTypes, Recursive: true}
|
|
|
|
req := types.CreateContainerView{This: viewManager.Reference(), Container: datacenter, Type: objectTypes, Recursive: true}
|
|
|
|
res, err := methods.CreateContainerView(ctx, client.RoundTripper, &req)
|
|
|
|
res, err := methods.CreateContainerView(ctx, client.RoundTripper, &req)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
errlog.Println("Could not create container view from vcenter: " + vcenter.Hostname)
|
|
|
|
errlog.Println("Could not create container view from vcenter:", vcenter.Hostname)
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -238,7 +260,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
var containerView mo.ContainerView
|
|
|
|
var containerView mo.ContainerView
|
|
|
|
err = client.RetrieveOne(ctx, res.Returnval, nil, &containerView)
|
|
|
|
err = client.RetrieveOne(ctx, res.Returnval, nil, &containerView)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
errlog.Println("Could not get container view from vcenter: " + vcenter.Hostname)
|
|
|
|
errlog.Println("Could not get container view from vcenter:", vcenter.Hostname)
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -255,7 +277,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
|
|
|
|
|
|
|
|
newMors := []types.ManagedObjectReference{}
|
|
|
|
newMors := []types.ManagedObjectReference{}
|
|
|
|
|
|
|
|
|
|
|
|
if debug == true {
|
|
|
|
if debug {
|
|
|
|
spew.Dump(mors)
|
|
|
|
spew.Dump(mors)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Assign each MORS type to a specific array
|
|
|
|
// Assign each MORS type to a specific array
|
|
|
@ -279,21 +301,27 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
mors = newMors
|
|
|
|
mors = newMors
|
|
|
|
pc := property.DefaultCollector(client.Client)
|
|
|
|
pc := property.DefaultCollector(client.Client)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// govmomi segfaults when the list objects to retrieve is empty, so check everything
|
|
|
|
|
|
|
|
|
|
|
|
// Retrieve properties for all vms
|
|
|
|
// Retrieve properties for all vms
|
|
|
|
var vmmo []mo.VirtualMachine
|
|
|
|
var vmmo []mo.VirtualMachine
|
|
|
|
|
|
|
|
if len(vmRefs) > 0 {
|
|
|
|
err = pc.Retrieve(ctx, vmRefs, []string{"summary"}, &vmmo)
|
|
|
|
err = pc.Retrieve(ctx, vmRefs, []string{"summary"}, &vmmo)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Retrieve properties for hosts
|
|
|
|
// Retrieve properties for hosts
|
|
|
|
var hsmo []mo.HostSystem
|
|
|
|
var hsmo []mo.HostSystem
|
|
|
|
|
|
|
|
if len(hostRefs) > 0 {
|
|
|
|
err = pc.Retrieve(ctx, hostRefs, []string{"parent", "summary"}, &hsmo)
|
|
|
|
err = pc.Retrieve(ctx, hostRefs, []string{"parent", "summary"}, &hsmo)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Retrieve properties for Cluster(s)
|
|
|
|
//Retrieve properties for Cluster(s)
|
|
|
|
var clmo []mo.ClusterComputeResource
|
|
|
|
var clmo []mo.ClusterComputeResource
|
|
|
@ -317,11 +345,13 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
|
|
|
|
|
|
|
|
// Retrieve summary property for all datastores
|
|
|
|
// Retrieve summary property for all datastores
|
|
|
|
var dss []mo.Datastore
|
|
|
|
var dss []mo.Datastore
|
|
|
|
|
|
|
|
if len(datastoreRefs) > 0 {
|
|
|
|
err = pc.Retrieve(ctx, datastoreRefs, []string{"summary"}, &dss)
|
|
|
|
err = pc.Retrieve(ctx, datastoreRefs, []string{"summary"}, &dss)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
log.Fatal(err)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize the map that will hold the VM MOR to ResourcePool reference
|
|
|
|
// Initialize the map that will hold the VM MOR to ResourcePool reference
|
|
|
|
vmToPool := make(map[types.ManagedObjectReference]string)
|
|
|
|
vmToPool := make(map[types.ManagedObjectReference]string)
|
|
|
@ -329,8 +359,8 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
var respool []mo.ResourcePool
|
|
|
|
var respool []mo.ResourcePool
|
|
|
|
// Retrieve properties for ResourcePools
|
|
|
|
// Retrieve properties for ResourcePools
|
|
|
|
if len(respoolRefs) > 0 {
|
|
|
|
if len(respoolRefs) > 0 {
|
|
|
|
if debug == true {
|
|
|
|
if debug {
|
|
|
|
stdlog.Println("going inside ResourcePools")
|
|
|
|
stdlog.Println("Going inside ResourcePools")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = pc.Retrieve(ctx, respoolRefs, []string{"name", "config", "vm"}, &respool)
|
|
|
|
err = pc.Retrieve(ctx, respoolRefs, []string{"name", "config", "vm"}, &respool)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -338,14 +368,14 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, pool := range respool {
|
|
|
|
for _, pool := range respool {
|
|
|
|
stdlog.Println(pool.Config.MemoryAllocation.GetResourceAllocationInfo().Limit)
|
|
|
|
if debug {
|
|
|
|
stdlog.Println(pool.Config.CpuAllocation.GetResourceAllocationInfo().Limit)
|
|
|
|
|
|
|
|
if debug == true {
|
|
|
|
|
|
|
|
stdlog.Println("---resourcepool name - you should see every resourcepool here (+VMs inside)----")
|
|
|
|
stdlog.Println("---resourcepool name - you should see every resourcepool here (+VMs inside)----")
|
|
|
|
stdlog.Println(pool.Name)
|
|
|
|
stdlog.Println(pool.Name)
|
|
|
|
|
|
|
|
stdlog.Println(pool.Config.MemoryAllocation.GetResourceAllocationInfo().Limit)
|
|
|
|
|
|
|
|
stdlog.Println(pool.Config.CpuAllocation.GetResourceAllocationInfo().Limit)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, vm := range pool.Vm {
|
|
|
|
for _, vm := range pool.Vm {
|
|
|
|
if debug == true {
|
|
|
|
if debug {
|
|
|
|
stdlog.Println("--VM ID - you should see every VM ID here--")
|
|
|
|
stdlog.Println("--VM ID - you should see every VM ID here--")
|
|
|
|
stdlog.Println(vm)
|
|
|
|
stdlog.Println(vm)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -357,13 +387,16 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize the map that will hold the VM MOR to cluster reference
|
|
|
|
// Initialize the map that will hold the host MOR to cluster reference
|
|
|
|
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
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
if debug == true {
|
|
|
|
if debug {
|
|
|
|
stdlog.Println("going inside clusters")
|
|
|
|
stdlog.Println("Going inside clusters")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Step 1 : Get ObjectContents and Host info for VM
|
|
|
|
// Step 1 : Get ObjectContents and Host info for VM
|
|
|
@ -378,6 +411,10 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
// If we find it, return it, otherwise we return null.
|
|
|
|
// If we find it, return it, otherwise we return null.
|
|
|
|
|
|
|
|
|
|
|
|
for _, vm := range vmmo {
|
|
|
|
for _, vm := range vmmo {
|
|
|
|
|
|
|
|
// check if VM is a clone in progress and skip it
|
|
|
|
|
|
|
|
if vm.Summary.Runtime.Host == nil {
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
vmhost := vm.Summary.Runtime.Host
|
|
|
|
vmhost := vm.Summary.Runtime.Host
|
|
|
|
|
|
|
|
|
|
|
|
for _, cl := range clmo {
|
|
|
|
for _, cl := range clmo {
|
|
|
@ -400,24 +437,34 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
respoolSummary[pools.Self]["name"] = pools.Summary.GetResourcePoolSummary().Name
|
|
|
|
respoolSummary[pools.Self]["name"] = pools.Summary.GetResourcePoolSummary().Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Retrieve properties for the hosts
|
|
|
|
// Initialize the maps that will hold the extra tags and metrics for VMs
|
|
|
|
hostSummary := make(map[types.ManagedObjectReference]map[string]string)
|
|
|
|
hostSummary := make(map[types.ManagedObjectReference]map[string]string)
|
|
|
|
hostExtraMetrics := make(map[types.ManagedObjectReference]map[string]int64)
|
|
|
|
hostExtraMetrics := make(map[types.ManagedObjectReference]map[string]int64)
|
|
|
|
|
|
|
|
|
|
|
|
for _, host := range hsmo {
|
|
|
|
for _, host := range hsmo {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Extra tags per host
|
|
|
|
hostSummary[host.Self] = make(map[string]string)
|
|
|
|
hostSummary[host.Self] = make(map[string]string)
|
|
|
|
hostSummary[host.Self]["name"] = host.Summary.Config.Name
|
|
|
|
hostSummary[host.Self]["name"] = host.Summary.Config.Name
|
|
|
|
|
|
|
|
// Remove Domain Name from Host
|
|
|
|
|
|
|
|
if config.RemoveHostDomainName {
|
|
|
|
|
|
|
|
hostSummary[host.Self]["name"] = strings.Replace(host.Summary.Config.Name, config.Domain, "", -1)
|
|
|
|
|
|
|
|
}
|
|
|
|
hostSummary[host.Self]["cluster"] = hostToCluster[host.Self]
|
|
|
|
hostSummary[host.Self]["cluster"] = hostToCluster[host.Self]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Extra metrics per host
|
|
|
|
hostExtraMetrics[host.Self] = make(map[string]int64)
|
|
|
|
hostExtraMetrics[host.Self] = make(map[string]int64)
|
|
|
|
|
|
|
|
hostExtraMetrics[host.Self]["uptime"] = int64(host.Summary.QuickStats.Uptime)
|
|
|
|
hostExtraMetrics[host.Self]["cpu_corecount_total"] = int64(host.Summary.Hardware.NumCpuThreads)
|
|
|
|
hostExtraMetrics[host.Self]["cpu_corecount_total"] = int64(host.Summary.Hardware.NumCpuThreads)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize the map that will hold all extra tags
|
|
|
|
// Initialize the maps that will hold the extra tags and metrics for VMs
|
|
|
|
vmSummary := make(map[types.ManagedObjectReference]map[string]string)
|
|
|
|
vmSummary := make(map[types.ManagedObjectReference]map[string]string)
|
|
|
|
|
|
|
|
vmExtraMetrics := make(map[types.ManagedObjectReference]map[string]int64)
|
|
|
|
|
|
|
|
|
|
|
|
// Assign extra details per VM in vmSummary
|
|
|
|
// Assign extra details per VM in vmSummary
|
|
|
|
for _, vm := range vmmo {
|
|
|
|
for _, vm := range vmmo {
|
|
|
|
|
|
|
|
// extra tags per VM
|
|
|
|
vmSummary[vm.Self] = make(map[string]string)
|
|
|
|
vmSummary[vm.Self] = make(map[string]string)
|
|
|
|
// Ugly way to extract datastore value
|
|
|
|
// Ugly way to extract datastore value
|
|
|
|
re, err := regexp.Compile(`\[(.*?)\]`)
|
|
|
|
re, err := regexp.Compile(`\[(.*?)\]`)
|
|
|
@ -425,15 +472,34 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
// if device.Backing.FileName != nil && device.Backing.Datastore.Name != vmSummary[vm.Self]["datastore"] {
|
|
|
|
|
|
|
|
// if vDiskToDatastore[vm.Self] == nil {
|
|
|
|
|
|
|
|
// vDiskToDatastore[vm.Self] = make(map[string]string)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// 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]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if vmToPool[vm.Self] != "" {
|
|
|
|
if vmToPool[vm.Self] != "" {
|
|
|
|
vmSummary[vm.Self]["respool"] = vmToPool[vm.Self]
|
|
|
|
vmSummary[vm.Self]["respool"] = vmToPool[vm.Self]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if vm.Summary.Runtime.Host != nil {
|
|
|
|
vmSummary[vm.Self]["esx"] = hostSummary[*vm.Summary.Runtime.Host]["name"]
|
|
|
|
vmSummary[vm.Self]["esx"] = hostSummary[*vm.Summary.Runtime.Host]["name"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Extra metrics per VM
|
|
|
|
|
|
|
|
vmExtraMetrics[vm.Self] = make(map[string]int64)
|
|
|
|
|
|
|
|
vmExtraMetrics[vm.Self]["uptime"] = int64(vm.Summary.QuickStats.UptimeSeconds)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// fmt.Println("vDiskDatastore:")
|
|
|
|
|
|
|
|
// spew.Dump(vDiskToDatastore)
|
|
|
|
// get object names
|
|
|
|
// get object names
|
|
|
|
objects := []mo.ManagedEntity{}
|
|
|
|
objects := []mo.ManagedEntity{}
|
|
|
|
|
|
|
|
|
|
|
@ -448,7 +514,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
propreq := types.RetrieveProperties{SpecSet: []types.PropertyFilterSpec{{ObjectSet: objectSet, PropSet: []types.PropertySpec{*propSpec}}}}
|
|
|
|
propreq := types.RetrieveProperties{SpecSet: []types.PropertyFilterSpec{{ObjectSet: objectSet, PropSet: []types.PropertySpec{*propSpec}}}}
|
|
|
|
propres, err := client.PropertyCollector().RetrieveProperties(ctx, propreq)
|
|
|
|
propres, err := client.PropertyCollector().RetrieveProperties(ctx, propreq)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
errlog.Println("Could not retrieve object names from vcenter: " + vcenter.Hostname)
|
|
|
|
errlog.Println("Could not retrieve object names from vcenter:", vcenter.Hostname)
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -456,7 +522,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
//load retrieved properties
|
|
|
|
//load retrieved properties
|
|
|
|
err = mo.LoadRetrievePropertiesResponse(propres, &objects)
|
|
|
|
err = mo.LoadRetrievePropertiesResponse(propres, &objects)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
errlog.Println("Could not retrieve object names from vcenter: " + vcenter.Hostname)
|
|
|
|
errlog.Println("Could not retrieve object names from vcenter:", vcenter.Hostname)
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -504,7 +570,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
perfreq := types.QueryPerf{This: *client.ServiceContent.PerfManager, QuerySpec: queries}
|
|
|
|
perfreq := types.QueryPerf{This: *client.ServiceContent.PerfManager, QuerySpec: queries}
|
|
|
|
perfres, err := methods.QueryPerf(ctx, client.RoundTripper, &perfreq)
|
|
|
|
perfres, err := methods.QueryPerf(ctx, client.RoundTripper, &perfreq)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
errlog.Println("Could not request perfs from vcenter: " + vcenter.Hostname)
|
|
|
|
errlog.Println("Could not request perfs from vcenter:", vcenter.Hostname)
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
errlog.Println("Error:", err)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -607,15 +673,21 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
specialTags[measurementName][tags["name"]][instanceName]["instance"] = instanceName
|
|
|
|
specialTags[measurementName][tags["name"]][instanceName]["instance"] = instanceName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the fields for the hostExtraMetrics
|
|
|
|
if metrics, ok := hostExtraMetrics[pem.Entity]; ok {
|
|
|
|
if metrics, ok := hostExtraMetrics[pem.Entity]; ok {
|
|
|
|
for key, value := range metrics {
|
|
|
|
for key, value := range metrics {
|
|
|
|
fields[key] = value
|
|
|
|
fields[key] = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the fields for the vmExtraMetrics
|
|
|
|
|
|
|
|
if metrics, ok := vmExtraMetrics[pem.Entity]; ok {
|
|
|
|
|
|
|
|
for key, value := range metrics {
|
|
|
|
|
|
|
|
fields[key] = value
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//create InfluxDB points
|
|
|
|
//create InfluxDB points
|
|
|
|
pt, err := influxclient.NewPoint(entityName, tags, fields, nowTime)
|
|
|
|
pt, err := influxclient.NewPoint(config.InfluxDB.Prefix+entityName, tags, fields, nowTime)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
errlog.Println(err)
|
|
|
|
errlog.Println(err)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
@ -625,7 +697,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
for measurement, v := range specialFields {
|
|
|
|
for measurement, v := range specialFields {
|
|
|
|
for name, metric := range v {
|
|
|
|
for name, metric := range v {
|
|
|
|
for instance, value := range metric {
|
|
|
|
for instance, value := range metric {
|
|
|
|
pt2, err := influxclient.NewPoint(measurement, specialTags[measurement][name][instance], value, time.Now())
|
|
|
|
pt2, err := influxclient.NewPoint(config.InfluxDB.Prefix+measurement, specialTags[measurement][name][instance], value, time.Now())
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
errlog.Println(err)
|
|
|
|
errlog.Println(err)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
@ -635,20 +707,13 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// var respool []mo.ResourcePool
|
|
|
|
|
|
|
|
// err = pc.Retrieve(ctx, respoolRefs, []string{"name", "config", "vm"}, &respool)
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
|
|
|
// errlog.Println(err)
|
|
|
|
|
|
|
|
// continue
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, pool := range respool {
|
|
|
|
for _, pool := range respool {
|
|
|
|
respoolFields := map[string]interface{}{
|
|
|
|
respoolFields := map[string]interface{}{
|
|
|
|
"cpu_limit": pool.Config.CpuAllocation.GetResourceAllocationInfo().Limit,
|
|
|
|
"cpu_limit": pool.Config.CpuAllocation.GetResourceAllocationInfo().Limit,
|
|
|
|
"memory_limit": pool.Config.MemoryAllocation.GetResourceAllocationInfo().Limit,
|
|
|
|
"memory_limit": pool.Config.MemoryAllocation.GetResourceAllocationInfo().Limit,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
respoolTags := map[string]string{"pool_name": pool.Name}
|
|
|
|
respoolTags := map[string]string{"pool_name": pool.Name}
|
|
|
|
pt3, err := influxclient.NewPoint("resourcepool", respoolTags, respoolFields, time.Now())
|
|
|
|
pt3, err := influxclient.NewPoint(config.InfluxDB.Prefix+"resourcepool", respoolTags, respoolFields, time.Now())
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
errlog.Println(err)
|
|
|
|
errlog.Println(err)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
@ -660,9 +725,10 @@ 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)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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("datastore", datastoreTags, datastoreFields, time.Now())
|
|
|
|
pt4, err := influxclient.NewPoint(config.InfluxDB.Prefix+"datastore", datastoreTags, datastoreFields, time.Now())
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
errlog.Println(err)
|
|
|
|
errlog.Println(err)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
@ -672,14 +738,17 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//InfluxDB send
|
|
|
|
//InfluxDB send if not in test mode
|
|
|
|
|
|
|
|
if test != true {
|
|
|
|
err = InfluxDBClient.Write(bp)
|
|
|
|
err = InfluxDBClient.Write(bp)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
errlog.Println(err)
|
|
|
|
errlog.Println(err)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stdlog.Println("Sent data to Influxdb from:", vcenter.Hostname)
|
|
|
|
stdlog.Println("sent data to Influxdb")
|
|
|
|
} else {
|
|
|
|
|
|
|
|
spew.Dump(bp)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func min(n ...int64) int64 {
|
|
|
|
func min(n ...int64) int64 {
|
|
|
@ -697,7 +766,6 @@ func min(n ...int64) int64 {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return min
|
|
|
|
return min
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func max(n ...int64) int64 {
|
|
|
|
func max(n ...int64) int64 {
|
|
|
|
var max int64 = -1
|
|
|
|
var max int64 = -1
|
|
|
|
for _, i := range n {
|
|
|
|
for _, i := range n {
|
|
|
@ -737,20 +805,44 @@ func average(n ...int64) int64 {
|
|
|
|
return int64(math.Floor(favg + .5))
|
|
|
|
return int64(math.Floor(favg + .5))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func queryVCenter(vcenter VCenter, config Configuration, InfluxDBClient influxclient.Client) {
|
|
|
|
func worker(id int, config Configuration, influxDBClient influxclient.Client, nowTime time.Time, vcenters <-chan *VCenter, results chan<- bool) {
|
|
|
|
stdlog.Println("Querying vcenter")
|
|
|
|
for vcenter := range vcenters {
|
|
|
|
vcenter.Query(config, InfluxDBClient)
|
|
|
|
if debug {
|
|
|
|
|
|
|
|
stdlog.Println("Worker", id, "received vcenter", vcenter.Hostname)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := vcenter.Connect(); err != nil {
|
|
|
|
|
|
|
|
errlog.Println("Could not initialize connection to vcenter", vcenter.Hostname, err)
|
|
|
|
|
|
|
|
results <- true
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := vcenter.Init(config); err == nil {
|
|
|
|
|
|
|
|
vcenter.Query(config, influxDBClient, nowTime)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vcenter.Disconnect()
|
|
|
|
|
|
|
|
results <- true
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
func main() {
|
|
|
|
flag.BoolVar(&debug, "debug", false, "Debug mode")
|
|
|
|
baseName := path.Base(os.Args[0])
|
|
|
|
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)
|
|
|
|
stdlog = log.New(os.Stdout, "", log.Ldate|log.Ltime)
|
|
|
|
errlog = log.New(os.Stderr, "", log.Ldate|log.Ltime)
|
|
|
|
errlog = log.New(os.Stderr, "", log.Ldate|log.Ltime)
|
|
|
|
|
|
|
|
|
|
|
|
stdlog.Println("Starting :", path.Base(os.Args[0]))
|
|
|
|
flag.BoolVar(&debug, "debug", false, "Debug mode")
|
|
|
|
|
|
|
|
flag.BoolVar(&test, "test", false, "Test mode, data will be collected from vCenters, but nothing will be written to InfluxDB, only printed to stdout")
|
|
|
|
|
|
|
|
flag.BoolVar(&getversion, "version", false, "Get version and exit")
|
|
|
|
|
|
|
|
workerCount := flag.Int("workers", 4, "Number of concurrent workers to query vcenters")
|
|
|
|
|
|
|
|
cfgFile := flag.String("config", "/etc/"+baseName+".json", "Config file to use")
|
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if getversion {
|
|
|
|
|
|
|
|
fmt.Println("Version:", version)
|
|
|
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stdlog.Println("Starting", baseName, "with config file", *cfgFile)
|
|
|
|
|
|
|
|
|
|
|
|
// read the configuration
|
|
|
|
// read the configuration
|
|
|
|
file, err := os.Open(*cfgFile)
|
|
|
|
file, err := os.Open(*cfgFile)
|
|
|
@ -774,7 +866,6 @@ func main() {
|
|
|
|
config.InfluxDB.Password = os.Getenv("INFLUX_PASSWORD")
|
|
|
|
config.InfluxDB.Password = os.Getenv("INFLUX_PASSWORD")
|
|
|
|
config.InfluxDB.Database = os.Getenv("INFLUX_DATABASE")
|
|
|
|
config.InfluxDB.Database = os.Getenv("INFLUX_DATABASE")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Support environment variables for VSphere
|
|
|
|
// Support environment variables for VSphere
|
|
|
|
// Currently ony one server is supported and added to the list of vSphere servers
|
|
|
|
// Currently ony one server is supported and added to the list of vSphere servers
|
|
|
|
if vhostname := os.Getenv("VSPHERE_HOSTNAME"); vhostname != "" {
|
|
|
|
if vhostname := os.Getenv("VSPHERE_HOSTNAME"); vhostname != "" {
|
|
|
@ -787,28 +878,48 @@ func main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Print configuration in debug mode
|
|
|
|
// Print configuration in debug mode
|
|
|
|
if debug == true {
|
|
|
|
if debug {
|
|
|
|
stdlog.Println("---Configuration - you should see the config here---")
|
|
|
|
stdlog.Println("---Configuration - you should see the config here---")
|
|
|
|
spew.Dump(config)
|
|
|
|
spew.Dump(config)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for _, vcenter := range config.VCenters {
|
|
|
|
// Initialize InfluxDB and connect to database
|
|
|
|
vcenter.Init(config)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InfluxDBClient, err := influxclient.NewHTTPClient(influxclient.HTTPConfig{
|
|
|
|
InfluxDBClient, err := influxclient.NewHTTPClient(influxclient.HTTPConfig{
|
|
|
|
Addr: config.InfluxDB.Hostname,
|
|
|
|
Addr: config.InfluxDB.Hostname,
|
|
|
|
Username: config.InfluxDB.Username,
|
|
|
|
Username: config.InfluxDB.Username,
|
|
|
|
Password: config.InfluxDB.Password,
|
|
|
|
Password: config.InfluxDB.Password,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
errlog.Println("Could not initialize InfluxDB client")
|
|
|
|
|
|
|
|
errlog.Fatalln(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _, _, err := InfluxDBClient.Ping(0); err != nil {
|
|
|
|
errlog.Println("Could not connect to InfluxDB")
|
|
|
|
errlog.Println("Could not connect to InfluxDB")
|
|
|
|
errlog.Fatalln(err)
|
|
|
|
errlog.Fatalln(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defer InfluxDBClient.Close()
|
|
|
|
|
|
|
|
|
|
|
|
stdlog.Println("Successfully connected to Influx")
|
|
|
|
stdlog.Println("Successfully connected to Influx")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// make the channels, get the time, launch the goroutines
|
|
|
|
|
|
|
|
vcenterCount := len(config.VCenters)
|
|
|
|
|
|
|
|
vcenters := make(chan *VCenter, vcenterCount)
|
|
|
|
|
|
|
|
results := make(chan bool, vcenterCount)
|
|
|
|
|
|
|
|
nowTime := time.Now()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i := 0; i < *workerCount; i++ {
|
|
|
|
|
|
|
|
go worker(i, config, InfluxDBClient, nowTime, vcenters, results)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for _, vcenter := range config.VCenters {
|
|
|
|
for _, vcenter := range config.VCenters {
|
|
|
|
queryVCenter(*vcenter, config, InfluxDBClient)
|
|
|
|
vcenters <- vcenter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(vcenters)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i := 0; i < vcenterCount; i++ {
|
|
|
|
|
|
|
|
<-results
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|