1
0
mirror of https://github.com/Oxalide/vsphere-influxdb-go.git synced 2023-10-10 11:36:51 +00:00

22 Commits

Author SHA1 Message Date
Adrian Todorov
e0c31fa803 update to use nfpm instead of fpm for packaging 2018-09-16 15:47:55 +02:00
Adrian Todorov
9094700d21 rollback vDisk parsing for now 2018-09-16 15:39:38 +02:00
Adrian Todorov
23505fb8d3 Merge pull request #93 from MicKBfr/patch-1
Update vsphere-influxdb.go
2018-09-16 15:01:46 +02:00
MicKBfr
e9bccef96d Update vsphere-influxdb.go 2018-09-13 17:02:26 +02:00
Adrian Todorov
639ef28ecf Merge pull request #72 from MicKBfr/MicKBfr-patch-1
Remove domain from esx name
2018-09-03 22:07:41 +02:00
Adrian Todorov
57703fa0b3 Merge pull request #81 from krische/master
Compute usage percentage of datastore.
2018-08-09 18:32:26 +02:00
Brian Krische
a32178917a Compute usage percentage of datastore. 2018-06-25 07:39:38 -05:00
MicKBfr
3ddb5a30da patch to made RemoveHostDomainName optional 2018-04-12 17:45:57 +02:00
MicKBfr
3eb0f579a9 Update vsphere-influxdb.go 2018-04-12 17:36:51 +02:00
MicKBfr
39330e4d31 Remove domain from esx name
Domain in esx name can be a problem with influxgraph and grafana.
2018-04-06 09:40:32 +02:00
Adrian Todorov
3f8a36f0cf virtual disk to datastore mapping 2018-03-31 15:15:52 +00:00
Adrian Todorov
d04a66083b fix copyright notice year 2018-03-31 15:03:58 +00:00
Adrian Todorov
1467c58c08 merge 2018-03-31 16:40:43 +02:00
Adrian Todorov
71d921b681 Merge pull request #63 from ncareau/patch-2
Typo in readme.
2018-02-24 22:13:32 +01:00
NMC
2091fe3207 Typo in readme.
Sorry, made a typo in my PR.
2018-02-24 15:33:11 -05:00
Adrian Todorov
770c98ecd4 Merge pull request #62 from ncareau/patch-1
Update README.md with note for time (check #31 comments)
2018-02-24 21:05:12 +01:00
NMC
c3dc5c2e75 Update Readme.md with note for time (view #31)
Added a note for the NTP service to be valid since there have been reports (including myself) where an invalid time on the ESXi server caused the script to dump no data at all.
2018-02-24 14:43:56 -05:00
Adrian Todorov
60baa6670b fix typo in README 2018-02-04 13:18:23 +01:00
Adrian Todorov
2656627e47 cleanup 2018-02-03 21:29:32 +01:00
Adrian Todorov
cc748fd2ae print PerformanceManager HistoricalInterval metric collection level if -debug is present 2018-02-03 21:27:12 +01:00
Adrian Todorov
a2b027825c print version if -debug is present 2018-02-03 21:22:10 +01:00
Adrian Todorov
b2da326242 fix version print to fmt.Println instead of stdlog.Println 2018-02-03 19:45:35 +01:00
5 changed files with 82 additions and 24 deletions

View File

@@ -17,6 +17,6 @@ before_script:
script:
- git status
after_success:
- gem install --no-ri --no-rdoc fpm
# - gem install --no-ri --no-rdoc fpm
- test -n "$TRAVIS_TAG" && curl -sL https://git.io/goreleaser | bash

39
Gopkg.lock generated
View File

@@ -2,32 +2,65 @@
[[projects]]
digest = "1:56c130d885a4aacae1dd9c7b71cfe39912c7ebc1ff7d2b46083c8812996dc43b"
name = "github.com/davecgh/go-spew"
packages = ["spew"]
pruneopts = ""
revision = "346938d642f2ec3594ed81d874461961cd0faa76"
version = "v1.1.0"
[[projects]]
digest = "1:ec837623c12abf4f44837163ad32274dd0c9dfa29f0d65068c60897bce34bb75"
name = "github.com/influxdata/influxdb"
packages = ["client/v2","models","pkg/escape"]
packages = [
"client/v2",
"models",
"pkg/escape",
]
pruneopts = ""
revision = "a7c3d3c0f7b74f71919047adbc4933460967a576"
version = "v1.3.6"
[[projects]]
digest = "1:c5342f3ddefc1644d1a3ed028e739bfabe5b457978084b9a28d42ed235c8bb4d"
name = "github.com/vmware/govmomi"
packages = [".","property","session","vim25","vim25/debug","vim25/methods","vim25/mo","vim25/progress","vim25/soap","vim25/types","vim25/xml"]
packages = [
".",
"property",
"session",
"vim25",
"vim25/debug",
"vim25/methods",
"vim25/mo",
"vim25/progress",
"vim25/soap",
"vim25/types",
"vim25/xml",
]
pruneopts = ""
revision = "b63044e5f833781eb7b305bc035392480ee06a82"
version = "v0.15.0"
[[projects]]
branch = "master"
digest = "1:70ca15641aa31be55859a7f75ddef3ae384ae18068deab8274668a1a77d1e84a"
name = "golang.org/x/net"
packages = ["context"]
pruneopts = ""
revision = "4b14673ba32bee7f5ac0f990a48f033919fd418b"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "0b7718e6a338978c4ea1efca3255565c667967ddd6ff68999a1d1cea5112209e"
input-imports = [
"github.com/davecgh/go-spew/spew",
"github.com/influxdata/influxdb/client/v2",
"github.com/vmware/govmomi",
"github.com/vmware/govmomi/property",
"github.com/vmware/govmomi/vim25/methods",
"github.com/vmware/govmomi/vim25/mo",
"github.com/vmware/govmomi/vim25/types",
"golang.org/x/net/context",
]
solver-name = "gps-cdcl"
solver-version = 1

View File

@@ -49,7 +49,7 @@ For InfluxDB:
For vSphere:
* VSPHERE\_HOSTNAME
* VSPHERE\_USERNAME
* SPHERE\_PASSWORD
* VSPHERE\_PASSWORD
Keep in mind, that currently only one vCenter/ESXi can be added via environment variable.
@@ -57,6 +57,7 @@ If you set a domain, it will be automaticaly removed from the names of the found
Metrics collected are defined by associating ObjectType groups with Metric groups.
There have been reports of the script not working correctly when the time is incorrect on the vsphere or vcenter. Make sure that the time is valid or activate the NTP service on the machine.
# Run as a service

View File

@@ -19,7 +19,7 @@ archive:
files:
- LICENSE.txt
- README.md
fpm:
nfpm:
# Your app's vendor.
# Default is empty.
vendor: Oxalide

View File

@@ -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
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
@@ -47,11 +47,12 @@ const (
// Configuration is used to store config data
type Configuration struct {
VCenters []*VCenter
Metrics []Metric
Interval int
Domain string
InfluxDB InfluxDB
VCenters []*VCenter
Metrics []Metric
Interval int
Domain string
RemoveHostDomainName bool
InfluxDB InfluxDB
}
// InfluxDB is used for InfluxDB connections
@@ -103,7 +104,6 @@ var getversion, debug, test bool
var stdlog, errlog *log.Logger
var version = "master"
// Connect to the actual vCenter connection used to query data
func (vcenter *VCenter) Connect() error {
ctx, cancel := context.WithCancel(context.Background())
@@ -151,6 +151,12 @@ func (vcenter *VCenter) Init(config Configuration) error {
client := vcenter.client
// Print version
if debug {
aboutInfo := client.Client.ServiceContent.About
stdlog.Println("Version:", aboutInfo.FullName)
}
var perfmanager mo.PerformanceManager
err := client.RetrieveOne(ctx, *client.ServiceContent.PerfManager, nil, &perfmanager)
if err != nil {
@@ -159,6 +165,12 @@ func (vcenter *VCenter) Init(config Configuration) error {
return err
}
// Print PerformanceManager interval collection level
if debug {
stdlog.Println("PerformanceManager interval collection level")
spew.Dump(perfmanager.HistoricalInterval)
}
for _, perf := range perfmanager.PerfCounter {
groupinfo := perf.GroupInfo.GetElementDescription()
nameinfo := perf.NameInfo.GetElementDescription()
@@ -377,6 +389,9 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
// Initialize the map that will hold the host MOR to cluster reference
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
if len(clusterRefs) > 0 {
if debug {
@@ -430,6 +445,10 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
// Extra tags per host
hostSummary[host.Self] = make(map[string]string)
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]
// Extra metrics per host
@@ -452,6 +471,18 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
fmt.Println(err)
}
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] != "" {
vmSummary[vm.Self]["cluster"] = vmToCluster[vm.Self]
}
@@ -466,7 +497,8 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
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
objects := []mo.ManagedEntity{}
@@ -674,13 +706,6 @@ 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 {
respoolFields := map[string]interface{}{
"cpu_limit": pool.Config.CpuAllocation.GetResourceAllocationInfo().Limit,
@@ -699,6 +724,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
datastoreFields := map[string]interface{}{
"capacity": datastore.Summary.Capacity,
"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}
pt4, err := influxclient.NewPoint(config.InfluxDB.Prefix+"datastore", datastoreTags, datastoreFields, time.Now())
@@ -739,7 +765,6 @@ func min(n ...int64) int64 {
}
return min
}
func max(n ...int64) int64 {
var max int64 = -1
for _, i := range n {
@@ -790,7 +815,6 @@ func worker(id int, config Configuration, influxDBClient influxclient.Client, no
results <- true
continue
}
if err := vcenter.Init(config); err == nil {
vcenter.Query(config, influxDBClient, nowTime)
}
@@ -813,7 +837,7 @@ func main() {
flag.Parse()
if getversion {
stdlog.Println("Version:",version)
fmt.Println("Version:", version)
os.Exit(0)
}