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

Added support for Tengine #1390

Merged
merged 2 commits into from
Jun 21, 2016
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions plugins/inputs/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
42 changes: 35 additions & 7 deletions plugins/inputs/nginx/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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")
}
Expand All @@ -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)},
}

var acc_nginx testutil.Accumulator
var acc_tengine testutil.Accumulator

err_nginx := n.Gather(&acc_nginx)
err_tengine := nt.Gather(&acc_tengine)

err := n.Gather(&acc)
require.NoError(t, err)
require.NoError(t, err_nginx)
require.NoError(t, err_tengine)

fields := map[string]interface{}{
fields_nginx := map[string]interface{}{
"active": uint64(585),
"accepts": uint64(85340),
"handled": uint64(85340),
Expand All @@ -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)
Expand All @@ -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)
}