How to configure multiple Java web applications in New Relic

21 September 2013
By Gonçalo Marques
In this tutorial we will see 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:

  1. 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

enable_auto_app_naming: true

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 value

<display-name>applicationOne</display-name>

We may also define it by the means of a context parameter:

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:

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:

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:

Programmatic New Relic application name definition

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");
  }

}

Related Articles

Comments

About the author
Gonçalo Marques is a Software Engineer with several years of experience in software development and architecture definition. During this period his main focus was delivering software solutions in banking, telecommunications and governmental areas. He created the Bytes Lounge website with one ultimate goal: share his knowledge with the software development community. His main area of expertise is Java and open source.

GitHub profile: https://github.com/gonmarques

He is also the author of the WiFi File Browser Android application: