▶ overview

Elastic APM is an application performance monitoring system based on Elastic Stack. With Elastic APM, applications can be monitored to gather detailed performance information about response times for requests, database queries, cache calls, external HTTP requests, and more so that performance problems can be identified and fixed more quickly.

Elastic APM also automatically collects unhandled errors and exceptions, and errors are grouped based on stack traces so that new errors can be identified and the number of times a particular error occurs can be closely monitored.

▶ APM components

Elastic APM consists of four components:

APM agent

APM Agent is an open source library written in the same language as the service, which can be installed into the service just like any other library. The Agent will detect the code of the service and collect performance data and errors at run time, which will be cached for a short time and sent to the APM Server.

APM server

APM Server is an open source application written in Go, usually running on a dedicated Server, listening on port 8200 by default and receiving data from the Agent via the JSON HTTP API, then creating documents from that data and storing it in Elasticsearch.

Elasticsearch

Elasticsearch is a highly extensible open source full-text search and analysis engine for storing, searching, and analyzing large amounts of data quickly and in near real time. This is used to store and aggregate APM performance metrics.

Kibana

Kibana is an open source analysis and visualization platform designed to work with Elasticsearch. You can use Kibana to search for and view data stored in Elasticsearch.

▶ Deploy the APM Server

1. Deploy Elasticsearch and Kibana

Reference: Deploying Elasticsearch with permission authentication using Docker

2. Edit the APM Server configuration file apm-server.yml

Elasticsearch: hosts: ["elasticsearch:9200"] username: "admin" password: "Passw0rd"Copy the code

For more information, see Config APM Server

3. Deploy the APM Server

docker run -d \ --name apm-server \ --link elasticsearch:elasticsearch \ -v `pwd`/apm-server.yml:/usr/share/apm-server/apm-server.yml \ -p 8200:8200 \ -e "TZ=Asia/Shanghai" \ Docker. Elastic. Co/apm/apm - server: 6.6.2Copy the code

Reference Document: Running APM Server on Docker

▶ APM Agent

Currently, APM Agent supports the following languages:

  • Java: Servlet API, Spring MVC, Spring Boot
  • Node.js: Express, HApi, Koa, Restify
  • Go: Gorilla, Gin
  • Python: Django, Flask
  • Ruby: Rails
  • RUM(Real User Monitoring) : Captures User interactions with clients, such as Web browsers

Reference: Installing and configuring APM Agents

▶ Example: Spring Boot & APM Agent

1. Download the Java Agent library

Download address: https://search.maven.org/search?q=a:elastic-apm-agent

2. Start the Spring Boot application

Using the spring-boot-demos/ Hello Spring Boot project as an example, after using Maven to package, run the following command to start the service:

java \
-javaagent:/path/to/elastic-apm-agent-<version>.jar \
-Delastic.apm.service_name=my-cool-service \
-Delastic.apm.application_packages=org.example,org.another.example \
-Delastic.apm.server_urls=http://localhost:8200 \
-jar <app-name>.jarCopy the code

If logs similar to the following are displayed, the Agent is successfully started:

The 2019-03-24 18:29:49. 027 / apm - server - healthcheck INFO co., elastic. The apm. Agent. The report. ApmServerHealthChecker - elastic apm server is available: {" ok ": {" build_date" : "the 2019-03-06 T14:11:42 Z", "build_sha" : "daad5449d758e7bf101f6482778a2b15f646a67f", "version" : "6.6.2"}} 18:29:49 2019-03-24. 215. [the main] INFO co., elastic. The apm. Agent. The configuration. The StartupInfo - Starting elastic apm 1.4.0 as My-application on Java 1.8.0_172 (Oracle Corporation) Mac OS X 10.14.3.........Copy the code

3. Access any address of the Spring Boot service for APM Agent to collect information

  • http://localhost:8080/
  • http://localhost:8080/user

> Kibana APM Dashboard

  • Kibana address: http://localhost:5601
  • Account/Password:admin / Passw0rd

Add APM data to the panel

Start the APM panel

APM service list

Interface request data

● Spring Boot injects static variables from external configuration into the application

● Convert HTML to PDF new pose

● Java calls the Docker API using UnixSocket

● Fastjson fatal flaw

● Service mesh-GRPC Local integrated remote Service

● Use Thymeleaf to render HTML dynamically

● Fastjson fatal flaw

● Spring Boot 2 integrates log4J2 logging framework

● Java interview key points summary set of core reference answers

● Java interview key points summary of the framework of reference answers

● How to protect your password

● Spring Boot RabbitMQ – Priority queue

This article is published by OpenWrite!