feat(inputs.vsphere): Add VM memory configuration (#11591)

Co-authored-by: Dane Strandboge <136023093+DStrand1@users.noreply.github.com>
This commit is contained in:
6monlambert 2024-10-14 21:00:39 +02:00 committed by GitHub
parent 02a4ad58d5
commit c9a7582b12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 44 additions and 21 deletions

View File

@ -537,7 +537,7 @@ override the default query interval in the vSphere plugin.
* CPU: demand, usage, readiness, cost, mhz * CPU: demand, usage, readiness, cost, mhz
* Datastore: latency, # reads/writes * Datastore: latency, # reads/writes
* Disk: commands, latency, # reads/writes, provisioned, usage * Disk: commands, latency, # reads/writes, provisioned, usage
* Memory: granted, usage, active, swap, vmmemctl * Memory: granted, usage, active, swap, vmmemctl, memorySizeMB (allocated), memoryReservation
* Network: broadcast, bytes, dropped, multicast, packets, usage * Network: broadcast, bytes, dropped, multicast, packets, usage
* Power: energy, usage * Power: energy, usage
* Res CPU: active, max, running * Res CPU: active, max, running

View File

@ -95,15 +95,17 @@ type metricEntry struct {
type objectMap map[string]*objectRef type objectMap map[string]*objectRef
type objectRef struct { type objectRef struct {
name string name string
altID string altID string
ref types.ManagedObjectReference ref types.ManagedObjectReference
parentRef *types.ManagedObjectReference // Pointer because it must be nillable parentRef *types.ManagedObjectReference // Pointer because it must be nillable
guest string guest string
dcname string memorySizeMB int32
rpname string memoryReservation int32
customValues map[string]string dcname string
lookup map[string]string rpname string
customValues map[string]string
lookup map[string]string
} }
func (e *Endpoint) getParent(obj *objectRef, res *resourceKind) (*objectRef, bool) { func (e *Endpoint) getParent(obj *objectRef, res *resourceKind) (*objectRef, bool) {
@ -845,6 +847,7 @@ func getVMs(ctx context.Context, e *Endpoint, resourceFilter *ResourceFilter) (o
} }
uuid = r.Config.Uuid uuid = r.Config.Uuid
} }
cvs := make(map[string]string) cvs := make(map[string]string)
if e.customAttrEnabled { if e.customAttrEnabled {
for _, cv := range r.Summary.CustomValue { for _, cv := range r.Summary.CustomValue {
@ -863,14 +866,16 @@ func getVMs(ctx context.Context, e *Endpoint, resourceFilter *ResourceFilter) (o
} }
} }
m[r.ExtensibleManagedObject.Reference().Value] = &objectRef{ m[r.ExtensibleManagedObject.Reference().Value] = &objectRef{
name: r.Name, name: r.Name,
ref: r.ExtensibleManagedObject.Reference(), ref: r.ExtensibleManagedObject.Reference(),
parentRef: r.Runtime.Host, parentRef: r.Runtime.Host,
guest: guest, guest: guest,
altID: uuid, memorySizeMB: r.Summary.Config.MemorySizeMB,
rpname: rpname, memoryReservation: r.Summary.Config.MemoryReservation,
customValues: e.loadCustomAttributes(r.ManagedEntity), altID: uuid,
lookup: lookup, rpname: rpname,
customValues: e.loadCustomAttributes(r.ManagedEntity),
lookup: lookup,
} }
} }
return m, nil return m, nil
@ -1268,6 +1273,7 @@ func (e *Endpoint) collectChunk(
nValues := 0 nValues := 0
alignedInfo, alignedValues := e.alignSamples(em.SampleInfo, v.Value, interval) alignedInfo, alignedValues := e.alignSamples(em.SampleInfo, v.Value, interval)
globalFields := e.populateGlobalFields(objectRef, resourceType, prefix)
for idx, sample := range alignedInfo { for idx, sample := range alignedInfo {
// According to the docs, SampleInfo and Value should have the same length, but we've seen corrupted // According to the docs, SampleInfo and Value should have the same length, but we've seen corrupted
@ -1287,7 +1293,11 @@ func (e *Endpoint) collectChunk(
bKey := mn + " " + v.Instance + " " + strconv.FormatInt(ts.UnixNano(), 10) bKey := mn + " " + v.Instance + " " + strconv.FormatInt(ts.UnixNano(), 10)
bucket, found := buckets[bKey] bucket, found := buckets[bKey]
if !found { if !found {
bucket = metricEntry{name: mn, ts: ts, fields: make(map[string]interface{}), tags: t} fields := make(map[string]interface{})
for k, v := range globalFields {
fields[k] = v
}
bucket = metricEntry{name: mn, ts: ts, fields: fields, tags: t}
buckets[bKey] = bucket buckets[bKey] = bucket
} }
@ -1414,6 +1424,19 @@ func (e *Endpoint) populateTags(objectRef *objectRef, resourceType string, resou
} }
} }
func (e *Endpoint) populateGlobalFields(objectRef *objectRef, resourceType, prefix string) map[string]interface{} {
globalFields := make(map[string]interface{})
if resourceType == "vm" && objectRef.memorySizeMB != 0 {
_, fieldName := e.makeMetricIdentifier(prefix, "memorySizeMB")
globalFields[fieldName] = strconv.Itoa(int(objectRef.memorySizeMB))
}
if resourceType == "vm" && objectRef.memoryReservation != 0 {
_, fieldName := e.makeMetricIdentifier(prefix, "memoryReservation")
globalFields[fieldName] = strconv.Itoa(int(objectRef.memoryReservation))
}
return globalFields
}
func (e *Endpoint) makeMetricIdentifier(prefix, metric string) (metricName, fieldName string) { func (e *Endpoint) makeMetricIdentifier(prefix, metric string) (metricName, fieldName string) {
parts := strings.Split(metric, ".") parts := strings.Split(metric, ".")
if len(parts) == 1 { if len(parts) == 1 {

View File

@ -258,8 +258,8 @@ func init() {
"HostSystem": {"parent", "summary.customValue", "customValue"}, "HostSystem": {"parent", "summary.customValue", "customValue"},
"ResourcePool": {"parent", "customValue"}, "ResourcePool": {"parent", "customValue"},
"VirtualMachine": {"runtime.host", "config.guestId", "config.uuid", "runtime.powerState", "VirtualMachine": {"runtime.host", "config.guestId", "config.uuid", "runtime.powerState",
"summary.customValue", "guest.guestId", "guest.net", "guest.hostName", "resourcePool", "summary.customValue", "summary.config.memorySizeMB", "guest.guestId", "guest.net", "guest.hostName",
"customValue"}, "resourcePool", "customValue"},
"Datastore": {"parent", "info", "customValue"}, "Datastore": {"parent", "info", "customValue"},
"ClusterComputeResource": {"parent", "customValue"}, "ClusterComputeResource": {"parent", "customValue"},
"Datacenter": {"parent", "customValue"}, "Datacenter": {"parent", "customValue"},