From ba2f767239a8b437283ab79d45e8ab9e3365c3e5 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Mon, 27 Jan 2020 13:15:08 +0100 Subject: [PATCH] [Metricbeat] Memcached: add support for Unix socket (#15822) * Memcached: add support for Unix socket * Use single host field for URI (cherry picked from commit 4a072f719e1d5b4cd143a2520fbbd529f26fc027) --- CHANGELOG.next.asciidoc | 4 ++++ metricbeat/module/memcached/stats/stats.go | 24 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 3e2aff8ea1b..0ba49cbc8b9 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -168,6 +168,10 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Add a `system/network_summary` metricset {pull}15196[15196] - Add IBM MQ light-weight Metricbeat module {pull}15301[15301] - Enable script processor. {pull}14711[14711] +- Add mesh metricset for Istio Metricbeat module {pull}15535[15535] +- Add mixer metricset for Istio Metricbeat module {pull}15696[15696] +- Make the `system/cpu` metricset collect normalized CPU metrics by default. {issue}15618[15618] {pull}15729[15729] +- Add support for Unix socket in Memcached metricbeat module. {issue}13685[13685] {pull}15822[15822] *Packetbeat* diff --git a/metricbeat/module/memcached/stats/stats.go b/metricbeat/module/memcached/stats/stats.go index be66dfc3e68..52c938a6342 100644 --- a/metricbeat/module/memcached/stats/stats.go +++ b/metricbeat/module/memcached/stats/stats.go @@ -20,15 +20,20 @@ package stats import ( "bufio" "net" + "net/url" "strings" "github.com/pkg/errors" "github.com/elastic/beats/metricbeat/mb" + "github.com/elastic/beats/metricbeat/mb/parse" ) +var hostParser = parse.URLHostParserBuilder{DefaultScheme: "tcp"}.Build() + func init() { mb.Registry.MustAddMetricSet("memcached", "stats", New, + mb.WithHostParser(hostParser), mb.DefaultMetricSet(), ) } @@ -47,7 +52,12 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { // format. It publishes the event which is then forwarded to the output. In case // of an error set the Error field of mb.Event or simply call report.Error(). func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { - conn, err := net.DialTimeout("tcp", m.Host(), m.Module().Config().Timeout) + network, address, err := m.getNetworkAndAddress() + if err != nil { + return errors.Wrap(err, "error in fetch") + } + + conn, err := net.DialTimeout(network, address, m.Module().Config().Timeout) if err != nil { return errors.Wrap(err, "error in fetch") } @@ -81,3 +91,15 @@ func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { return nil } + +func (m *MetricSet) getNetworkAndAddress() (network string, address string, err error) { + hostData := m.HostData() + u, err := url.Parse(hostData.URI) + if err != nil { + err = errors.Wrap(err, "invalid URL") + return + } + network = u.Scheme + address = u.Host + return +}