added a single debug mode

This commit is contained in:
Adrian Todorov 2016-08-10 17:57:01 +02:00
parent 301a75885f
commit 143b0d12aa
1 changed files with 20 additions and 0 deletions

View File

@ -19,7 +19,9 @@ package main
import ( import (
"encoding/json" "encoding/json"
"flag"
"fmt" "fmt"
// "github.com/davecgh/go-spew/spew"
"golang.org/x/net/context" "golang.org/x/net/context"
"log" "log"
"math" "math"
@ -78,6 +80,7 @@ type MetricDef struct {
// Metrics description in config // Metrics description in config
var vm_refs []types.ManagedObjectReference var vm_refs []types.ManagedObjectReference
var debug bool
type Metric struct { type Metric struct {
ObjectType []string ObjectType []string
@ -284,6 +287,9 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
// Retrieve properties for clusters, if any // Retrieve properties for clusters, if any
if len(cluster_refs) > 0 { if len(cluster_refs) > 0 {
if debug == true {
stdlog.Println("going inside clusters")
}
var clmo []mo.ClusterComputeResource var clmo []mo.ClusterComputeResource
err = pc.Retrieve(ctx, cluster_refs, []string{"name", "configuration"}, &clmo) err = pc.Retrieve(ctx, cluster_refs, []string{"name", "configuration"}, &clmo)
if err != nil { if err != nil {
@ -291,7 +297,17 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
return return
} }
for _, cl := range clmo { for _, cl := range clmo {
if debug == true {
stdlog.Println("---cluster name - you should see every cluster here---")
stdlog.Println(cl.Name)
}
for _, vm := range cl.Configuration.DasVmConfig { for _, vm := range cl.Configuration.DasVmConfig {
if debug == true {
stdlog.Println("--VM ID - you should see every VM ID here--")
stdlog.Println(vm.Key.Value)
}
vmToCluster[vm.Key] = cl.Name vmToCluster[vm.Key] = cl.Name
} }
} }
@ -591,6 +607,10 @@ func queryVCenter(vcenter VCenter, config Configuration, InfluxDBClient influxcl
} }
func main() { func main() {
flag.BoolVar(&debug, "debug", false, "Debug mode")
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)