diff --git a/CHANGELOG.md b/CHANGELOG.md index 1202bbb1f..b7e4d3d5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,15 @@ ## v0.1.6 [unreleased] ### Features -[#112](https://github.com/influxdb/telegraf/pull/112): Datadog output. Thanks @jipperinbham! -[#116](https://github.com/influxdb/telegraf/pull/116): Use godep to vendor all dependencies -[#120](https://github.com/influxdb/telegraf/pull/120): Httpjson plugin. Thanks @jpalay & @alvaromorales! +- [#112](https://github.com/influxdb/telegraf/pull/112): Datadog output. Thanks @jipperinbham! +- [#116](https://github.com/influxdb/telegraf/pull/116): Use godep to vendor all dependencies +- [#120](https://github.com/influxdb/telegraf/pull/120): Httpjson plugin. Thanks @jpalay & @alvaromorales! ### Bugfixes -[#113](https://github.com/influxdb/telegraf/issues/113): Update README with Telegraf/InfluxDB compatibility -[#118](https://github.com/influxdb/telegraf/pull/118): Fix for disk usage stats in Windows. Thanks @srfraser! -[#122](https://github.com/influxdb/telegraf/issues/122): Fix for DiskUsage segv fault. Thanks @srfraser! +- [#113](https://github.com/influxdb/telegraf/issues/113): Update README with Telegraf/InfluxDB compatibility +- [#118](https://github.com/influxdb/telegraf/pull/118): Fix for disk usage stats in Windows. Thanks @srfraser! +- [#122](https://github.com/influxdb/telegraf/issues/122): Fix for DiskUsage segv fault. Thanks @srfraser! +- [#126](https://github.com/influxdb/telegraf/issues/126): Nginx plugin not catching net.SplitHostPort error ## v0.1.5 [2015-08-13] diff --git a/plugins/nginx/nginx.go b/plugins/nginx/nginx.go index 75b17232b..00a7a174c 100644 --- a/plugins/nginx/nginx.go +++ b/plugins/nginx/nginx.go @@ -20,7 +20,7 @@ type Nginx struct { var sampleConfig = ` # An array of Nginx stub_status URI to gather stats. -urls = ["localhost/status"]` +urls = ["http://localhost/status"]` func (n *Nginx) SampleConfig() string { return sampleConfig @@ -125,8 +125,8 @@ func (n *Nginx) gatherUrl(addr *url.URL, acc plugins.Accumulator) error { return err } - host, _, _ := net.SplitHostPort(addr.Host) - tags := map[string]string{"server": host} + tags := getTags(addr) + acc.Add("active", active, tags) acc.Add("accepts", accepts, tags) acc.Add("handled", handled, tags) @@ -138,6 +138,18 @@ func (n *Nginx) gatherUrl(addr *url.URL, acc plugins.Accumulator) error { return nil } +// 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} +} + func init() { plugins.Add("nginx", func() plugins.Plugin { return &Nginx{} diff --git a/plugins/nginx/nginx_test.go b/plugins/nginx/nginx_test.go index 6184f9b44..5e1eb1e79 100644 --- a/plugins/nginx/nginx_test.go +++ b/plugins/nginx/nginx_test.go @@ -14,12 +14,23 @@ import ( ) const sampleResponse = ` -Active connections: 585 +Active connections: 585 server accepts handled requests - 85340 85340 35085 -Reading: 4 Writing: 135 Waiting: 446 + 85340 85340 35085 +Reading: 4 Writing: 135 Waiting: 446 ` +// Verify that nginx tags are properly parsed based on the server +func TestNginxTags(t *testing.T) { + urls := []string{"http://localhost/endpoint", "http://localhost:80/endpoint"} + var addr *url.URL + for _, url1 := range urls { + addr, _ = url.Parse(url1) + tagMap := getTags(addr) + assert.Contains(t, tagMap["server"], "localhost") + } +} + func TestNginxGeneratesMetrics(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var rsp string