pinpoint 学习笔记
本地编译打 release 包
- 配置 JDK 环境变量,不管本地安装的那个版本的 JDK,一定要配置 6、7、8 对应的环境变量,都赋值为你本机安装的 JDK 版本,我这里没写 Maven 的安装配置说明,请自行 Google
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
export JAVA_6_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
export JAVA_7_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
- 克隆指定分支或 tag 到本地,我这里克隆的 tag 版本是 1.6.2 注意「1.6.2 版本的 pinpoint 不支持 RestTemplate 和 mysql-connector-java 6.x 版本,我被这两点坑惨了」
git clone -b 1.6.2 https://github.com/naver/pinpoint.git
- 修改 pinpoint/collector/pom.xml 中 JDK 版本为你本机安装的版本
<properties>
<jdk.version>1.8</jdk.version>
<jdk.home>${env.JAVA_8_HOME}</jdk.home>
<sniffer.artifactid>java18</sniffer.artifactid>
...
...
...
</properties>
- 输入下面的命令测试能否打包成功
mvn install -Prelease -Dmaven.test.skip=true
开启报警功能
- 初始化数据库表 CreateTableStatement-mysql.sql 和 SpringBatchJobReositorySchema-mysql.sql
- 修改 pinpoint/web 模块的 jdbc.properties
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://mysqlhost:3306/pinpoint?characterEncoding=UTF-8
jdbc.username=admin
jdbc.password=admin
- 修改 pinpoint/web 模块的 batch.properties
#batch enable config
batch.enable=true
#batch server ip to execute batch
batch.server.ip=127.0.0.1
- 添加邮件配置文件 mail.properties 到 pinpoint/web 模块的 resources 目录中
mail.smtpserver=smtp.xxxx.com
mail.smtpserver.port=25
[email protected]
mail.password=your_pwd
- 为 pinpoint/web 模块的 pom.xml 添加依赖
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.0</version>
</dependency>
- 添加报警消息发送器 AlarmMessageSenderImpl.java 到 pinpoint/web 模块的包 com.navercorp.pinpoint.web.alarm 中
package com.navercorp.pinpoint.web.alarm;
import com.navercorp.pinpoint.common.util.PropertyUtils;
import com.navercorp.pinpoint.web.alarm.checker.AlarmChecker;
import com.navercorp.pinpoint.web.service.UserGroupService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
/**
* 作者:王浩 邮件:[email protected]
* 创建时间:2017/8/4 下午1:51
* 描述:报警消息发送器
*/
@Component
public class AlarmMessageSenderImpl implements AlarmMessageSender {
private static final Logger LOGGER = LoggerFactory.getLogger(AlarmMessageSenderImpl.class);
@Autowired
private UserGroupService userGroupService;
private JavaMailSenderImpl mailSender;
public AlarmMessageSenderImpl() {
try {
Properties properties = PropertyUtils.loadPropertyFromClassPath("mail.properties");
mailSender = new JavaMailSenderImpl();
mailSender.setHost(properties.getProperty("mail.smtpserver"));
mailSender.setPort(Integer.parseInt(properties.getProperty("mail.smtpserver.port")));
mailSender.setUsername(properties.getProperty("mail.from"));
mailSender.setPassword(properties.getProperty("mail.password"));
mailSender.setJavaMailProperties(getMailProperties());
} catch (IOException e) {
mailSender = null;
LOGGER.error("初始化邮件发送者失败", e);
e.printStackTrace();
}
}
private Properties getMailProperties() {
Properties properties = new Properties();
properties.setProperty("mail.transport.protocol", "smtp");
properties.setProperty("mail.smtp.auth", "true");
properties.setProperty("mail.smtp.starttls.enable", "true");
properties.setProperty("mail.smtp.starttls.required", "true");
properties.setProperty("mail.debug", "false");
return properties;
}
/**
* 发送邮件
*
* @param to 邮件接收者
* @param text 邮件内容
*/
private void sendEmail(String to, String text) {
try {
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(to);
message.setSubject("pinpoint 报警邮件");
message.setText(text);
mailSender.send(message);
} catch (Exception e) {
LOGGER.error("发送邮件失败", e);
}
}
@Override
public void sendEmail(AlarmChecker checker, int sequenceCount) {
LOGGER.error("发送邮件");
List<String> receivers = userGroupService.selectEmailOfMember(checker.getuserGroupId());
if (mailSender == null || receivers.size() == 0) {
return;
}
for (String emailId : receivers) {
sendEmail(emailId, checker.getEmailMessage());
}
}
@Override
public void sendSms(AlarmChecker checker, int sequenceCount) {
}
}
- 打 release 包
mvn install -Prelease -Dmaven.test.skip=true
- 后面要用到的是下面四个文件
- pinpoint/collector/target/pinpoint-collector-1.6.2.war
- pinpoint/web/target/pinpoint-web-1.6.2.war
- pinpoint/agent/target/pinpoint-agent-1.6.2.tar.gz
- hbase/scripts/hbase-create.hbase
更多配置信息请参考 官方文档
REAL TIME
修改 com.navercorp.pinpoint.web.config.WebSocketConfig

