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

Cherry-pick #7793 to 6.x: Fixes to metricbeat's KVM module #8706

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ https://github.com/elastic/beats/compare/v6.4.0...6.x[Check the HEAD diff]
- Fix issue that would prevent kafka module to find a proper broker when port is not set {pull}8613[8613]
- Fix range colors in multiple visualizations. {issue}8633[8633] {pull}8634[8634]
- Fix incorrect header parsing on http metricbeat module {issue}8564[8564] {pull}8585[8585]
- Fixed a panic when the kvm module cannot establish a connection to libvirtd. {issue}7792[7792].

*Packetbeat*

Expand Down
5 changes: 4 additions & 1 deletion metricbeat/docs/modules/kvm.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ metricbeat.modules:
metricsets: ["dommemstat"]
enabled: true
period: 10s
hosts: ["localhost"]
hosts: ["unix:///var/run/libvirt/libvirt-sock"]
# For remote hosts, setup network access in libvirtd.conf
# and use the tcp scheme:
# hosts: [ "tcp://<host>:16509" ]

# Timeout to connect to Libvirt server
#timeout: 1s
Expand Down
5 changes: 4 additions & 1 deletion metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,10 @@ metricbeat.modules:
metricsets: ["dommemstat"]
enabled: true
period: 10s
hosts: ["localhost"]
hosts: ["unix:///var/run/libvirt/libvirt-sock"]
# For remote hosts, setup network access in libvirtd.conf
# and use the tcp scheme:
# hosts: [ "tcp://<host>:16509" ]

# Timeout to connect to Libvirt server
#timeout: 1s
Expand Down
5 changes: 4 additions & 1 deletion metricbeat/module/kvm/_meta/config.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
metricsets: ["dommemstat"]
enabled: true
period: 10s
hosts: ["localhost"]
hosts: ["unix:///var/run/libvirt/libvirt-sock"]
# For remote hosts, setup network access in libvirtd.conf
# and use the tcp scheme:
# hosts: [ "tcp://<host>:16509" ]

# Timeout to connect to Libvirt server
#timeout: 1s
2 changes: 1 addition & 1 deletion metricbeat/module/kvm/_meta/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#metricsets:
# - dommemstat
period: 10s
hosts: ["localhost"]
hosts: ["unix:///var/run/libvirt/libvirt-sock"]
35 changes: 21 additions & 14 deletions metricbeat/module/kvm/dommemstat/dommemstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@
package dommemstat

import (
"errors"
"net"
"net/url"
"time"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/cfgwarn"
"github.com/elastic/beats/metricbeat/mb"
"github.com/pkg/errors"

"github.com/digitalocean/go-libvirt"
"github.com/digitalocean/go-libvirt/libvirttest"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/cfgwarn"
"github.com/elastic/beats/metricbeat/mb"
)

const (
Expand Down Expand Up @@ -101,30 +102,40 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) {

c, err = net.DialTimeout(u.Scheme, address, m.Timeout)
if err != nil {
report.Error(err)
report.Error(errors.Wrapf(err, "cannot connect to %v", u))
return
}
}

defer c.Close()

l := libvirt.New(c)
if err := l.Connect(); err != nil {
report.Error(err)
if err = l.Connect(); err != nil {
report.Error(errors.Wrap(err, "error connecting to libvirtd"))
return
}
defer func() {
if err = l.Disconnect(); err != nil {
report.Error(errors.Wrap(err, "failed to disconnect"))
}
}()

domains, err := l.Domains()
if err != nil {
report.Error(err)
report.Error(errors.Wrap(err, "error listing domains"))
return
}

for _, d := range domains {
gotDomainMemoryStats, err := l.DomainMemoryStats(d, maximumStats, flags)
if err != nil {
report.Error(err)
report.Error(errors.Wrapf(err, "error fetching memory stats for domain %s", d.Name))
continue
}

if len(gotDomainMemoryStats) == 0 {
report.Error(errors.New("no domain memory stats found"))
report.Error(errors.Errorf("no memory stats for domain %s", d.Name))
continue
}

for i := range gotDomainMemoryStats {
Expand All @@ -140,10 +151,6 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) {
})
}
}

if err := l.Disconnect(); err != nil {
report.Error(errors.New("failed to disconnect"))
}
}

func getDomainMemoryStatName(tag int32) string {
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/modules.d/kvm.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
#metricsets:
# - dommemstat
period: 10s
hosts: ["localhost"]
hosts: ["unix:///var/run/libvirt/libvirt-sock"]