fix for #126, nginx plugin not catching net.SplitHostPort error
This commit is contained in:
parent
ecfdafab06
commit
532d953b5a
13
CHANGELOG.md
13
CHANGELOG.md
|
@ -1,14 +1,15 @@
|
||||||
## v0.1.6 [unreleased]
|
## v0.1.6 [unreleased]
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
[#112](https://github.com/influxdb/telegraf/pull/112): Datadog output. Thanks @jipperinbham!
|
- [#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
|
- [#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!
|
- [#120](https://github.com/influxdb/telegraf/pull/120): Httpjson plugin. Thanks @jpalay & @alvaromorales!
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
[#113](https://github.com/influxdb/telegraf/issues/113): Update README with Telegraf/InfluxDB compatibility
|
- [#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!
|
- [#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!
|
- [#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]
|
## v0.1.5 [2015-08-13]
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ type Nginx struct {
|
||||||
|
|
||||||
var sampleConfig = `
|
var sampleConfig = `
|
||||||
# An array of Nginx stub_status URI to gather stats.
|
# An array of Nginx stub_status URI to gather stats.
|
||||||
urls = ["localhost/status"]`
|
urls = ["http://localhost/status"]`
|
||||||
|
|
||||||
func (n *Nginx) SampleConfig() string {
|
func (n *Nginx) SampleConfig() string {
|
||||||
return sampleConfig
|
return sampleConfig
|
||||||
|
@ -125,8 +125,8 @@ func (n *Nginx) gatherUrl(addr *url.URL, acc plugins.Accumulator) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
host, _, _ := net.SplitHostPort(addr.Host)
|
tags := getTags(addr)
|
||||||
tags := map[string]string{"server": host}
|
|
||||||
acc.Add("active", active, tags)
|
acc.Add("active", active, tags)
|
||||||
acc.Add("accepts", accepts, tags)
|
acc.Add("accepts", accepts, tags)
|
||||||
acc.Add("handled", handled, tags)
|
acc.Add("handled", handled, tags)
|
||||||
|
@ -138,6 +138,18 @@ func (n *Nginx) gatherUrl(addr *url.URL, acc plugins.Accumulator) error {
|
||||||
return nil
|
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() {
|
func init() {
|
||||||
plugins.Add("nginx", func() plugins.Plugin {
|
plugins.Add("nginx", func() plugins.Plugin {
|
||||||
return &Nginx{}
|
return &Nginx{}
|
||||||
|
|
|
@ -14,12 +14,23 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const sampleResponse = `
|
const sampleResponse = `
|
||||||
Active connections: 585
|
Active connections: 585
|
||||||
server accepts handled requests
|
server accepts handled requests
|
||||||
85340 85340 35085
|
85340 85340 35085
|
||||||
Reading: 4 Writing: 135 Waiting: 446
|
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) {
|
func TestNginxGeneratesMetrics(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
var rsp string
|
var rsp string
|
||||||
|
|
Loading…
Reference in New Issue