diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 76c419f8a51..71a908f2250 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -214,6 +214,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] *Metricbeat* +- Add support for new metrics for vSphere module datastorecluster metricset. {pull}40694[40694] *Osquerybeat* diff --git a/metricbeat/docs/fields.asciidoc b/metricbeat/docs/fields.asciidoc index 0016c473805..8f3ccce6fff 100644 --- a/metricbeat/docs/fields.asciidoc +++ b/metricbeat/docs/fields.asciidoc @@ -67175,6 +67175,26 @@ format: bytes -- +*`vsphere.datastorecluster.datastore.names`*:: ++ +-- +List of all the Datastore names associated with the Datastore Cluster. + + +type: keyword + +-- + +*`vsphere.datastorecluster.datastore.count`*:: ++ +-- +Number of datastores in the Datastore Cluster. + + +type: long + +-- + [float] === host diff --git a/metricbeat/module/vsphere/datastorecluster/_meta/data.json b/metricbeat/module/vsphere/datastorecluster/_meta/data.json index 833b852c6da..10a4d2f98de 100644 --- a/metricbeat/module/vsphere/datastorecluster/_meta/data.json +++ b/metricbeat/module/vsphere/datastorecluster/_meta/data.json @@ -21,6 +21,12 @@ }, "free_space": { "bytes": 8788836876288 + }, + "datastore": { + "count": 1, + "names": [ + "LocalDS_0" + ] } } } diff --git a/metricbeat/module/vsphere/datastorecluster/_meta/fields.yml b/metricbeat/module/vsphere/datastorecluster/_meta/fields.yml index 8e22bb6259d..50ce1ca9d44 100644 --- a/metricbeat/module/vsphere/datastorecluster/_meta/fields.yml +++ b/metricbeat/module/vsphere/datastorecluster/_meta/fields.yml @@ -17,4 +17,12 @@ type: long description: > Total free space on this storage pod, in bytes. - format: bytes \ No newline at end of file + format: bytes + - name: datastore.names + type: keyword + description: > + List of all the Datastore names associated with the Datastore Cluster. + - name: datastore.count + type: long + description: > + Number of datastores in the Datastore Cluster. \ No newline at end of file diff --git a/metricbeat/module/vsphere/datastorecluster/data.go b/metricbeat/module/vsphere/datastorecluster/data.go index 8abdc5e695d..d7c7903c62c 100644 --- a/metricbeat/module/vsphere/datastorecluster/data.go +++ b/metricbeat/module/vsphere/datastorecluster/data.go @@ -23,12 +23,18 @@ import ( "github.com/elastic/elastic-agent-libs/mapstr" ) -func (m *DatastoreClusterMetricSet) mapEvent(datastoreCluster mo.StoragePod) mapstr.M { - event := mapstr.M{} - - event.Put("name", datastoreCluster.Name) - event.Put("capacity.bytes", datastoreCluster.Summary.Capacity) - event.Put("free_space.bytes", datastoreCluster.Summary.FreeSpace) - - return event +func (m *DatastoreClusterMetricSet) mapEvent(datastoreCluster mo.StoragePod, data *metricData) mapstr.M { + return mapstr.M{ + "name": datastoreCluster.Name, + "capacity": mapstr.M{ + "bytes": datastoreCluster.Summary.Capacity, + }, + "free_space": mapstr.M{ + "bytes": datastoreCluster.Summary.FreeSpace, + }, + "datastore": mapstr.M{ + "names": data.assetNames.outputDsNames, + "count": len(data.assetNames.outputDsNames), + }, + } } diff --git a/metricbeat/module/vsphere/datastorecluster/data_test.go b/metricbeat/module/vsphere/datastorecluster/data_test.go index de181264210..41d1736777e 100644 --- a/metricbeat/module/vsphere/datastorecluster/data_test.go +++ b/metricbeat/module/vsphere/datastorecluster/data_test.go @@ -38,7 +38,7 @@ func TestEventMapping(t *testing.T) { }, } - event := (&DatastoreClusterMetricSet{}).mapEvent(datastoreClusterTest) + event := (&DatastoreClusterMetricSet{}).mapEvent(datastoreClusterTest, &metricData{assetNames: assetNames{outputDsNames: []string{"DCS_0"}}}) name, _ := event.GetValue("name") assert.Equal(t, "Folder1", name) @@ -48,4 +48,10 @@ func TestEventMapping(t *testing.T) { freeSpace, _ := event.GetValue("free_space.bytes") assert.Equal(t, int64(50), freeSpace) + + datastoreNames, _ := event.GetValue("datastore.names") + assert.Equal(t, []string{"DCS_0"}, datastoreNames) + + datastoreCount, _ := event.GetValue("datastore.count") + assert.Equal(t, 1, datastoreCount) } diff --git a/metricbeat/module/vsphere/datastorecluster/datastorecluster.go b/metricbeat/module/vsphere/datastorecluster/datastorecluster.go index 5d20217202a..dd26fa7ba04 100644 --- a/metricbeat/module/vsphere/datastorecluster/datastorecluster.go +++ b/metricbeat/module/vsphere/datastorecluster/datastorecluster.go @@ -20,8 +20,10 @@ package datastorecluster import ( "context" "fmt" + "strings" "github.com/vmware/govmomi" + "github.com/vmware/govmomi/property" "github.com/vmware/govmomi/view" "github.com/vmware/govmomi/vim25/mo" @@ -55,6 +57,14 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { return &DatastoreClusterMetricSet{ms}, nil } +type metricData struct { + assetNames assetNames +} + +type assetNames struct { + outputDsNames []string +} + func (m *DatastoreClusterMetricSet) Fetch(ctx context.Context, reporter mb.ReporterV2) error { ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -84,18 +94,45 @@ func (m *DatastoreClusterMetricSet) Fetch(ctx context.Context, reporter mb.Repor }() var datastoreCluster []mo.StoragePod - err = v.Retrieve(ctx, []string{"StoragePod"}, nil, &datastoreCluster) + err = v.Retrieve(ctx, []string{"StoragePod"}, []string{"name", "summary", "childEntity"}, &datastoreCluster) if err != nil { return fmt.Errorf("error in retrieve from vsphere: %w", err) } + pc := property.DefaultCollector(c) for i := range datastoreCluster { if ctx.Err() != nil { return ctx.Err() } - reporter.Event(mb.Event{MetricSetFields: m.mapEvent(datastoreCluster[i])}) + assetNames, err := getAssetNames(ctx, pc, &datastoreCluster[i]) + if err != nil { + m.Logger().Errorf("Failed to retrieve object from host %s: %w", datastoreCluster[i].Name, err) + } + + reporter.Event(mb.Event{MetricSetFields: m.mapEvent(datastoreCluster[i], &metricData{assetNames: assetNames})}) } return nil } + +func getAssetNames(ctx context.Context, pc *property.Collector, dsc *mo.StoragePod) (assetNames, error) { + var objects []mo.ManagedEntity + if len(dsc.ChildEntity) > 0 { + if err := pc.Retrieve(ctx, dsc.ChildEntity, []string{"name"}, &objects); err != nil { + return assetNames{}, err + } + } + + outputDsNames := make([]string, 0) + for _, ob := range objects { + if ob.Reference().Type == "Datastore" { + name := strings.ReplaceAll(ob.Name, ".", "_") + outputDsNames = append(outputDsNames, name) + } + } + + return assetNames{ + outputDsNames: outputDsNames, + }, nil +} diff --git a/metricbeat/module/vsphere/fields.go b/metricbeat/module/vsphere/fields.go index 05e29ff253c..729c11e6264 100644 --- a/metricbeat/module/vsphere/fields.go +++ b/metricbeat/module/vsphere/fields.go @@ -32,5 +32,5 @@ func init() { // AssetVsphere returns asset data. // This is the base64 encoded zlib format compressed contents of module/vsphere. func AssetVsphere() string { - return "eJzUXEuP2zgSvudXFOayCdDx3PuwQDbBTAJsJ4M409cGTZUtblOklizZcH79gKQoybYkvyin24cgcNusr94PlvwennF7D2tb5mjwDQAJkngPv63n/p3f3gBkaLkRJQmt7uHfbwAA6r9CobNKuq8ZlMgs3sOKvQFYCpSZvfcffQ+KFdgl4V60Ld2Hja7K+p0eKrsHdQ/jsrKEpnm/70D3amAtkFjn/V5i4fUxHA1CLbUpmPvIrPOBfURdVBkjZkk3TI5jGzqte6L71x78NZ74jNuNNlnP30f4i6//Ckugl8CkBMoRPkXwgSgwazUXjDCDjaDcf6YW+2wQL9eVokG8UqvVZWC/VsUCjYPbwDwDYasf+8S1Wop9FJcriGWFsNbZCNeKjJYzVGwhsU8pgcpCa4lMXSaHLyoTnBFa2ORIORqwZASnFgfUOEBYqKEMq+vGWGPU+PwBlsioMjiIMiLMtd23p8uVNb11ftaWLnSdG7q6Q3mul3dh9iqkH+ERdDHYulMH6CFttHl+RTbwNSB++WZQAz3HEsYyXb9ORnD1HbJbR8TXWNLlrGRc0Ha2NIizxZYOxDeo2iMy+8Mggj/QSc3Jo0G8r79QKtzDIfkDmKSJyaQ4f7gT0wOtLGZJcf5tMZsIZsn7s4TlTGL2tJSa7X/gCNi/0HBUxFbowDZAG7rg6Q7ALsOXe4EvrYOWLoT+ISTarSUs/CnDaXTWF/ou1WUb7tzRdoRqX0C7gt39IJY3uawfg9BlKvudkzbOHr78/g0+1lUWW60MrnzU/KLK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