测试环境准备(如果你已经准备好测试环境可忽略该步骤)
Docker 环境准备
- 创建 pinpoint 容器
docker run -it -p 22:22 -p 81:80 --name pp bingoogolapple/bga-centos-java:v1
- 配置 hosts 文件
echo "172.17.0.4 mysqlhost" >> /etc/hosts
- 启动 sshd
service sshd start
- 以交互方式启动容器后,使进程在后台运行
先 ctrl + p
然后 ctrl + q
- 拷贝软件包
scp -r software root@localhost:~
- pinpoint-web 对应的 mysql 容器
docker run -d -p 3306:3306 --name pp_mysql -e MYSQL_ROOT_PASSWORD=admin -e MYSQL_USER=admin -e MYSQL_PASSWORD=admin -e MYSQL_DATABASE=pinpoint mysql:latest --character-set-server=utf8 --collation-server=utf8_general_ci --lower-case-table-names=1
Nginx 配置以便在容器外部访问
- 在你本机上配置 hosts
127.0.0.1 hbase.bga.cn
127.0.0.1 ppw.bga.cn
127.0.0.1 www.bga.cn
- ssh 登录到 Docker 容器 pp
ssh root@localhost
- vim /opt/nginx/conf/vhost/hbase.bga.cn.conf
upstream server_hbase {
server 127.0.0.1:16010;
}
server {
listen 80;
server_name hbase.bga.cn;
location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://server_hbase;
proxy_read_timeout 90;
}
}
- vim /opt/nginx/conf/vhost/ppw.bga.cn.conf
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream server_ppw {
server 127.0.0.1:28080;
}
server {
listen 80;
server_name ppw.bga.cn;
location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://server_ppw;
proxy_read_timeout 90;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
- vim /opt/nginx/conf/vhost/www.bga.cn.conf
upstream server_www {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name www.bga.cn;
location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://server_www;
proxy_read_timeout 90;
}
}
安装 Hbase
- 安装
tar -zxvf hbase-1.2.6-bin.tar.gz -C /opt
- 配置环境变量「vim /etc/profile.d/hbase.sh」「source /etc/profile.d/hbase.sh」
export HBASE_HOME=/opt/hbase-1.2.6
export PATH=$HBASE_HOME/bin:$PATH
- 修改 Hbase 的配置信息「vim /opt/hbase-1.2.6/conf/hbase-site.xml」
<configuration>
<property>
<name>hbase.rootdir</name>
<value>file:///data/hbase</value>
</property>
</configuration>
- 启动停止 HBase,如果通过「jps」命令看到有「HMaster」则表示启动成功
start-hbase.sh
- 初始化 Hbase 的 pinpoint 库
hbase shell hbase-create.hbase
- 进入 HBase
hbase shell
- 查看刚才初始化的表是否存在
status 'detailed'
- 启动 Nginx
nginx
- 通过 http://hbase.bga.cn:81/master-status 就可以访问了

