-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
new plugin: nginx_plus #3214
Conversation
@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 |
plugins/inputs/nginx_plus/README.md
Outdated
|
||
### Measurements & Fields: | ||
|
||
- Measurement |
There was a problem hiding this comment.
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.
plugins/inputs/nginx_plus/README.md
Outdated
### Tags: | ||
|
||
- All measurements have the following tags: | ||
- port |
There was a problem hiding this comment.
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": |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
3372ebd
to
d204a2f
Compare
d204a2f
to
5987e64
Compare
plugins/inputs/nginx_plus/README.md
Outdated
|
||
### Measurements & Fields: | ||
|
||
- nginx_processes |
There was a problem hiding this comment.
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>
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good
plugins/inputs/nginx_plus/README.md
Outdated
### 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) |
There was a problem hiding this comment.
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), | ||
} |
There was a problem hiding this comment.
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.
@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. |
cdff0ea
to
f965bca
Compare
|
||
client := &http.Client{ | ||
Timeout: n.ResponseTimeout.Duration, | ||
} |
There was a problem hiding this comment.
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.
plugins/inputs/nginx_plus/README.md
Outdated
- upstream | ||
- server | ||
- port | ||
- serverAddress |
There was a problem hiding this comment.
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
?
plugins/inputs/nginx_plus/README.md
Outdated
|
||
- nginx_plus_upstream_peer, nginx_plus_stream_upstream_peer | ||
- id | ||
- host |
There was a problem hiding this comment.
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).
plugins/inputs/nginx_plus/README.md
Outdated
It produces: | ||
``` | ||
* Plugin: inputs.nginx_plus, Collection 1 | ||
> nginx_plus_processes,server=localhost,port=12021,host=word.local respawned="0xc420075538" 1504922954000000000 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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,
)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah
There was a problem hiding this comment.
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
plugins/inputs/nginx_plus/README.md
Outdated
> 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 |
There was a problem hiding this comment.
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.
3e2179d
to
b19a1da
Compare
This will be in 1.5, thanks @poblahblahblah @mplonka |
Required for all PRs: