use non-greedy regex to match a log to fix an error if ngxlog fields are more than pre-defined #62
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi Lebinh
I find an error in matching if my nginx log's fields are more than pre-defined, this error causes ngxtop cannot output any stats result.
My nginx log looks like:
10.18.110.79 - - [31/Mar/2016:14:19:00 +0800] "GET /favicon.ico HTTP/1.1" 200 1406 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36 SE 2.X MetaSr 1.0" "-" "yangchao-g.jifen.360.cn" "80" 0.000
after $http_user_agent, I have 3 extra fields.
the current ngxtop matching result is:
{
'remote_addr': '10.18.110.79',
'remote_user': '-',
'time_local': '31/Mar/2016:14:19:00 +0800',
'request': 'GET /favicon.ico HTTP/1.1" 200 1406 "-',
'status': '"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36 SE 2.X MetaSr 1.0"',
'body_bytes_sent': '"-"',
'http_referer': 'yangchao-g.jifen.360.cn',
'http_user_agent': '80',
}
you see that the request field eats more bytes than it should.
the fix is to use non-greedy-matching regex.