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

Nginx Plus stats #2405

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 14 additions & 5 deletions plugins/inputs/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Nginx struct {
}

var sampleConfig = `
## An array of Nginx stub_status URI to gather stats.
## An array of ngx_http_stub_status_module or ngx_http_status_module or status URI to gather stats.
urls = ["http://localhost/status"]
`

Expand All @@ -30,7 +30,7 @@ func (n *Nginx) SampleConfig() string {
}

func (n *Nginx) Description() string {
return "Read Nginx's basic status information (ngx_http_stub_status_module)"
return "Read Nginx's basic status information (ngx_http_stub_status_module) or Nginx's Plus full status information (ngx_http_status_module)"
}

func (n *Nginx) Gather(acc telegraf.Accumulator) error {
Expand Down Expand Up @@ -72,10 +72,20 @@ func (n *Nginx) gatherUrl(addr *url.URL, acc telegraf.Accumulator) error {
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("%s returned HTTP status %s", addr.String(), resp.Status)
}
r := bufio.NewReader(resp.Body)
contentType := strings.Split(resp.Header.Get("Content-Type"), ";")[0]
switch contentType {
case "text/plain":
return gatherStubStatusUrl(bufio.NewReader(resp.Body), getTags(addr), acc)
case "application/json":
return gatherStatusUrl(bufio.NewReader(resp.Body), getTags(addr), acc)
default:
return fmt.Errorf("%s returned unexpected content type %s", addr.String(), contentType)
}
}

func gatherStubStatusUrl(r *bufio.Reader, tags map[string]string, acc telegraf.Accumulator) error {
// Active connections
_, err = r.ReadString(':')
_, err := r.ReadString(':')
if err != nil {
return err
}
Expand Down Expand Up @@ -131,7 +141,6 @@ func (n *Nginx) gatherUrl(addr *url.URL, acc telegraf.Accumulator) error {
return err
}

tags := getTags(addr)
fields := map[string]interface{}{
"active": active,
"accepts": accepts,
Expand Down
Loading