安装 pinpoint-collector
- 添加 pinpoint-collector 对应的 Tomcat
cd /opt
cp -r apache-tomcat-8.5.14 tomcat-pp-collector
- 修改端口
cd /opt/tomcat-pp-collector/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/`ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | awk -F: '{print $2}'`/g" server.xml
- 部署 pinpoint-collector
rm -rf /opt/tomcat-pp-collector/webapps/*
unzip ~/software/pinpoint-collector-1.6.2.war -d /opt/tomcat-pp-collector/webapps/ROOT
- 启动 pinpoint-collector 对应 Tomcat
/opt/tomcat-pp-collector/bin/startup.sh
- 通过跟踪日志信息查看 pinpoint-collector 对应的 Tomcat 是否启动成功
tail -f /opt/tomcat-pp-collector/logs/catalina.out
安装 pinpoint-web
- 添加 pinpoint-web 对应的 Tomcat
cd /opt
cp -r apache-tomcat-8.5.14 tomcat-pp-web
- 修改端口
cd /opt/tomcat-pp-web/conf
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/`ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | awk -F: '{print $2}'`/g" server.xml
- 部署 pinpoint-web
rm -rf /opt/tomcat-pp-web/webapps/*
unzip ~/software/pinpoint-web-1.6.2.war -d /opt/tomcat-pp-web/webapps/ROOT
- 启动 pinpoint-web 对应 Tomcat
/opt/tomcat-pp-web/bin/startup.sh
- 通过跟踪日志信息查看 pinpoint-web 对应的 Tomcat 是否启动成功
tail -f /opt/tomcat-pp-web/logs/catalina.out
- 通过 http://ppw.bga.cn:81 就可以访问了

部署 pinpoint-agent 采集监控数据
- 安装 pinpoint-agent
cd /opt/tomcat-web
tar -zxvf ~/software/pinpoint-agent-1.6.2.tar.gz
mkdir /opt/pinpoint-agent-1.6.2
tar -zxvf ~/software/pinpoint-agent-1.6.2.tar.gz -C /opt/pinpoint-agent-1.6.2
- 添加 test 应用对应的 Tomcat
cd /opt
cp -r apache-tomcat-8.5.14 tomcat-web
- 部署 test 应用
rm -rf /opt/tomcat-web/webapps/*
unzip ~/software/backend-1.0.0.war -d /opt/tomcat-web/webapps/ROOT
- 配置 pinpoint-agent「vim /opt/tomcat-web/bin/catalina.sh」
CATALINA_OPTS="$CATALINA_OPTS -javaagent:/opt/pinpoint-agent-1.6.2/pinpoint-bootstrap-1.6.2.jar"
CATALINA_OPTS="$CATALINA_OPTS -Dpinpoint.agentId=pp_test8080"
CATALINA_OPTS="$CATALINA_OPTS -Dpinpoint.applicationName=test8080"
- 启动 test 应用对应 Tomcat 并通过日志信息查看是否启动成功
/opt/tomcat-web/bin/startup.sh
tail -f /opt/tomcat-web/logs/catalina.out
可以通过 http://www.bga.cn:81 访问
Docker 重启后重新初始化环境
docker start pp
docker start pp_mysql
docker attach pp
echo "172.17.0.4 mysqlhost" >> /etc/hosts
service sshd start
nginx
start-hbase.sh
/opt/tomcat-pp-collector/bin/startup.sh
/opt/tomcat-pp-web/bin/startup.sh
/opt/tomcat-web/bin/startup.sh
参考链接
- https://github.com/naver/pinpoint
- https://henryz.gitbooks.io/pinpoint-leaning
- https://skyao.gitbooks.io/learning-pinpoint/content
虽然pinpoint说支持springboot,但是实际情况却无法捕获数据。楼主遇到过吗
@wyfaq 你是无法抓取 http 请求的数据,还是无法抓取数据库操作的数据,还是抓取不到两台服务器之前相互调用的数据?
- agent 的配置文件里有配置采样率的属性 rate,默认值是 20,表示 5% 的采样率
- pinpoint 1.6.2 只支持 mysql-connector-java 6.x.x 以下版本,要 pinpoint 1.7.0 版开始才支持 mysql-connector-java 6.x.x
- pinpoint 1.6.2 没有支持 RestTemplete,看他们的 commit 记录也是要 pinpoint 1.7.0 版才支持
所有的都抓不到,包括http请求以及连接数据库的请求。我已经把采样率设置为100%了。
pinpoint.config配置如下:
profiler.collector.ip=192.168.22.139 profiler.collector.span.ip=${profiler.collector.ip} profiler.collector.span.port=9996 profiler.collector.stat.ip=${profiler.collector.ip} profiler.collector.stat.port=9995 profiler.collector.tcp.ip=${profiler.collector.ip} profiler.collector.tcp.port=9994 profiler.enable=true profiler.interceptorregistry.size=8192 profiler.jvm.collect.interval=1000 profiler.jvm.collect.detailed.metrics=true profiler.sampling.enable=true profiler.sampling.rate=1 profiler.io.buffering.enable=true profiler.io.buffering.buffersize=20 profiler.spandatasender.write.queue.size=5120 profiler.spandatasender.chunk.size=16384 profiler.spandatasender.socket.type=OIO profiler.statdatasender.write.queue.size=5120 profiler.statdatasender.chunk.size=16384 profiler.statdatasender.socket.type=OIO profiler.agentInfo.send.retry.interval=300000 profiler.tcpdatasender.command.accept.enable=true profiler.tcpdatasender.command.activethread.enable=true profiler.tcpdatasender.command.activethread.count.enable=true profiler.tcpdatasender.command.activethread.threaddump.enable=true profiler.tcpdatasender.command.activethread.threadlightdump.enable=true profiler.pinpoint.activethread=true profiler.pinpoint.datasource=true profiler.callstack.max.depth=64 profiler.interceptor.exception.propagate=false profiler.instrument.engine=ASM bytecode.dump.enable=false bytecode.dump.classlist= bytecode.dump.bytecode=false bytecode.dump.verify=false bytecode.dump.asm=false profiler.applicationservertype=SPRING_BOOT profiler.type.detect.order= profiler.plugin.disable= profiler.include= profiler.entrypoint= profiler.tomcat.enable=true profiler.tomcat.bootstrap.main=org.apache.catalina.startup.Bootstrap profiler.tomcat.conditional.transform=false profiler.tomcat.hidepinpointheader=true profiler.tomcat.excludeurl=/aa/test.html, /bb/exclude.html profiler.tomcat.tracerequestparam=true profiler.tomcat.realipheader=X-Forwarded-For profiler.jetty.enable=true profiler.jetty.bootstrap.main=org.eclipse.jetty.start.Main profiler.jetty.excludeurl= profiler.dubbo.enable=true profiler.dubbo.bootstrap.main=com.alibaba.dubbo.container.Main profiler.jboss.enable=true profiler.jboss.bootstrap.main=org.jboss.modules.Main profiler.jboss.conditional.transform=true profiler.jboss.hidepinpointheader=true profiler.jboss.excludeurl= profiler.jboss.tracerequestparam=true profiler.jboss.realipheader=X-Forwarded-For profiler.vertx.enable=false profiler.vertx.bootstrap.main=io.vertx.core.Starter profiler.vertx.handlers= profiler.vertx.http.server.enable=false profiler.vertx.http.server.tracerequestparam=true profiler.vertx.http.server.excludeurl= profiler.vertx.http.server.realipheader=X-Forwarded-For profiler.vertx.http.client.enable=false profiler.vertx.http.client.param=true profiler.vertx.http.client.cookie=true profiler.vertx.http.client.cookie.dumptype=ALWAYS profiler.vertx.http.client.cookie.sampling.rate=1 profiler.vertx.http.client.entity.statuscode=true profiler.springboot.enable=true profiler.springboot.bootstrap.main=org.springframework.boot.loader.JarLauncher, org.springframework.boot.loader.WarLauncher, org.springframework.boot.loader.PropertiesLauncher profiler.jdbc=true profiler.jdbc.sqlcachesize=1024 profiler.jdbc.tracesqlbindvalue=true profiler.jdbc.maxsqlbindvaluesize=1024 profiler.jdbc.mysql=true profiler.jdbc.mysql.setautocommit=true profiler.jdbc.mysql.commit=true profiler.jdbc.mysql.rollback=true profiler.jdbc.mariadb=true profiler.jdbc.mariadb.setautocommit=true profiler.jdbc.mariadb.commit=true profiler.jdbc.mariadb.rollback=true profiler.jdbc.jtds=true profiler.jdbc.jtds.setautocommit=true profiler.jdbc.jtds.commit=true profiler.jdbc.jtds.rollback=true profiler.jdbc.oracle=true profiler.jdbc.oracle.setautocommit=true profiler.jdbc.oracle.commit=true profiler.jdbc.oracle.rollback=true profiler.jdbc.cubrid=true profiler.jdbc.cubrid.setautocommit=true profiler.jdbc.cubrid.commit=true profiler.jdbc.cubrid.rollback=true profiler.jdbc.dbcp=true profiler.jdbc.dbcp.connectionclose=true profiler.jdbc.dbcp2=true profiler.jdbc.dbcp2.connectionclose=true profiler.jdbc.hikaricp=true profiler.jdbc.hikaricp.connectionclose=true profiler.cassandra=true profiler.jdbc.postgresql=true profiler.jdbc.postgresql.setautocommit=true profiler.jdbc.postgresql.commit=true profiler.jdbc.postgresql.rollback=true profiler.apache.httpclient3.param=true profiler.apache.httpclient3.cookie=true profiler.apache.httpclient3.cookie.dumptype=ALWAYS profiler.apache.httpclient3.cookie.sampling.rate=1 profiler.apache.httpclient3.entity=true profiler.apache.httpclient3.entity.dumptype=ALWAYS profiler.apache.httpclient3.entity.sampling.rate=1 profiler.apache.httpclient3.io=true profiler.apache.httpclient4.param=true profiler.apache.httpclient4.cookie=true profiler.apache.httpclient4.cookie.dumptype=ALWAYS profiler.apache.httpclient4.cookie.sampling.rate=1 profiler.apache.httpclient4.entity=true profiler.apache.httpclient4.entity.dumptype=ALWAYS profiler.apache.httpclient4.entity.sampling.rate=1 profiler.apache.httpclient4.entity.statuscode=true profiler.apache.httpclient4.io=true profiler.jdk.http.param=true profiler.ning.asynchttpclient=true profiler.ning.asynchttpclient.cookie=true profiler.ning.asynchttpclient.cookie.dumptype=ALWAYS profiler.ning.asynchttpclient.cookie.dumpsize=1024 profiler.ning.asynchttpclient.cookie.sampling.rate=1 profiler.ning.asynchttpclient.entity=true profiler.ning.asynchttpclient.entity.dumptype=ALWAYS profiler.ning.asynchttpclient.entity.dumpsize=1024 profiler.ning.asynchttpclient.entity.sampling.rate=1 profiler.ning.asynchttpclient.param=true profiler.ning.asynchttpclient.param.dumptype=ALWAYS profiler.ning.asynchttpclient.param.dumpsize=1024 profiler.ning.asynchttpclient.param.sampling.rate=1 profiler.arcus=true profiler.arcus.keytrace=true profiler.memcached=true profiler.memcached.keytrace=true profiler.thrift.client=true profiler.thrift.client.async=true profiler.thrift.processor=true profiler.thrift.processor.async=true profiler.thrift.service.args=true profiler.thrift.service.result=true profiler.orm.ibatis=true profiler.orm.mybatis=true profiler.spring.beans=true profiler.spring.beans.1.scope=component-scan profiler.spring.beans.1.base-packages= profiler.spring.beans.1.name.pattern= profiler.spring.beans.1.class.pattern= profiler.spring.beans.1.annotation=org.springframework.stereotype.Controller,org.springframework.stereotype.Service,org.springframework.stereotype.Repository profiler.spring.beans.mark.error=false profiler.log4j.logging.transactioninfo=false profiler.logback.logging.transactioninfo=false profiler.google.httpclient.async=true profiler.redis.pipeline profiler.redis=true profiler.redis.io=true profiler.okhttp.param=true profiler.okhttp.cookie=false profiler.okhttp.cookie.dumptype=EXCEPTION profiler.okhttp.cookie.sampling.rate=10 profiler.okhttp.async=true profiler.json.gson=false profiler.json.jackson=false profiler.json.jsonlib=false profiler.activemq.client.enable=true profiler.activemq.client.producer.enable=true profiler.activemq.client.consumer.enable=true profiler.activemq.client.destination.separator= profiler.activemq.client.destination.exclude= profiler.hystrix=true profiler.resin.enable=true profiler.resin.bootstrap.main= profiler.resin.tracerequestparam=true profiler.resin.excludeurl= profiler.resin.tracecookies=true profiler.resin.cookie.sampling.rate=10 profiler.resin.cookie.dumptype=ALWAYS
@wyfaq 你的问题解决了吗? 我也遇到这个问题了,trace信息采集不到,但是webUI可以找到对应的application
@oatiz 也许在pinpoint.config中配置profiler.springboot.bootstrap.main加上你的main class能解决问题
虽然pinpoint说支持springboot,但是实际情况却无法捕获数据。楼主遇到过吗
需要配置: profiler.rxjava=true profiler.hystrix=true profiler.resttemplate=true