How to configure multiple Java web applications in New Relic
Introduction
When we configure the New Relic agent to monitor our Java based application server it will by default aggregate all deployed web applications in a single application and show the corresponding aggregated performance indicators in New Relic's web console.
In this tutorial we will see how to configure multiple Java web applications to be listed individually in New Relic's console. We will assume that you have already deployed New Relic agent in your application server.
Used software:
- New Relic agent 2.21.3
New Relic settings file
The first step consists in changing enable_auto_app_naming parameter in the configuration file: newrelic.yml
Change the parameter value to true. Now we are ready to configure our web applications to be listed distinctly.
Configuring application names
Now that we have configured New Relic to show applications separately we just have to define the name than each one will have in the web console.
By default New Relic will use display-name value defined in web.xml:
<display-name>applicationOne</display-name>
We may also define it by the means of a context parameter:
<context-param> <param-name>com.newrelic.agent.APPLICATION_NAME</param-name> <param-value>applicationOne</param-value> </context-param>
If we need more fine-grained configuration we may define it individually by servlet:
<servlet> <servlet-name>TestServlet</servlet-name> <servlet-class>com.byteslounge.TestServlet</servlet-class> <init-param> <param-name>com.newrelic.agent.APPLICATION_NAME</param-name> <param-value>applicationOne</param-value> </init-param> </servlet>
Or even by filter:
<filter> <filter-name>TestFilter</filter-name> <filter-class>com.byteslounge.TestFilter</filter-class> <init-param> <param-name>com.newrelic.agent.APPLICATION_NAME</param-name> <param-value>applicationOne</param-value> </init-param> </filter>
We may also define it programmatically:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if(someCondition){ request.setAttribute("com.newrelic.agent.APPLICATION_NAME", "applicationOne"); } else { request.setAttribute("com.newrelic.agent.APPLICATION_NAME", "applicationTwo"); } }