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

Add port tag to nginx plugin #223

Closed
wants to merge 2 commits into from
Closed
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
22 changes: 14 additions & 8 deletions plugins/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
16 changes: 14 additions & 2 deletions plugins/nginx/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down