Tomcat request count only considers requests handeled by the default Servlet #878
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.
General information
CheckMK provides out-of-the-box-support for monitoring a Tomcat Application Server. This includes a metric for a request count.
Bug report
What is the expected behavior?
For each web application, the request count monitored by CheckMK should equal the total number of incoming HTTP requests, regardless of which Servlet responded to them.
What is the observed behavior?
For each web application, the request count monitored by CheckMK considers only HTTP request responded to by the "default" servlet, i.e. requests for static content such as images of CSS files.
The request count monitored by CheckMK is always significantly smaller than the actual request count for any given web application.
An extreme example would be a web application that only provides a REST-API and has no static content. In such a case, the request count would currently always be zero.
Proposed changes
Using Jolokia, query not just the request count of the "default" Servlet (which is a named Servlet with name
default). Query the request counts of all Servlets and aggregate the returned values.The agent plugin
mk_jolokia.pycontains two selectors for the request count of Servlets.The first one is currently active and queries only the named Servlet
default. If this selector is used, the response from Jolokia contains (per web application) only a single entry for a value namedrequestCount. This is the reqest count for the "default" Servlet. This causes the issue described above.The second one is currently commented out and queries all Servlets. If this selector is used, the response from Jolokia contains (per web application) multiple entries for values named
requestCount- one for each Servlet of the corresponding web application.When the response from Jolokia is processed, each of these entries is processes separately. For each entry, the
requestCountis extracted, but overwrites any previously extracted value. Therefore, only the last value would be seen by CheckMK. This would not be okay.It is therefore necessary to aggregate all entries containing a
requestCountinto a single such entry, before entries are further processed.This can be done in
fetch_metric.The approach described here and the change proposed in this PR are certainly not the most elegant solution to the problem, as they introduce hard-coded behavior for specific selectors. However, the method
fetch_metricalready includes hard-coded behavior for another specific selector (threadStatus,threadParam), so this should be acceptable.