Use Telegraf to collect monitoring data from Java applications or Tomcat servers, and upload the data to a Simple Log Service Metricstore through Logtail to build a visual monitoring solution. This topic uses a Java application as an example.
Prerequisites
-
Java 1.6 or later is installed on your server.
-
A project and a Metricstore have been created. For more information, see Manage projects and Create a Metricstore.
Limits
Only Logtail 0.16.48 and later for Linux supports collecting monitoring data from Java applications or Tomcat servers. If you use an earlier version, upgrade it first. For more information, see Install Logtail on a Linux server.
Step 1: Create a Logtail collection configuration
Log on to the Simple Log Service console.
-
In the Import Data section, on the Monitoring Data tab, click Java Application Monitoring.
This example describes how to collect Java application monitoring data. To collect Tomcat monitoring data, click Tomcat Monitoring instead.
-
Select the target Project and MetricStore, and click Next. In the Select Log Space step, select an existing Project and MetricStore, or click Create Now on the right to create new ones, and then click Next.
-
On the Create Machine Group tab:
-
If you have an available machine group, click Use Existing Machine Groups. Select Host scenario and ECS. From the source machine group list, select the target machine group and click > to move it to the applied machine group list. Then, click Next.
-
If no machine groups are available, perform the following steps to create a machine group. In this example, an Elastic Compute Service (ECS) instance is used.
-
On the ECS Instance tab, in the Manually select instances section, select the target ECS instance and click Create.
For more information, see Install Logtail on ECS instances.
ImportantIf you want to collect logs from an ECS instance that belongs to a different Alibaba Cloud account than Simple Log Service, a server in a data center, or a server of a third-party cloud service provider, you must manually install Logtail. For more information, see Install Logtail on a Linux server. After you manually install Logtail, you must configure a user identifier for the server. For more information, see Configure a user identifier.
-
After the installation is complete, click Complete Installation.
-
On the Create Machine Group page, enter a Name and click Next.
In Simple Log Service, you can create IP address-based machine groups and custom identifier-based machine groups. For more information, see Create a machine group.
-
-
-
Confirm that the machine group is displayed in the Applied Server Groups section and click Next.
ImportantIf you apply a machine group immediately after you create the machine group, the heartbeat status of the machine group may be FAIL. This issue occurs because the machine group is not connected to Simple Log Service. To resolve this issue, you can click Automatic Retry. If the issue persists, see What do I do if no heartbeat connections are detected on Logtail?
-
On the Data Source Settings tab, configure the following parameters.
Parameter
Description
Configuration Name
The name for the Logtail data collection configuration.
Cluster Name
The name for the Tomcat cluster.
After you set this parameter, Simple Log Service adds a
cluster=<Cluster Name>tag to the Tomcat monitoring data collected through this configuration.ImportantEnsure that the cluster name is unique. Otherwise, data conflicts may occur.
Application Name
The name of the application.
Servers
The Tomcat servers to monitor. The following parameters are included:
-
Address: The address of the Tomcat server.
-
Port: The port number of the Tomcat server. The default value is 7777.
You can add information about multiple servers based on your business requirements.
Custom Tag
Custom key-value tags to add to the collected Tomcat monitoring data.
After you set this parameter, Simple Log Service adds these tags to the Tomcat monitoring data collected through this configuration.
-
Step 2: Configure JavaAgent
After you create the Logtail collection configuration, convert the Java Management Extensions (JMX) protocol to HTTP. Simple Log Service supports Jolokia for this conversion. You can download and load Jolokia by following the official documentation, or use the Jolokia JavaAgent bundled with Logtail at /etc/ilogtail/telegraf/javaagent/jolokia-jvm.jar.
-
For a standard Java application, add
-javaagent:/etc/ilogtail/telegraf/javaagent/jolokia-jvm.jar=port=7777to the Java startup parameters. -
For Tomcat, set the
JAVA_OPTSenvironment variable. For example,export JAVA_OPTS="-javaagent:/etc/ilogtail/telegraf/jolokia-jvm.jar=port=7777". The server port 7777 must be the same as the port number that you specified in Step 1: Create a Logtail collection configuration.
By default, Jolokia JavaAgent listens only on 127.0.0.1, accepting requests only from the local host. If Logtail and the monitored application are on different machines, add the host= field to listen on other IP addresses. Setting it to host=0.0.0.0 listens on all IP addresses. Example command:
-javaagent:/tmp/jolokia-jvm.jar=port=7777,host=0.0.0.0
After you complete the configuration, restart the application. If you cannot restart immediately, run the following command to attach the Jolokia JavaAgent to a specific Java process. Replace Process_PID with the actual process ID.
This operation is for testing only. Complete the configuration as described in the preceding steps to ensure the settings persist across restarts.
java -jar /etc/ilogtail/telegraf/javaagent/jolokia-jvm.jar --port 7777 start Process_PID
If the following information is returned, the connection is successful.
Jolokia is already attached to PID 752
http://127.0.0.1:7777/jolokia/
After a successful connection, access the URL to verify that it is working.
curl http://127.0.0.1:7777/jolokia/
# Sample response
{"request":{"type":"version"},"value":{"agent":"1.6.2","protocol":"7.2","config":{"listenForHttpService":"true","maxCollectionSize":"0","authIgnoreCerts":"false","agentId":"30.**.**.186-752-5b091b5d-jvm","debug":"false","agentType":"jvm","policyLocation":"classpath:\/jolokia-access.xml","agentContext":"\/jolokia","serializeException":"false","mimeType":"text\/plain","maxDepth":"15","authMode":"basic","authMatch":"any","discoveryEnabled":"true","streaming":"true","canonicalNaming":"true","historyMaxEntries":"10","allowErrorDetails":"true","allowDnsReverseLookup":"true","realm":"jolokia","includeStackTrace":"true","maxObjects":"0","useRestrictorService":"false","debugMaxEntries":"100"},"info":{"product":"tomcat","vendor":"Apache","version":"8.5.57"}},"timestamp":1602663330,"status":200}⏎
FAQ
How can I check whether Telegraf collects data as expected?
You can check the logs of the /etc/ilogtail/telegraf/telegraf.log file on your server. You can also collect this log file to Log Service and search for the required information.
What to do next
- Search and analyze
After you complete the settings, Telegraf uses the Logtail to upload collected metrics to the Metricstore of Log Service. You can query the data on the Search & Analysis page of the Metricstore. For more information, see Query and analyze metric data.
-
Visualization
-
After you configure Java application monitoring, Simple Log Service automatically creates a dashboard named Java Application Monitoring_<Cluster Name> in the corresponding project. You can use this dashboard directly or set alerts on it.
-
After you configure Tomcat monitoring, Simple Log Service automatically creates a dashboard named Tomcat Monitoring_<Cluster Name> in the corresponding project. You can use this dashboard directly or set alerts on it.
-