Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Update vSphere yaml and dimensions (#1148)
Browse files Browse the repository at this point in the history
* Fix minor problems and flag default metrics in metadata.yaml
* Rename ESX IP dimension 'esx_ip' from 'host_name'
* Remove extraneous 'os_type' dimension from ESX metrics
* Apply esx_ip dimension to VM-level metrics
* Add OS info as dimensions to VM metrics
* Add vCenter IP dimension to all metrics to support multiple vCenters

This is in support of new vSphere built in content:
Issue: https://signalfuse.atlassian.net/browse/INT-1717
  • Loading branch information
Pablo Collins authored Jan 17, 2020
1 parent f0bd442 commit a3c5b1e
Show file tree
Hide file tree
Showing 12 changed files with 1,035 additions and 975 deletions.
358 changes: 179 additions & 179 deletions docs/monitors/vsphere.md

Large diffs are not rendered by default.

410 changes: 211 additions & 199 deletions pkg/monitors/vsphere/genmetadata.go

Large diffs are not rendered by default.

382 changes: 191 additions & 191 deletions pkg/monitors/vsphere/metadata.yaml

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion pkg/monitors/vsphere/service/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ type IGateway interface {
queryPerfProviderSummary(mor types.ManagedObjectReference) (*types.QueryPerfProviderSummaryResponse, error)
queryPerf(invObjs []*model.InventoryObject, maxSample int32) (*types.QueryPerfResponse, error)
retrieveCurrentTime() (*time.Time, error)
vcenterName() string
}

type Gateway struct {
ctx context.Context
client *govmomi.Client
vcName string
}

func NewGateway(ctx context.Context, client *govmomi.Client) *Gateway {
return &Gateway{ctx, client}
return &Gateway{
ctx: ctx,
client: client,
vcName: client.Client.URL().Host,
}
}

func (g *Gateway) retrievePerformanceManager() (*mo.PerformanceManager, error) {
Expand Down Expand Up @@ -102,3 +108,7 @@ func (g *Gateway) queryPerf(invObjs []*model.InventoryObject, maxSample int32) (
func (g *Gateway) retrieveCurrentTime() (*time.Time, error) {
return methods.GetCurrentTime(g.ctx, g.client)
}

func (g *Gateway) vcenterName() string {
return g.vcName
}
21 changes: 13 additions & 8 deletions pkg/monitors/vsphere/service/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ func (svc *InventorySvc) retrieveCluster(ref types.ManagedObjectReference, inv *
return nil, err
}

hostInvObj := model.NewInventoryObject(host.Self, map[string]string{
"host_name": host.Name,
"os_type": host.Config.Product.OsType,
})
hostDims := map[string]string{
"esx_ip": host.Name,
}
hostInvObj := model.NewInventoryObject(host.Self, hostDims)
inv.AddObject(hostInvObj)

for _, vmRef := range host.Vm {
Expand All @@ -102,10 +102,15 @@ func (svc *InventorySvc) retrieveCluster(ref types.ManagedObjectReference, inv *
return nil, err
}

vmInvObj := model.NewInventoryObject(vm.Self, map[string]string{
"vm_name": vm.Name,
"guest_id": vm.Config.GuestId,
})
vmDims := map[string]string{
"vm_name": vm.Name, // e.g. "MyDebian10Host"
"guest_id": vm.Config.GuestId, // e.g. "debian10_64Guest"
"vm_ip": vm.Guest.IpAddress,
"guest_family": vm.Guest.GuestFamily, // e.g. "linuxGuest"
"guest_fullname": vm.Guest.GuestFullName, // e.g. "Other 4.x or later Linux (64-bit)"
}
updateMap(vmDims, hostDims)
vmInvObj := model.NewInventoryObject(vm.Self, vmDims)
inv.AddObject(vmInvObj)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/monitors/vsphere/service/inventory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ func TestRetrieveInventory(t *testing.T) {
case model.HostType:
require.Equal(t, "host-0", dims["ref_id"])
require.Equal(t, model.HostType, dims["object_type"])
require.Equal(t, "foo host", dims["host_name"])
require.Equal(t, "foo os type", dims["os_type"])
require.Equal(t, "4.4.4.4", dims["esx_ip"])
case model.VMType:
require.Equal(t, "4.4.4.4", dims["esx_ip"])
require.Equal(t, "vm-0", dims["ref_id"])
require.Equal(t, model.VMType, dims["object_type"])
require.Equal(t, "foo vm", dims["vm_name"])
Expand Down
10 changes: 2 additions & 8 deletions pkg/monitors/vsphere/service/points.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func (svc *PointsSvc) RetrievePoints(vsInfo *model.VsphereInfo, numSamplesReqd i
dims["object"] = intSeries.Id.Instance
}

dims["vcenter"] = svc.gateway.vcenterName()

if len(intSeries.Value) > 0 && intSeries.Value[0] > 0 {
svc.log.Debugf(
"metric = %s, type = (%s->%s), dims = %v, values = %v",
Expand Down Expand Up @@ -93,14 +95,6 @@ func (svc *PointsSvc) RetrievePoints(vsInfo *model.VsphereInfo, numSamplesReqd i
return dps, latestSampleTime
}

func copyMap(in map[string]string) map[string]string {
out := make(map[string]string)
for k, v := range in {
out[k] = v
}
return out
}

func statsTypeToMetricType(statsType types.PerfStatsType) datapoint.MetricType {
switch statsType {
case types.PerfStatsTypeDelta:
Expand Down
1 change: 1 addition & 0 deletions pkg/monitors/vsphere/service/points_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ func TestRetrievePoints(t *testing.T) {
require.Equal(t, "vsphere.cpu_core_utilization_percent", pt.Metric)
require.Equal(t, datapoint.Count, pt.MetricType)
require.EqualValues(t, 1.11, pt.Value)
require.Equal(t, "my-vc", pt.Dimensions["vcenter"])
}
11 changes: 10 additions & 1 deletion pkg/monitors/vsphere/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (g *fakeGateway) retrieveRefProperties(mor types.ManagedObjectReference, ds
t.Name = "foo dc"
case *mo.HostSystem:
t.Self = mor
t.Name = "foo host"
t.Name = "4.4.4.4"
t.Config = &types.HostConfigInfo{
Product: types.AboutInfo{
OsType: "foo os type",
Expand All @@ -84,6 +84,11 @@ func (g *fakeGateway) retrieveRefProperties(mor types.ManagedObjectReference, ds
t.Config = &types.VirtualMachineConfigInfo{
GuestId: "foo guest id",
}
t.Guest = &types.GuestInfo{
IpAddress: "1.2.3.4",
GuestFamily: "fooFam",
GuestFullName: "fooFullName",
}
default:
return fmt.Errorf("type not found %v", t)
}
Expand Down Expand Up @@ -140,3 +145,7 @@ func (g *fakeGateway) createRefs(key string, prefix string, size int) []types.Ma
func (g *fakeGateway) retrieveCurrentTime() (*time.Time, error) {
panic("implement me")
}

func (g *fakeGateway) vcenterName() string {
return "my-vc"
}
15 changes: 15 additions & 0 deletions pkg/monitors/vsphere/service/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package service

func copyMap(in map[string]string) map[string]string {
out := make(map[string]string)
for k, v := range in {
out[k] = v
}
return out
}

func updateMap(target, updates map[string]string) {
for k, v := range updates {
target[k] = v
}
}
14 changes: 14 additions & 0 deletions pkg/monitors/vsphere/service/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package service

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestUpdateMap(t *testing.T) {
target := map[string]string{"foo": "bar"}
updates := map[string]string{"baz": "glarch"}
updateMap(target, updates)
require.Equal(t, target, map[string]string{"foo": "bar", "baz": "glarch"})
}
Loading

0 comments on commit a3c5b1e

Please sign in to comment.