From d55e00d2c09e95e19048b44d61be44748a477a71 Mon Sep 17 00:00:00 2001 From: Ruslan Islamgaliev Date: Wed, 23 Sep 2015 03:05:54 +0300 Subject: [PATCH 1/2] Add port tag to nginx plugin --- plugins/nginx/nginx.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/plugins/nginx/nginx.go b/plugins/nginx/nginx.go index 97f273b63..36caf7a63 100644 --- a/plugins/nginx/nginx.go +++ b/plugins/nginx/nginx.go @@ -141,16 +141,22 @@ func (n *Nginx) gatherUrl(addr *url.URL, acc plugins.Accumulator) error { // Get tag(s) for the nginx 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 - } else { - htag = h - } - return map[string]string{"server": htag} + h := addr.Host + 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() { plugins.Add("nginx", func() plugins.Plugin { return &Nginx{} From 283578f947d6285d7dd0faed691e0c1177eeeb80 Mon Sep 17 00:00:00 2001 From: Ruslan Islamgaliev Date: Wed, 23 Sep 2015 21:43:44 +0300 Subject: [PATCH 2/2] Make nginx_test check port in nginx module tags --- plugins/nginx/nginx_test.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/plugins/nginx/nginx_test.go b/plugins/nginx/nginx_test.go index 5e1eb1e79..4031baf59 100644 --- a/plugins/nginx/nginx_test.go +++ b/plugins/nginx/nginx_test.go @@ -70,8 +70,20 @@ func TestNginxGeneratesMetrics(t *testing.T) { if err != nil { panic(err) } - host, _, _ := net.SplitHostPort(addr.Host) - tags := map[string]string{"server": host} + + host, port, err := net.SplitHostPort(addr.Host) + if err != nil { + host = addr.Host + if addr.Scheme == "http" { + port = "80" + } else if addr.Scheme == "https" { + port = "443" + } else { + port = "" + } + } + + tags := map[string]string{"server": host, "port": port} for _, m := range metrics { assert.NoError(t, acc.ValidateTaggedValue(m.name, m.value, tags))