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

new plugin: nginx_plus #3214

Merged
merged 14 commits into from
Sep 19, 2017
Merged

Conversation

poblahblahblah
Copy link
Contributor

@poblahblahblah poblahblahblah commented Sep 9, 2017

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

@poblahblahblah
Copy link
Contributor Author

@danielnelson Here's a copy that compiles but needs a bit of cleanup. Before I dig deeper it would be nice if you could give it a quick once over. I'll clean up my WIP commits once we're ready to actually merge.

@mplonka here's a new PR retaining your original commits


### Measurements & Fields:

- Measurement
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be cleaned up to reflect what nginx plus will give us.

### Tags:

- All measurements have the following tags:
- port
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably needs to get cleaned up.

}
contentType := strings.Split(resp.Header.Get("Content-Type"), ";")[0]
switch contentType {
case "text/plain":
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a holdover from the previous PR - this should probably just be removed as the nginx plus status module will just return JSON.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, just try to parse and don't worry about this being set correctly.

"time"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal/errchan"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was working off an old master, so I will need to rebase and get rid of all calls to errchan.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


### Measurements & Fields:

- nginx_processes
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielnelson should these be renamed to nginx_plus_<measurement> ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it should be easy for anyone to change the prefix with name_override if they prefer the shorter name.

Also removing code that was specific to regular nginx. The nginx plus status
url should always return JSON.
@danielnelson danielnelson added this to the 1.5.0 milestone Sep 12, 2017
Copy link
Contributor

@danielnelson danielnelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good

### Reference material

Structures for Nginx Plus have been built based on history of
[status module documentation](http://nginx.org/en/docs/http/ngx_http_status_module.html)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets move this up to the first section, and mention that you need a commercial license to have access to this module.

var client = &http.Client{
Transport: tr,
Timeout: time.Duration(4 * time.Second),
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the Client and Transport part of the NginxPlus struct, this way they won't need to share configuration values if you have more than one plugin instance.

Bonus points if you want to add SSL support and a timeout option, but not required.

@poblahblahblah
Copy link
Contributor Author

@danielnelson Updated PR per feedback and added a timeout. My golang-fu isn't too great so I would rather tackle SSL support in a follow up PR, if possible.


client := &http.Client{
Timeout: n.ResponseTimeout.Duration,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize the client only once, probably above since it can be shared between goroutines. Use a new http.Transport, I'd just follow the original nginx plugin here: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/nginx/nginx.go#L63-L69. If you don't have TLS support then the transport can be initialized like &Transport{}

The reason for this is that each http.Transport/http.Client comes with it's own connection pool and this will allow the connection to be kept alive between Gather intervals.

- upstream
- server
- port
- serverAddress
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be server_address to match the naming style. This is the address of the upstream? If so maybe it would be more descriptive to call it upstream_address?


- nginx_plus_upstream_peer, nginx_plus_stream_upstream_peer
- id
- host
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't list host since it is added globally by Telegraf (depending on config).

It produces:
```
* Plugin: inputs.nginx_plus, Collection 1
> nginx_plus_processes,server=localhost,port=12021,host=word.local respawned="0xc420075538" 1504922954000000000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

respawned is an address, this is probably a bug where we need to dereference a pointer.

Copy link
Contributor Author

@poblahblahblah poblahblahblah Sep 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielnelson I think I fixed all of these. Here's the commit: 33fe1f0 - It looks like in the original commits the test was written like this, which was making the tests pass:

                       "selected": func() *int64 {
                               var v int64 = 1451606400000
                               return &v
                       }(),

I updated the test to just expect the int64:

                       "selected":               int64(1451606400000),

And updated the map:

"selected":               *peer.Selected,

Those were the only two instances where this was happening. I made the changes to both nginx_plus.go and the tests, and made sure this compiled. I then ran telegraf in test mode against one of our load balancers and I did not see any addresses in the output.

If this looks like a good fix I will update the README to remove the addresses from the sample output.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will want to check that they are not nil before dereferencing, I assume they are pointers because in some versions they don't exist.

Copy link
Contributor Author

@poblahblahblah poblahblahblah Sep 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you recommend I do that? Something like this for respawned?

func (s *Status) gatherProcessesMetrics(tags map[string]string, acc telegraf.Accumulator) {
    var respawned int

    if s.Processes.Respawned != nil {
      respawned = *s.Processes.Respawned
    }

    acc.AddFields(
        "nginx_plus_processes",
        map[string]interface{}{
            "respawned": respawned,
        },
        tags,
    )

}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a fix in c84861a

> nginx_plus_ssl,server=localhost,port=12021,host=word.local handshakes=0i,handshakes_failed=0i,session_reuses=0i 1504922954000000000
> nginx_plus_requests,host=word.local,server=localhost,port=12021 total=147885504244i,current=10019i 1504922954000000000
> nginx_plus_upstream,host=word.local,upstream=dataserver80,server=localhost,port=12021 zombies=0i,keepalive=0i 1504922954000000000
> nginx_plus_upstream_peer,id=0,server=localhost,port=12021,host=word.local,upstream=dataserver80,serverAddress=10.10.102.181:80 responses_5xx=27831i,healthchecks_unhealthy=1i,downtime=484817i,healthchecks_last_passed=true,responses_1xx=0i,active=22i,requests=2620930i,responses_total=2620652i,fails=4i,downstart=0i,state="up",responses_4xx=16i,healthchecks_checks=14133i,selected="0xc4201b22e8",response_time=95i,responses_2xx=2592805i,weight=1i,responses_3xx=0i,sent=3802831967i,received=536695496i,unavail=4i,healthchecks_fails=27i,header_time=94i,backup=false 1504922954000000000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selected also has an address and probably needs dereferenced. Double check that other similar pointers are dereferenced.

@danielnelson
Copy link
Contributor

This will be in 1.5, thanks @poblahblahblah @mplonka

maxunt pushed a commit that referenced this pull request Jun 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants