Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #7187/fix vsphere metricbeat host #7213

Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix marshaling of ms-since-epoch values in `elasticsearch/cluster_stats` metricset. {pull}14378[14378]
- Fix checking tagsFilter using length in cloudwatch metricset. {pull}14525[14525]
- Log bulk failures from bulk API requests to monitoring cluster. {issue}14303[14303] {pull}14356[14356]

- Vshpere module splits `virtualmachine.host` into `virtualmachine.host.id` and `virtualmachine.host.hostname`. {issue}7187[7187] {pull}7213[7213]
*Packetbeat*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a blank line between your entry and the packetbeat section?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


- Prevent duplicate packet loss error messages in HTTP events. {pull}10709[10709]
Expand Down
14 changes: 12 additions & 2 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -32469,10 +32469,20 @@ virtualmachine



*`vsphere.virtualmachine.host`*::
*`vsphere.virtualmachine.host.id`*::
+
--
Host name
Host id


type: keyword

--

*`vsphere.virtualmachine.host.hostname`*::
+
--
Host name of the host


type: keyword
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (

func init() {
common.RegisterCheckDeps(update.Update)

devtools.SetBuildVariableSources(devtools.DefaultBeatBuildVariableSources)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed?
If not, can you remove that line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove it..it should not be be there

devtools.BeatDescription = "Metricbeat is a lightweight shipper for metrics."
}

Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/vsphere/fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions metricbeat/module/vsphere/virtualmachine/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"mhz": 0
}
},
"host": "ha-host",
"host.id": "ha-host",
"host.hostname": "localhost.localdomain",
"memory": {
"free": {
"guest": {
Expand All @@ -41,4 +42,4 @@
"name": "ha-host_VM1"
}
}
}
}
8 changes: 6 additions & 2 deletions metricbeat/module/vsphere/virtualmachine/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
virtualmachine
release: beta
fields:
- name: host
- name: host.id
type: keyword
description: >
Host name
Host id
- name: host.hostname
type: keyword
description: >
Host name of the host
- name: name
type: keyword
description: >
Expand Down
23 changes: 20 additions & 3 deletions metricbeat/module/vsphere/virtualmachine/virtualmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ func (m *MetricSet) Fetch(ctx context.Context, reporter mb.ReporterV2) error {
"bytes": (int64(vm.Summary.QuickStats.GuestMemoryUsage) * 1024 * 1024),
},
"host": common.MapStr{
"bytes": (int64(vm.Summary.QuickStats.HostMemoryUsage) * 1024 * 1024),
"bytes": int64(vm.Summary.QuickStats.HostMemoryUsage) * 1024 * 1024,
},
},
"total": common.MapStr{
"guest": common.MapStr{
"bytes": (int64(vm.Summary.Config.MemorySizeMB) * 1024 * 1024),
"bytes": int64(vm.Summary.Config.MemorySizeMB) * 1024 * 1024,
},
},
"free": common.MapStr{
Expand All @@ -168,13 +168,19 @@ func (m *MetricSet) Fetch(ctx context.Context, reporter mb.ReporterV2) error {
}

if vm.Summary.Runtime.Host != nil {
event["host"] = vm.Summary.Runtime.Host.Value
event["host.id"] = vm.Summary.Runtime.Host.Value
} else {
m.Logger().Debug("'Host', 'Runtime' or 'Summary' data not found. This is either a parsing error " +
"from vsphere library, an error trying to reach host/guest or incomplete information returned " +
"from host/guest")
}

hostSystem, err := getHostSystem(ctx, c, vm.Summary.Runtime.Host.Reference())
if err != nil {
m.Logger().Debug(err.Error())
} else {
event["host.hostname"] = hostSystem.Summary.Config.Name
}
// Get custom fields (attributes) values if get_custom_fields is true.
if m.GetCustomFields && vm.Summary.CustomValue != nil {
customFields := getCustomFields(vm.Summary.CustomValue, customFieldsMap)
Expand Down Expand Up @@ -285,3 +291,14 @@ func setCustomFieldsMap(ctx context.Context, client *vim25.Client) (map[int32]st

return customFieldsMap, nil
}

func getHostSystem(ctx context.Context, c *vim25.Client, ref types.ManagedObjectReference) (*mo.HostSystem, error) {
pc := property.DefaultCollector(c)

var hs mo.HostSystem
err := pc.RetrieveOne(ctx, ref, []string{"summary"}, &hs)
if err != nil {
return nil, fmt.Errorf("error retrieving host information: %v", err)
}
return &hs, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func TestFetchEventContents(t *testing.T) {

t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), event.StringToPrint())

assert.EqualValues(t, "ha-host", event["host"])
assert.EqualValues(t, "ha-host", event["host.id"])
assert.EqualValues(t, "localhost.localdomain", event["host.hostname"])
assert.True(t, strings.Contains(event["name"].(string), "ha-host_VM"))

cpu := event["cpu"].(common.MapStr)
Expand Down