0%

开源APM工具pinpoint搭建使用

APM,全称:Application Performance Management (应用程序性能管理)。 在应用服务各节点相互调用的时候,从中记录并传递一个应用级别的标记,这个标记可以用来关联各个服务节点之间的关系。比如两个应用服务节点之间使用 HTTP 作为传输协议的话,那么这些标记就会被加入到 HTTP 头中。这样就可以更加精细化的分析应用性能,也就是计量应用程序在执行不同区域的代码已经完成事务过程找那个所消耗的具体时长,耗费资源情况。
商用软件:OneAPM,听云,透视宝,Oracle的EMCC等
开源软件:Pinpoint,SkyWalking,Zipkin,CAT

Pinpoint是开源在github(项目地址:https://github.com/naver/pinpoint )上的一款APM监控工具,它是用Java编写的,用于大规模分布式系统监控。它对性能的影响最小(只增加约3%资源利用率),安装agent是无侵入式的,只需要在被测试的Tomcat中加上3行内容,添加探针,就可以监控整套程序了。

软件环境

官方给的快速安装教程,是使用git clone代码,然后build编译安装,这样时间比较慢,而且容易出错,不方便排查,所以我们这里直接从https://github.com/naver/pinpoint/releases/ 下载war包,进行部署!

ps:如果hbase和pinpoint-collector、pinpoint-web部署在同一台机器,不用单独部署zookeeper;如果是下载war包部署,也不用安装maven
ps:不要使用hbase2.0,否则首页server map不显示

组件版本功能下载路径
zookeeper3.4.12应用程序协调http://mirror.bit.edu.cn/apache/zookeeper/stable/zookeeper-3.4.12.tar.gz
hbase1.2.9存储收集的数据http://mirror.bit.edu.cn/apache/hbase/hbase-1.2.9/hbase-1.2.9-bin.tar.gz
pinpoint-collector1.8.1收集各种性能数据https://github.com/naver/pinpoint/releases/download/1.8.1/pinpoint-collector-1.8.1.war
pinpoint-web1.8.1数据WEB网页展示https://github.com/naver/pinpoint/releases/download/1.8.1/pinpoint-web-1.8.1.war
pinpoint-agent1.8.1应用关联探针https://github.com/naver/pinpoint/releases/download/1.8.1/pinpoint-agent-1.8.1.tar.gz
Oracle JDK1.8JAVA运行环境https://www.oracle.com/technetwork/java/archive-139210.html
apache-tomcat8.5.37web容器http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.37/bin/apache-tomcat-8.5.37.tar.gz
apache-maven3.3.9编译环境http://apache.mirrors.lucidnetworks.net/maven/maven-3/

架构

pinpoint

支持的模块

  • JDK 6+
  • Tomcat 6/7/8/9, Jetty 8/9, JBoss EAP 6/7, Resin 4, Websphere 6/7/8, Vertx 3.3/3.4/3.5, Weblogic 10/11g/12c, Undertow
  • Spring, Spring Boot (Embedded Tomcat, Jetty), Spring asynchronous communication
  • Apache HTTP Client 3.x/4.x, JDK HttpConnector, GoogleHttpClient, OkHttpClient, NingAsyncHttpClient, Akka-http, Apache CXF
  • Thrift Client, Thrift Service, DUBBO PROVIDER, DUBBO CONSUMER, GRPC
  • ActiveMQ, RabbitMQ, Kafka
  • MySQL, Oracle, MSSQL(jtds), CUBRID, POSTGRESQL, MARIA
  • Arcus, Memcached, Redis(Jedis, Lettuce), CASSANDRA, MongoDB, Hbase
  • iBATIS, MyBatis
  • DBCP, DBCP2, HIKARICP, DRUID
  • gson, Jackson, Json Lib, Fastjson
  • log4j, Logback

组件兼容性

pinpoint

准备工作

查看主机名

cat /etc/hostname

1
pinpoint_server

添加主机名解析

cat /etc/hosts

1
2
3
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 pinpoint_server

准备所需的软件包

1
2
3
4
5
6
7
8
9
10
11
[root@pinpoint_server ~]# cd /usr/local/src/pinpoint
[root@pinpoint_server pinpoint]# ll
total 499488
-rw-r--r-- 1 root root 9584807 Jan 9 08:52 apache-tomcat-8.5.32.tar.gz
-rw-r--r-- 1 root root 105514702 Jan 9 08:52 hbase-1.2.9-bin.tar.gz
-rw-r--r-- 1 root root 16984 Jan 9 08:52 hbase-create.hbase
-rw-r--r-- 1 root root 183212596 Jan 9 09:03 jdk-8u112-linux-x64.tar.gz
-rw-r--r-- 1 root root 16507792 Jan 9 08:52 pinpoint-agent-1.8.1.tar.gz
-rw-r--r-- 1 root root 62644974 Jan 9 08:52 pinpoint-collector-1.8.1.war
-rw-r--r-- 1 root root 97301169 Jan 9 08:52 pinpoint-web-1.8.1.war
-rw-r--r-- 1 root root 36667596 Jan 9 08:52 zookeeper-3.4.12.tar.gz

安装JDK

tar xf jdk-8u112-linux-x64.tar.gz -C /usr/local/
vim /etc/profile

1
2
3
4
5
6
export HISTSIZE=10000
export HISTTIMEFORMAT="%F %T "
export JAVA_HOME=/usr/local/jdk1.8.0_112/
export JAVA_8_HOME=/usr/local/jdk1.8.0_112/
export CLASSPATH=.:$JAVA_HOME/lib/:$JAVA_HOME/jre/lib/
export PATH=$JAVA_HOME/bin:$PATH

source /etc/profile

安装hbase

解压软件包

tar xf hbase-1.2.9-bin.tar.gz -C /usr/local/
cd /usr/local/hbase-1.2.9/conf/

修改配置文件

vim hbase-env.sh

1
2
#在27行左右配置JAVA_HOME
export JAVA_HOME=/usr/local/jdk1.8.0_112/

vim hbase-site.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<configuration>
<property>
<name>hbase.rootdir</name>
<value>file:///data/pinpoint/hbase</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/data/pinpoint/zookeeper</value>
</property>
<property>
<name>hbase.master.port</name>
<value>60000</value>
</property>
<property>
<name>hbase.regionserver.port</name>
<value>60020</value>
</property>
</configuration>

新建数据目录

mkdir -p /data/pinpoint/hbase
mkdir -p /data/pinpoint/zookeeper

启动hbase服务

cd /usr/local/hbase-1.2.9/bin
./start-hbase.sh
查看启动日志
tailf /usr/local/hbase-1.2.9/bin/../logs/hbase-root-master-pinpoint_server.log
也可以通过web控制台 http://192.168.6.140:16010/ 来访问hbase
pinpoint

导入hbase数据

下载这个hbase数据 https://github.com/naver/pinpoint/tree/master/hbase/scripts/hbase-create.hbase
$HBASE_HOME/bin/hbase shell $PATH_TO_SCRIPTS/hbase-create.hbase
/usr/local/hbase-1.2.9/bin/hbase shell /usr/local/src/pinpoint/hbase-create.hbase

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
2019-01-09 09:20:19,016 WARN  [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
0 row(s) in 1.5720 seconds

0 row(s) in 2.2760 seconds

0 row(s) in 4.3110 seconds

0 row(s) in 1.2430 seconds

0 row(s) in 1.2840 seconds

0 row(s) in 1.2550 seconds

0 row(s) in 1.2400 seconds

0 row(s) in 1.2540 seconds

0 row(s) in 2.2630 seconds

0 row(s) in 4.2830 seconds

0 row(s) in 18.4010 seconds

0 row(s) in 2.2570 seconds

0 row(s) in 2.2760 seconds

0 row(s) in 2.2510 seconds

0 row(s) in 2.2520 seconds

0 row(s) in 1.2370 seconds

TABLE
AgentEvent
AgentInfo
AgentLifeCycle
AgentStat
AgentStatV2
ApiMetaData
ApplicationIndex
ApplicationMapStatisticsCallee_Ver2
ApplicationMapStatisticsCaller_Ver2
ApplicationMapStatisticsSelf_Ver2
ApplicationTraceIndex
HostApplicationMap_Ver2
SqlMetaData_Ver2
StringMetaData
TraceV2
Traces
16 row(s) in 0.0400 seconds

./hbase shell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2019-01-09 10:55:54,792 WARN  [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.2.9, rfd0d55b1e5ef54eb9bf60cce1f0a8e4c1da073ef, Sat Nov 17 21:43:34 CST 2018

hbase(main):001:0> status 'detailed'
version 1.2.9
0 regionsInTransition
active master: localhost:44182 1546996425069
0 backup masters
master coprocessors: []
1 live servers
localhost:33288 1546996426037
requestsPerSecond=0.0, numberOfOnlineRegions=498, usedHeapMB=456, maxHeapMB=931, numberOfStores=626, numberOfStorefiles=3, storefileUncompressedSizeMB=0, storefileSizeMB=0, memstoreSizeMB=0, storefileIndexSizeMB=0, readRequestsCount=16623, writeRequestsCount=8095, rootIndexSizeKB=6, totalStaticIndexSizeKB=4, totalStaticBloomSizeKB=0, totalCompactingKVs=0, currentCompactedKVs=0, compactionProgressPct=NaN, coprocessors=[MultiRowMutationEndpoint]
……

当然也可以通过web控制台查看数据初始化是否成功!

安装pinpoint-collector

部署过程很简单,起一个web容器(tomcat),把下载的war包扔进去就可以了

解压tomcat

tar xf apache-tomcat-8.5.32.tar.gz -C /usr/local/
cd /usr/local/
mv apache-tomcat-8.5.32/ tomcat_pinpoint-collector
cd tomcat_pinpoint-collector/

删除默认的应用

rm -fr webapps/*

部署 pinpoint-collector-1.8.1.war

拷贝pinpoint-collector-1.8.1.war到webapps目录下,重命名为ROOT.war,改名只是为了访问的时候不用加上下文对象名称,就是懒~~~
cp /usr/local/src/pinpoint/pinpoint-collector-1.8.1.war webapps/ROOT.war

启动tomcat服务

bin/startup.sh

安装pinpoint-web

解压tomcat

tar xf apache-tomcat-8.5.32.tar.gz -C /usr/local/
cd /usr/local/
mv apache-tomcat-8.5.32 tomcat_pinpoint-web

修改tomcat端口

由于已经有一个tomcat把默认的端口都占用了,我们这里修改一下tomcat使用到的端口
cd tomcat_pinpoint-web/conf
sed -i 's/port="8005"/port="18005"/g' server.xml
sed -i 's/port="8080"/port="18080"/g' server.xml
sed -i 's/port="8443"/port="18443"/g' server.xml
sed -i 's/port="8009"/port="18009"/g' server.xml
sed -i 's/redirectPort="8443"/redirectPort="18443"/g' server.xml
sed -i "s/localhost/192.168.6.140/g" server.xml

删除默认的应用

rm -fr ../webapps/*
cp /usr/local/src/pinpoint/pinpoint-web-1.8.1.war /usr/local/tomcat_pinpoint-web/webapps/ROOT.war
bin/startup.sh
访问web控制台http://192.168.6.140:18080
pinpoint

安装pinpoint-agent

部署探针也很简单,就是在tomcat的启动配置文件中添加以下三行内容即可

添加linux探针

mkdir -p /usr/local/pinpoint-agent
tar xf pinpoint-agent-1.8.1.tar.gz -C /usr/local/pinpoint-agent
/usr/local/pinpoint-agent
vim pinpoint.config

1
profiler.collector.ip=192.168.6.140

检测一下agent和服务端的通信情况

如果有问题,大部分情况下是pinpoint和hbase之间的连通性问题
sh script/networktest.sh
pinpoint

tar xf apache-tomcat-8.5.32.tar.gz -C /usr/local/
mv apache-tomcat-8.5.32/ tomcat_test
cd tomcat_test/conf/
和之前一样,因为本机的tomcat端口被占用,我们修改一下相关端口
sed -i 's/port="8005"/port="28005"/g' server.xml
sed -i 's/port="8080"/port="28080"/g' server.xml
sed -i 's/port="8443"/port="28443"/g' server.xml
sed -i 's/port="8009"/port="28009"/g' server.xml
sed -i 's/redirectPort="8443"/redirectPort="28443"/g' server.xml
sed -i "s/localhost/192.168.6.140/g" server.xml

vim catalina.sh

1
2
3
4
5
6
7
8
# for pinpoint agent
AGENT_PATH=/usr/local/pinpoint-agent
AGENT_VERSION=1.8.1
AGENT_ID="agent001"
APPLICATION_NAME="test_140_28080"
CATALINA_OPTS="$CATALINA_OPTS -javaagent:$AGENT_PATH/pinpoint-bootstrap-$AGENT_VERSION.jar"
CATALINA_OPTS="$CATALINA_OPTS -Dpinpoint.agentId=$AGENT_ID"
CATALINA_OPTS="$CATALINA_OPTS -Dpinpoint.applicationName=$APPLICATION_NAME"

pinpoint
bin/startup.sh
pinpoint

添加windows探针

由于我这边目前大部分项目都是在windows跑的,我们添加两个windows探针看一下真实的效果
解压pinpoint-agent-1.8.1.tar.gz到D:/pinpoint-agent/
修改配置文件pinpoint.config

1
profiler.collector.ip=192.168.6.140

修改D:\apache-tomcat-8082\bin\catalina.bat文件,添加到最前边即可

1
2
3
set CATALINA_OPTS=%CATALINA_OPTS% -javaagent:D:/pinpoint-agent/pinpoint-bootstrap-1.8.1.jar
set CATALINA_OPTS=%CATALINA_OPTS% -Dpinpoint.agentId=agent002
set CATALINA_OPTS=%CATALINA_OPTS% -Dpinpoint.applicationName=172_8082

pinpoint
修改D:\apache-tomcat-ou\bin\catalina.bat文件,添加到最前边即可

1
2
3
set CATALINA_OPTS=%CATALINA_OPTS% -javaagent:D:/pinpoint-agent/pinpoint-bootstrap-1.8.1.jar
set CATALINA_OPTS=%CATALINA_OPTS% -Dpinpoint.agentId=agent003
set CATALINA_OPTS=%CATALINA_OPTS% -Dpinpoint.applicationName=172_8081

启动tomcat后,我们打开pinpoint-web控制台
pinpoint

微服务springboot添加pinpoint探针

1
/usr/local/jdk1.8.0_202/bin/java -jar -javaagent:/usr/local/ths/pinpoint-agent/pinpoint-bootstrap-1.8.4.jar  -Dpinpoint.agentId=monitor-china-server -Dpinpoint.applicationName=chinaserver /usr/local/ths/monitor-china-server.jar 

web控制台简单应用

通过这个图,我们就能看到项目应用直接的依赖关系
pinpoint
pinpoint
pinpoint

删除应用

如果有调试时产生已经废弃的应用,我们可以使用管理员api调用删除,可以使用应用名称( /admin/removeApplicationName.pinpoint?applicationName=$APPLICATION_NAME&password=$PASSWORD)或者客户端id(/admin/removeAgentId.pinpoint?applicationName=$APPLICATION_NAME&agentId=$AGENT_ID&password=$PASSWORD)两种方法删除;$PASSWORD为pinpoint-web.properties文件中的admin.password配置项值。

1
2
#示例
http://172.16.10.24:8080/admin/removeApplicationName.pinpoint?applicationName=chinaserver.jar&password=admin

参考链接;
https://www.infoq.cn/article/apm-Pinpoint-practice
https://www.cnblogs.com/yyhh/p/6106472.html
https://github.com/naver/pinpoint/releases
https://blog.csdn.net/wh211212/article/details/80437696