window 10安装和使用Elastic APM Server

官方文档:https://www.elastic.co/guide/en/apm/server/current/index.html

1、下载APM Server

2、安装APM Server

官方安装教程:https://www.elastic.co/guide/en/apm/server/current/installing.html
# 进入安装目录,管理员权限安装APM Server服务,会开机启动
cd D:\ELK\apm-server-7.15.0
PowerShell.exe -ExecutionPolicy UnRestricted -File .\install-service-apm-server.ps1

Status   Name               DisplayName
------   ----               -----------
Stopped  apm-server         apm-server

3、修改apm-server.yml配置

配置kibana

  #---------------------------- APM Server - Agent Configuration ----------------------------
  # 配置kibana
  kibana:
    enabled: true
    host: "kibana-host:5601"
    username: "elastic"
    password: "123456"
  #---------------------------- APM Server - ILM Index Lifecycle Management ----------------------------
  # 修改默认索引需要关闭ilm
  ilm:
    enabled: false
#================================= Template =================================
# 配置自定义索引模板名称
setup.template.name: "moss-oauth-apm"
setup.template.pattern: "moss-oauth-apm-*"
#-------------------------- Elasticsearch output --------------------------
# 配置es
output.elasticsearch:
  hosts: ["es-node-1-host:9200","es-node-2-host:9200"]
  username: "elastic"
  password: "123456"
  # 根据不同的服务生成不同的索引
  indices:
    - index: "moss-oauth-apm-%{+yyyy.MM.dd}"
      when.contains:
        service.name: "moss-oauth"

4、启动APM Server

默认的日志在:C:\ProgramData\apm-server

# 启动
net start apm-server

# 停止
net stop apm-server

5、安装APM Agent

支持的Agent:https://www.elastic.co/guide/en/apm/server/current/next-steps.html
官方教程:https://www.elastic.co/guide/en/apm/agent/java/1.x/setup.html

有三种安装方式
第一种:使用-javaagent

maven central下载elastic-apm-agent.jar
在这里插入图片描述
在这里插入图片描述
jar包启动的应用(springboot)使用

java -javaagent:d:/elastic-apm-agent-1.26.0.jar -Delastic.apm.service_name=my-cool-service -Delastic.apm.application_packages=org.example,org.another.example -Delastic.apm.server_url=http://localhost:8200 -jar my-application.jar

其它方式,如Tomcat,jetty等,见官方教程

第二种:使用apm-agent-attach-cli.jar自动安装(此安装方法是beta版),不推荐使用

具体操作见官方教程

第三种:代码入侵式的,在应用启动入口main方法中加入ElasticApmAttacher.attach()调用

添加依赖

<dependency>
    <groupId>co.elastic.apm</groupId>
    <artifactId>apm-agent-attach</artifactId>
    <version>${elastic-apm.version}</version>
</dependency>

在应用的配置文件中加入以下配置

service_name=my-cool-service
application_packages=org.example,org.another.example
server_url=http://localhost:8200

在启动入口加入ElasticApmAttacher.attach(),以springboot为例

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);
    }
}

6、启动应用

示例

java -javaagent:d:/elastic-apm-agent-1.26.0.jar -Delastic.apm.service_name=my-cool-service -Delastic.apm.application_packages=org.example,org.another.example -Delastic.apm.server_url=http://localhost:8200 -jar my-application.jar

7、登录kibana查看

生成的索引
在这里插入图片描述

服务
在这里插入图片描述
请求查看
在这里插入图片描述
关联节点
在这里插入图片描述

如果kibana上的APM显示无服务,要做以下配置

点击右上角的【设置】

在这里插入图片描述
点【索引】,因为默认是显示apm开头的索引的,上面更改了索引的名称,所以要在这里加进去
在这里插入图片描述
点【应用更改】就可以看到了

常见错误

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值