mirror of
https://github.com/Oxalide/vsphere-influxdb-go.git
synced 2023-10-10 13:36:51 +02:00
Making golint happy
This commit is contained in:
parent
88bc206ac2
commit
6558137160
@ -47,7 +47,7 @@ const (
|
|||||||
description = "send vsphere stats to influxdb"
|
description = "send vsphere stats to influxdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Configuration
|
// Configuration is used to store config data
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
VCenters []*VCenter
|
VCenters []*VCenter
|
||||||
Metrics []Metric
|
Metrics []Metric
|
||||||
@ -56,7 +56,7 @@ type Configuration struct {
|
|||||||
InfluxDB InfluxDB
|
InfluxDB InfluxDB
|
||||||
}
|
}
|
||||||
|
|
||||||
// InfluxDB description
|
// InfluxDB is used for InfluxDB connections
|
||||||
type InfluxDB struct {
|
type InfluxDB struct {
|
||||||
Hostname string
|
Hostname string
|
||||||
Username string
|
Username string
|
||||||
@ -64,7 +64,7 @@ type InfluxDB struct {
|
|||||||
Database string
|
Database string
|
||||||
}
|
}
|
||||||
|
|
||||||
// VCenter description
|
// VCenter for VMware vCenter connections
|
||||||
type VCenter struct {
|
type VCenter struct {
|
||||||
Hostname string
|
Hostname string
|
||||||
Username string
|
Username string
|
||||||
@ -72,30 +72,30 @@ type VCenter struct {
|
|||||||
MetricGroups []*MetricGroup
|
MetricGroups []*MetricGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
// Metric Definition
|
// MetricDef metric definition
|
||||||
type MetricDef struct {
|
type MetricDef struct {
|
||||||
Metric string
|
Metric string
|
||||||
Instances string
|
Instances string
|
||||||
Key int32
|
Key int32
|
||||||
}
|
}
|
||||||
|
|
||||||
// Metrics description in config
|
|
||||||
var vmRefs []types.ManagedObjectReference
|
var vmRefs []types.ManagedObjectReference
|
||||||
var debug bool
|
var debug bool
|
||||||
|
|
||||||
|
// Metric is used for metrics retrieval
|
||||||
type Metric struct {
|
type Metric struct {
|
||||||
ObjectType []string
|
ObjectType []string
|
||||||
Definition []MetricDef
|
Definition []MetricDef
|
||||||
}
|
}
|
||||||
|
|
||||||
// Metric Grouping for retrieval
|
// MetricGroup is used for grouping metrics retrieval
|
||||||
type MetricGroup struct {
|
type MetricGroup struct {
|
||||||
ObjectType string
|
ObjectType string
|
||||||
Metrics []MetricDef
|
Metrics []MetricDef
|
||||||
Mor []types.ManagedObjectReference
|
Mor []types.ManagedObjectReference
|
||||||
}
|
}
|
||||||
|
|
||||||
// Informations to query about an entity
|
// EntityQuery are informations to query about an entity
|
||||||
type EntityQuery struct {
|
type EntityQuery struct {
|
||||||
Name string
|
Name string
|
||||||
Entity types.ManagedObjectReference
|
Entity types.ManagedObjectReference
|
||||||
@ -107,6 +107,7 @@ var dependencies = []string{}
|
|||||||
|
|
||||||
var stdlog, errlog *log.Logger
|
var stdlog, errlog *log.Logger
|
||||||
|
|
||||||
|
// Connect to the actual vCenter connection used to query data
|
||||||
func (vcenter *VCenter) Connect() (*govmomi.Client, error) {
|
func (vcenter *VCenter) Connect() (*govmomi.Client, error) {
|
||||||
// Prepare vCenter Connections
|
// Prepare vCenter Connections
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
@ -127,7 +128,7 @@ func (vcenter *VCenter) Connect() (*govmomi.Client, error) {
|
|||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialise vcenter
|
// Init the VCenter connection
|
||||||
func (vcenter *VCenter) Init(config Configuration) {
|
func (vcenter *VCenter) Init(config Configuration) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@ -393,9 +394,9 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|||||||
queries := []types.PerfQuerySpec{}
|
queries := []types.PerfQuerySpec{}
|
||||||
|
|
||||||
// Common parameters
|
// Common parameters
|
||||||
intervalIdint := 20
|
intervalIDint := 20
|
||||||
var intervalId int32
|
var intervalID int32
|
||||||
intervalId = int32(intervalIdint)
|
intervalID = int32(intervalIDint)
|
||||||
|
|
||||||
endTime := time.Now().Add(time.Duration(-1) * time.Second)
|
endTime := time.Now().Add(time.Duration(-1) * time.Second)
|
||||||
startTime := endTime.Add(time.Duration(-config.Interval) * time.Second)
|
startTime := endTime.Add(time.Duration(-config.Interval) * time.Second)
|
||||||
@ -410,7 +411,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
queries = append(queries, types.PerfQuerySpec{Entity: mor, StartTime: &startTime, EndTime: &endTime, MetricId: metricIds, IntervalId: intervalId})
|
queries = append(queries, types.PerfQuerySpec{Entity: mor, StartTime: &startTime, EndTime: &endTime, MetricId: metricIds, intervalID: intervalID})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query the performances
|
// Query the performances
|
||||||
@ -624,14 +625,14 @@ func main() {
|
|||||||
// read the configuration
|
// read the configuration
|
||||||
file, err := os.Open(*cfgFile)
|
file, err := os.Open(*cfgFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errlog.Println("Could not open configuration file" + *cfgFile)
|
errlog.Println("Could not open configuration file " + *cfgFile)
|
||||||
errlog.Println(err)
|
errlog.Println(err)
|
||||||
}
|
}
|
||||||
jsondec := json.NewDecoder(file)
|
jsondec := json.NewDecoder(file)
|
||||||
config := Configuration{}
|
config := Configuration{}
|
||||||
err = jsondec.Decode(&config)
|
err = jsondec.Decode(&config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errlog.Println("Could not decode configuration file")
|
errlog.Println("Could not decode configuration file " + *cfgFile)
|
||||||
errlog.Println(err)
|
errlog.Println(err)
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -647,7 +648,7 @@ func main() {
|
|||||||
errlog.Println("Could not connect to InfluxDB")
|
errlog.Println("Could not connect to InfluxDB")
|
||||||
errlog.Println(err)
|
errlog.Println(err)
|
||||||
} else {
|
} else {
|
||||||
stdlog.Println("Successfully connected to Influx\n")
|
stdlog.Println("Successfully connected to Influx")
|
||||||
}
|
}
|
||||||
for _, vcenter := range config.VCenters {
|
for _, vcenter := range config.VCenters {
|
||||||
queryVCenter(*vcenter, config, InfluxDBClient)
|
queryVCenter(*vcenter, config, InfluxDBClient)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user