Buy Support Online

Monitoring JMX Using the Notification Service

09 Feb 2018

Previously in GlassFish and Payara Server, if you wanted to monitor the status of your application's MBeans, you would have to rely mostly on external programs to capture the data. In Payara Server 174, we integrated the JMX Monitoring service with our existing notification service, meaning that you can now remotely receive monitoring data via any of our notifiers, from email to Slack.

In this blog I will look at enabling JMX Monitoring for the JVM Heap Size and then monitoring the MBean `java.lang:type=memory`, UsedHeapSize. For a full list of MBeans available within Payara Server, see the documentation.

 

Enabling JMX Monitoring

While Monitoring at a server level is enabled by default, it must be specifically enabled for each module. To receive monitoring data from Payara Server, you will need to:

  • Enable the Monitoring Service
  • Configure a notifier
  • Enabling JMX Monitoring

If you don't already have it enabled, the monitoring service can be started by using asadmin commands or via the admin console.

Via asadmin commands

The monitoring service itself is enabled by default. However, should you need to enable the monitoring service, use the following asadmin command:

 

asadmin> enable-monitoring

 

You will then need to decide which module (such as the ejb-container, etc) you wish to log. There are three levels of logging: OFF (the default), where no data is captured, LOW, where only very basic counts are captured, and HIGH, where all data that can be found is captured. To view the current logging status of all modules, run the following command:

 

asadmin> get "server.monitoring-service.*"
  ...
  server.monitoring-service.module-monitoring-levels.connector-connection-pool=HIGH
  server.monitoring-service.module-monitoring-levels.connector-service=HIGH
  server.monitoring-service.module-monitoring-levels.deployment=LOW
  server.monitoring-service.module-monitoring-levels.ejb-container=HIGH
  ...

 

To start logging from a module, run the enable-monitoring command, separating multiple modules with colons:

 
asadmin> enable-monitoring --modules deployment=HIGH:ejb-container=HIGH:web-container=HIGH

 

Via the admin console

To enable monitoring for a module via the admin console, navigate to Configurations → <Your Configuration> → Monitoring. Select the modules you wish to enable from the list and set their Level to "HIGH":

 

1 - monitoring JMX blog.png

 

Configuring a notifier

Getting the Hipchat token

For my notifier I will be using Hipchat, but any of the notifiers within the Notification section will work for pushing monitoring, healthcheck, and request-tracing data.

To activate the Hipchat notifier, you will need to get a room notification token from Hipchat.

In another tab I have opened the Hipchat account settings and opened my room settings from the Room page. Here you can create the token which will allow you to authenticate to Hipchat from Payara Server. The label should be something sensible, as messages sent using this token will appear as if the label had sent them.

 

2 - monitoring JMX blog.png

Via asadmin commands

By default the Notification Service is enabled; if not, you can enable it using the following command:

 

asadmin> notification-configure --enabled=true --dynamic=true

 

Each notifier has its own command. To enable the Hipchat notifier, use the following command:

asadmin> notification-hipchat-configure --dynamic=true --enabled=true --roomName=<Room name or number> --token=<Hipchat Token> --target=<Your Config>

To test that your configuration works, run the command:

asadmin> test-hipchat-notifier-configuration --roomName=<Room name or number> --target=server-config --token=<Hipchat Token>

4 - monitoring JMX blog.png

Via the admin console

Go to Configurations → <Your Configuration> → Notification, then select the "Hipchat" tab:

 

5 - monitoring JMX blog.png

 

With your token created, you can go back to the Admin Console and insert the details (as well as the "Room Name" which can either be the string or the number displayed in your browser's address bar):

 

6 - monitoring JMX blog.png

 

Once you've added the room name and token, you can test that the connection is working properly using the "Test" button. If you've entered the correct token for the room, and the correct room number, you should see something like this:

 

7 - monitoring JMX blog.png

 

Enabling JMX Monitoring

Via asadmin commands

We first need to link our chosen notifier to the monitoring service. Each notifier has a command along the lines of:

 

monitoring-<notifier>-notifier-configure

 

To add the Hipchat Notifier to the Monitoring Service, run the above command with the following arguments:

monitoring-hipchat-notifier-configure --dynamic true --enabled true --target server-config

Finally, to enable JMX monitoring for the MBean "java.lang:type=Memory", run the following command:

asadmin> set-monitoring-configuration --dynamic true --enabled true --amx true --logfrequency 15 --logfrequencyunit SECONDS --addattribute 'name=java.lang:type=Memory value=HeapMemoryUsage'

 

8 - monitoring JMX blog.png

 

At the top of the page, we'll enable both JMX monitoring and enable AMX, allowing us to access all MBean data on the server. We also need to add our Hipchat notifier to the Selected Notifiers:

 

9 - monitoring JMX blog.png

 

Finally, if you scroll down on this page you will see a table titled "Monitored Attributes". This is where we will add the MBean data which we want to track. For further information on the MBeans available by default within Payara Server, see the documentation.

 

10 - monitoring JMX blog.png

 

Save the page, and voila, you should receive your JMX Monitoring notifications through Hipchat, or your notifier of choice:

 

11 - monitoring JMX blog.png

 

 

 

Comments

Subscribe

Themes

see all