当前位置:   article > 正文

总结之使用Elastic APM监控SpringBoot服务_springboot集成 apm

springboot集成 apm

一、创建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=
  • 1

CODE方式

1、添加apm的maven依赖
<!-- APM 应用监控 -->
        <dependency>
            <groupId>co.elastic.apm</groupId>
            <artifactId>apm-agent-attach</artifactId>
            <version>1.33.0</version>
        </dependency>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
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);
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
3、配置APM

#在配置文件elasticapm.properties中添加如下配置

service_name=maniy-service
application_packages=com.maniy
server_urls=http://127.0.0.1:8200
  • 1
  • 2
  • 3

或者在application.yml中

#elastic APM 应用监控
elastic:
  apm:
    server_name: ${spring.application.name}
    application_packages: com.maniy
    # 支持使用路径
    use_path_as_transaction_name: true
    server_urls: http://127.0.0.1:8200
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

以上参数未声明,取默认值,并且优先级 yml>环境变量
参考:官网-APM配置

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/962048
推荐阅读
相关标签
  

闽ICP备14008679号