From 05804230b49f30737f29f553bd4c90b047920cd1 Mon Sep 17 00:00:00 2001 From: Ruslan Islamgaliev Date: Tue, 22 Sep 2015 17:20:24 +0300 Subject: [PATCH 1/2] Add port tag to apache plugin --- plugins/apache/apache.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/plugins/apache/apache.go b/plugins/apache/apache.go index 307f8490718fe..bd6c6ad4962c9 100644 --- a/plugins/apache/apache.go +++ b/plugins/apache/apache.go @@ -134,13 +134,11 @@ func (n *Apache) gatherScores(data string, acc plugins.Accumulator, tags map[str // Get tag(s) for the apache plugin func getTags(addr *url.URL) map[string]string { h := addr.Host - var htag string - if host, _, err := net.SplitHostPort(h); err == nil { - htag = host + if host, port, err := net.SplitHostPort(h); err == nil { + return map[string]string{"server": host, "port": port} } else { - htag = h + return map[string]string{"server": h, "port": "80"} } - return map[string]string{"server": htag} } func init() { From e1eb25abb03738289b59aa0936a38808797d60e4 Mon Sep 17 00:00:00 2001 From: Ruslan Islamgaliev Date: Tue, 22 Sep 2015 20:37:13 +0300 Subject: [PATCH 2/2] Select default apache port depending on url scheme --- plugins/apache/apache.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/apache/apache.go b/plugins/apache/apache.go index bd6c6ad4962c9..f4098b3313928 100644 --- a/plugins/apache/apache.go +++ b/plugins/apache/apache.go @@ -134,11 +134,18 @@ func (n *Apache) gatherScores(data string, acc plugins.Accumulator, tags map[str // Get tag(s) for the apache plugin func getTags(addr *url.URL) map[string]string { h := addr.Host - if host, port, err := net.SplitHostPort(h); err == nil { - return map[string]string{"server": host, "port": port} - } else { - return map[string]string{"server": h, "port": "80"} + host, port, err := net.SplitHostPort(h) + if err != nil { + host = addr.Host + if addr.Scheme == "http" { + port = "80" + } else if addr.Scheme == "https" { + port = "443" + } else { + port = "" + } } + return map[string]string{"server": host, "port": port} } func init() {