一、创建ES集群和部署APM Server
参考:腾讯云大数据ES创建和部署
二、集成APM Java agent
参考:官网集成说明
jvm参数方式:
-javaagent:D:/codesoft/elastic-apm-agent-1.18.0.jar -Delastic.apm.service_name=maniy-application -Delastic.apm.server_urls=http://localhost:8200 -Delastic.apm.application_packages=com.maniy -Delastic.apm.secret_token=
CODE方式
1、添加apm的maven依赖
<!-- APM 应用监控 --><dependency><groupId>co.elastic.apm</groupId><artifactId>apm-agent-attach</artifactId><version>1.33.0</version></dependency>
2、SpringBootApplication类添加监控代码
import co.elastic.apm.attach.ElasticApmAttacher;
import org.springframework.boot.SpringApplication;@SpringBootApplication
public class MyApplication {public static void main(String[] args) {ElasticApmAttacher.attach();SpringApplication.run(MyApplication.class, args);}
}
3、配置APM
#在配置文件elasticapm.properties中添加如下配置
service_name=maniy-service
application_packages=com.maniy
server_urls=http://127.0.0.1:8200
或者在application.yml中
#elastic APM 应用监控
elastic:apm:server_name: ${spring.application.name}application_packages: com.maniy# 支持使用路径use_path_as_transaction_name: trueserver_urls: http://127.0.0.1:8200
以上参数未声明,取默认值,并且优先级 yml>环境变量
参考:官网-APM配置