Java Virtual Machine (JVM) supports multiple metrics. You can collect metric data from JVM servers to the Full-stack Monitoring application. This way, you can monitor the data in a visualized manner.
- An instance is created. For more information, see Create an instance.
- Java 1.6 or later is installed on your server.
Step 1: Create a Logtail configuration
- Log on to the Log Service console.
- In the Log Application section, click Full-stack Monitoring.
- On the Full-stack Monitoring page, click the instance.
- On the Data Import page, enable JVM.
If this is your first time to create a Logtail configuration for host monitoring, turn on the switch to go to the configuration page. If you have created a Logtail configuration, click the icon to go to the configuration page.
- In the Install Logtail step, select the machine on which you want to install Logtail and click Next.
Notice Make sure that the server on which you want to install Logtail can connect to the JVM server whose metric data you want to collect.
- If you want to install Logtail on an Elastic Compute Service (ECS) instance, select the ECS instance on the ECS Instances tab and click Execute Now. For more information, see Install Logtail on ECS instances.
- If you want to install Logtail on a self-managed Linux server or a Linux server from a third-party cloud, you must manually install Logtail V0.16.48 or later on the server. For more information, see Install Logtail on a Linux server.
- In the Create Machine Group step, create a machine group and click Next.
- In the Machine Group Settings step, select the machine group that you create in the Source Server Groups section and move the machine group to the Applied Server Groups section. Then, click Next. Notice If you immediately apply a machine group after it is created, the heartbeat status of the machine group may be FAIL. This issue occurs because the machine group is not connected to Log Service. In this case, you can click Automatic Retry. If the issue persists, see What do I do if no heartbeat connections are detected on Logtail?
- In the Specify Data Source step, configure the following parameters and click Complete.
Parameter Description Configuration Name The name of the Logtail configuration. You can enter a custom value. Cluster Name The name of the JVM cluster. You can enter a custom value.
After you configure this parameter, Log Service adds a cluster=Cluster name tag to the JVM monitoring data that is collected by using the Logtail configuration.Notice Make sure that the cluster name is unique. Otherwise, data conflicts may occur.
Application Name The name of the Java application. You can enter a custom value. Server List The information about the JVM server. The information includes the following configuration items:
- Address: the address of the JVM server.
- Port: the port number of the JVM server. Default value: 7777.
You can add information about multiple JVM servers based on your business requirements.
Custom Tags The custom tags that are added to the collected JVM monitoring data. The tags are key-value pairs.
After you configure this parameter, Log Service adds the custom tags to the JVM monitoring data that is collected by using the Logtail configuration.
After you complete the configurations, Log Service automatically creates assets such as Metricstores. For more information, see Assets.
Step 2: Configure JavaAgent
After you create the Logtail configuration, you must configure JavaAgent on the JVM server. Log Service allows you to use Jolokia to configure JavaAgent. For more information, see Jolokia. You can download and use Jolokia based on the official documentation of Jolokia. You can also use Jolokia JavaAgent that is provided together with Logtail in Log Service. Jolokia JavaAgent is stored in /etc/ilogtail/telegraf/javaagent/jolokia-jvm.jar.
- Add the script
-javaagent:/etc/ilogtail/telegraf/javaagent/jolokia-jvm.jar=port=7777to the Java startup parameters.7777 is the port number of the server. Make sure that the port number is the same as the port number that you specify in Step 1: Create a Logtail configuration.Note By default, Jolokia JavaAgent listens only on the IP address 127.0.0.1 and allows requests only from the local host. If Logtail and your Java application are installed on different servers, you can add the host= field to the added script. This way, Jolokia JavaAgent can listen on other IP addresses. If you add host=0.0.0.0, Jolokia JavaAgent listens on all IP addresses. Example:
- Restart your Java application. If your Java application fails to restart, run the following command to connect Jolokia JavaAgent to a specified Java process. This way, the configuration immediately takes effect. Replace Java PID with the actual value.Notice This operation is used only for testing. In actual scenarios, you must complete the configuration based on preceding descriptions. Otherwise, the configuration becomes invalid after your application restarts.
java -jar /etc/ilogtail/telegraf/javaagent/jolokia-jvm.jar --port 7777 start Java PIDIf information similar to the following code is returned, the connection is successful:
Jolokia is already attached to PID 752 http://127.0.0.1:7777/jolokia/
- Access the following URL to verify the connection:
curl http://127.0.0.1:7777/jolokia/If information similar to the following code is returned, the connection is normal:
What to do next
After JVM monitoring data is collected to Log Service, the Full-stack Monitoring application automatically creates dedicated dashboards for the monitoring data. You can use the dashboards to analyze the monitoring data. For more information, see View dashboards.