Added support for Tengine (#1390)

* Adds support for Tengine

* Added #1390 Tengine PR to changelog
This commit is contained in:
Iiro Uusitalo 2016-06-21 16:22:51 +03:00 committed by Cameron Sparr
parent 1f10639222
commit d50a1e83ac
3 changed files with 39 additions and 9 deletions

View File

@ -4,6 +4,7 @@
- [#1340](https://github.com/influxdata/telegraf/issues/1340): statsd: do not log every dropped metric.
- [#1368](https://github.com/influxdata/telegraf/pull/1368): Add precision rounding to all metrics on collection.
- [#1390](https://github.com/influxdata/telegraf/pull/1390): Add support for Tengine
### Bugfixes

View File

@ -97,11 +97,12 @@ func (n *Nginx) gatherUrl(addr *url.URL, acc telegraf.Accumulator) error {
if err != nil {
return err
}
data := strings.SplitN(strings.TrimSpace(line), " ", 3)
data := strings.Fields(line)
accepts, err := strconv.ParseUint(data[0], 10, 64)
if err != nil {
return err
}
handled, err := strconv.ParseUint(data[1], 10, 64)
if err != nil {
return err
@ -116,7 +117,7 @@ func (n *Nginx) gatherUrl(addr *url.URL, acc telegraf.Accumulator) error {
if err != nil {
return err
}
data = strings.SplitN(strings.TrimSpace(line), " ", 6)
data = strings.Fields(line)
reading, err := strconv.ParseUint(data[1], 10, 64)
if err != nil {
return err

View File

@ -13,12 +13,18 @@ import (
"github.com/stretchr/testify/require"
)
const sampleResponse = `
const nginxSampleResponse = `
Active connections: 585
server accepts handled requests
85340 85340 35085
Reading: 4 Writing: 135 Waiting: 446
`
const tengineSampleResponse = `
Active connections: 403
server accepts handled requests request_time
853 8533 3502 1546565864
Reading: 8 Writing: 125 Waiting: 946
`
// Verify that nginx tags are properly parsed based on the server
func TestNginxTags(t *testing.T) {
@ -36,7 +42,9 @@ func TestNginxGeneratesMetrics(t *testing.T) {
var rsp string
if r.URL.Path == "/stub_status" {
rsp = sampleResponse
rsp = nginxSampleResponse
} else if r.URL.Path == "/tengine_status" {
rsp = tengineSampleResponse
} else {
panic("Cannot handle request")
}
@ -49,12 +57,20 @@ func TestNginxGeneratesMetrics(t *testing.T) {
Urls: []string{fmt.Sprintf("%s/stub_status", ts.URL)},
}
var acc testutil.Accumulator
nt := &Nginx{
Urls: []string{fmt.Sprintf("%s/tengine_status", ts.URL)},
}
err := n.Gather(&acc)
require.NoError(t, err)
var acc_nginx testutil.Accumulator
var acc_tengine testutil.Accumulator
fields := map[string]interface{}{
err_nginx := n.Gather(&acc_nginx)
err_tengine := nt.Gather(&acc_tengine)
require.NoError(t, err_nginx)
require.NoError(t, err_tengine)
fields_nginx := map[string]interface{}{
"active": uint64(585),
"accepts": uint64(85340),
"handled": uint64(85340),
@ -63,6 +79,17 @@ func TestNginxGeneratesMetrics(t *testing.T) {
"writing": uint64(135),
"waiting": uint64(446),
}
fields_tengine := map[string]interface{}{
"active": uint64(403),
"accepts": uint64(853),
"handled": uint64(8533),
"requests": uint64(3502),
"reading": uint64(8),
"writing": uint64(125),
"waiting": uint64(946),
}
addr, err := url.Parse(ts.URL)
if err != nil {
panic(err)
@ -81,5 +108,6 @@ func TestNginxGeneratesMetrics(t *testing.T) {
}
tags := map[string]string{"server": host, "port": port}
acc.AssertContainsTaggedFields(t, "nginx", fields, tags)
acc_nginx.AssertContainsTaggedFields(t, "nginx", fields_nginx, tags)
acc_tengine.AssertContainsTaggedFields(t, "nginx", fields_tengine, tags)
}