All Products
Search
Document Center

Diagnose errors reported on the Java server

Last Updated: Mar 26, 2019

Web errors are one of the most common types of errors encountered by Internet applications. It can be difficult to diagnose the causes of these errors. Now, you only need to install ARMS Java Agent for your application to diagnose online errors, making using command lines and modifying the application code unnecessary.

Problem

Web errors, especially “5XX” errors, are one of the most common types of errors encountered by Internet applications. “5XX” errors usually occur on the server. The server is the most complex part of the business logic. It is also the most error-prone part in the entire network request link, and the most difficult part for error diagnosis. When errors occur, O&M engineers or R&D engineers have to log on to the faulty machines to view logs in order to locate the errors.

For applications with less complex logic and shorter usage duration, the engineers can generally log on to the faulty machines and locate web errors from logs. However, this traditional error diagnosis method often does not work in the following scenarios.

  • In a distributed Java application cluster, you may want to know how many times a type of error occurs every minute, and when it started.
  • The system has been running for a long time. You do not care about legacy exceptions, but only want to learn what new exceptions have occurred as of the current day, or what exceptions occurred after application publishing.
  • You may want to identify the Web request to which an error occurs and parameters of the Web request.
  • The customer service personnel requested you to locate the causes of a failed order.

Solution

By adding several lines of ARMS Java Agent loading codes into the application startup script (see Create an application monitoring job), you can use the automatic exception capturing, collection, statistics, and traceability capabilities of Application Real-Time Monitoring Service (ARMS) without modifying any application code. These capabilities help you fully understand application error information.

Next, this tutorial details how to perform the procedure.

Step 1: Install ARMS Java Agent for your application

To fully monitor your application, you must first install ARMS Java Agent.

Note: For EDAS applications, skip this step. For details about how to monitor EDAS applications, see Access EDAS applications in one click.

  1. Log on to the <span condition="site" label="span" tag="start"></span><span site="intl">[ARMS console](https://arms-intl.console.aliyun.com/#/home)</span><span end=""></span><span site="zh">[ARMS console](https://arms.console.aliyun.com/#/home)</span><span end=""></span><span condition="site" label="span" tag="end"></span>. In the left-side navigation pane, chooseApplication Monitoring > Applications.

  2. On the Application Monitoring page, click Add Application in the upper-right corner or the center.

  3. In the Add Application dialog box, enter the application name and click OK.

  4. On the Application Settings page, use either of the following methods to download the ARMS Java Agent package.

    • Method 1: Download directly. Click Click to Download to download the latest ZIP package.
    • Method 2: Run the wget command. Run the wget command to download the ARMS Java Agent package.

      1. wget "http://arms-apm-hangzhou.oss-cn-hangzhou.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
  5. Decompress the package and deploy ARMS Java Agent.

    1. Switch to the directory of the ArmsAgent package, and decompress the package to any working directory.

    2. On the Application Settings page, click the 2. Install Probe tab. On the tab page that is displayed, check the values of the arms.licenseKey and arms.appId attributes.

    3. Add the following code to the Java startup parameters.

      1. -javaagent:/{user.workspace}/ArmsAgent/arms-bootstrap-1.7.0-SNAPSHOT.jar -Darms.licenseKey=xxx -Darms.appId=xxx

      Note: Replace “xxx” with the values retrieved in the previous sub-step.

Step 2: View statistics on application exceptions

After ARMS Java Agent is installed, ARMS collects and displays performance metrics of the application, including exception information. You can perform the following steps to view statistics on corresponding application exceptions.

  1. In the left-side navigation pane of the ARMS console, chooseApplication Monitoring > Applications.

  2. On the Applications page, click the name of your application.

  3. On the Application Overview page, click the Overview Analysis tab. At the top of the tab page that is displayed, view the total number of exceptions, week-on-week data, and day-to-day data.

  4. On the Application Overview page, click the Overview Analysis tab. At the bottom of the tab page that is displayed, view the number of occurrences of each type of exception.

  5. In the left-side navigation pane, click Application Details. Then click the Exception Analysis tab on the right of the page. On the tab page that is displayed, view the exception statistics chart, count, and details.

Step 3: Diagnose the causes of exceptions

Causes of application exceptions cannot be located by using only the statistics. The Java exception stack in the log contains the code snippet for the call, but it does not contain the complete upstream and downstream information and request parameters of the call. ARMS Agent uses the bytecode enhancement technology. This allows you to capture complete upstream and downstream call snapshots at a low performance overhead, so that you can identify the causes of exceptions.

  1. On the Exception Analysis tab page, locate the row that contains the target exception type, and click Interface Snapshot in the Actions column. On the Interface Snapshot tab page, the trace information related to the exception is displayed.

  2. On the Interface Snapshot tab page, click a TraceId.

  3. On the displayed page, view the complete trace information, detailed request parameters, and exception logs to understand the context of the exception.

Step 4: Set alarms

Instead of passively diagnosing the cause of an error that has occurred, you can take actions in advance by using the alarm function of ARMS. You can set alarms for one or all interfaces so that the O&M team is notified immediately when an error on the interfaces is displayed.

For details about how to set alarms, see Quickly create an ARMS alarm task and Alarm description.

References