pinpoint2.5.0环境搭建监控预警钉钉推送

1 篇文章 0 订阅
1 篇文章 0 订阅

1. 环境准备

  1. jdk :jdk8,JDk11
  2. hbase: habse-1.7.2 需与hbase-client版本一致,pinpoint-2.5.0使用的hbase-client版本为1.7.2
  3. hbase初始化脚本:hbase-create.hbase
  4. pinpoint-collect(监控采集服务-jdk11):pinpoint-collector-boot-2.5.0.jar
  5. pinpoint-web(监控管理服务-jdk11): pinpoint-web-boot-2.5.0.jar
  6. pinpoint-agent(监控采集代理-jdk8):pinpoint-agent-2.5.0.tar.gz
  7. pinpoint-batch(监控Aram管理服务-jdk11):pinpoint-batch-2.5.0.jar
  8. slack-receiver(监控预警信息推送服务-jdk8):webhook推送服务
  9. mysql数据库:aram功能需要

2.部署步骤

1.先安装jdk

hbase使用jdk8即可,但pinpoint-collector-2.5.0及pinpoint-web-2.5.0需要jdk11才能运行

2.安装hbase-1.7.2

安装hbase步骤

#解压安装包
tar -zxvf hbase-1.7.2-bin.tar.gz
#进入配置目录
cd /data/hbase/hbase-1.7.2/conf
修改hbase-site.xml 相关配置
#进入命令目录
cd /hbase-1.7.2/bin
#启动hbase
./start-hbase.sh
#初始化hbase
./hbase shell /x/x/hbase-create.hbase

hbase配置文件

<configuration>
    <property>
      <name>hbase.rootdir</name>
      <value>file:///data/hbase/data</value>
    </property>
  <property>
    <name>hbase.cluster.distributed</name>
    <value>false</value>
  </property>
  <property>
    <name>hbase.tmp.dir</name>
    <value>./tmp</value>
  </property>
  <property>
    <name>hbase.unsafe.stream.capability.enforce</name>
    <value>false</value>
  </property>
</configuration>

3.部署pinpoint-collector

  • 环境依赖:JDK11

部署文件目录
image.png
准备配置文件:/config/collector.properties

spring.profiles.active=release
pinpoint.zookeeper.address=172.16.XX.XX
collector.receiver.grpc.agent.port=9999
collector.receiver.stat.udp.receiveBufferSize=4194304

准备启动脚本:start_collector.sh

#!/bin/bash
appName=$2

param="-Dspring.config.additional-location=./config/collector.properties"
jdkPath=/usr/lib/java-11/jdk-11/bin
# JVM="-XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -Xms512m -Xmx1G"
JVM=""
logPath="./logs/app.log"

if [ -z $appName ];then
    appName=`ls -t |grep .jar$ |head -n1`
fi

function start()
{
        count=`ps -ef |grep java|grep $appName|wc -l`
        if [ $count != 0 ];then
                echo "Maybe $appName is running, please check it..."
        else
                echo "The $appName is starting..."
                nohup $jdkPath/java -jar $param $JVM ./$appName > $logPath 2>&1 &
        fi
}
 
 
function stop()
{
        appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`
        if [ -z $appId ];then
            echo "Maybe $appName not running, please check it..."
        else
        echo "The $appName is stopping..."
        kill $appId
        fi
}

function restart()
{
    # get release version
    releaseApp=`ls -t |grep .jar$ |head -n1`
     
    # get last version
    lastVersionApp=`ls -t |grep .jar$ |head -n2 |tail -n1`
 
 
    appName=$lastVersionApp
    stop
    for i in {5..1}
    do
        echo -n "$i "
        sleep 1
    done
    echo 0
     
    # backup
     
    appName=$releaseApp
    start
}

function status()
{
    appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`
        if [ -z $appId ]
        then
            echo -e "\033[31m Not running \033[0m"
        else
            echo -e "\033[32m Running [$appId] \033[0m"
        fi
}
 
 
 
 
function usage()
{
    echo "Usage: $0 {start|stop|restart|status|stop -f}"
    echo "Example: $0 start"
    exit 1
}
case $1 in
        start)
        start;;
 
 
        stop)
        stop;;
 
 
        restart)
        restart;;
 
 
        status)
        status;;
 
 
        *)
        usage;;
esac


启动服务

./start_collector.sh start
#停止服务
./start_collector.sh stop

4.部署pinpoint-web

部署文件目录
image.png
准备配置文件:config/web.properties

spring.profiles.active=release
pinpoint.zookeeper.address=172.16.xx.xx
cluster.zookeeper.sessiontimeout=10000

准备配置文件:config/jdbc.properties

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/pinpoint?characterEncoding=UTF-8
jdbc.username=root
jdbc.password=123456

准备服务启动脚本:start_web.sh

#!/bin/bash
appName=$2

param="-Dspring.config.additional-location=./config/web.properties,./config/jdbc.properties"
jdkPath=/usr/lib/java-11/jdk-11/bin
# JVM="-XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -Xms512m -Xmx1G"
JVM=""
logPath="./logs/app.log"

if [ -z $appName ];then
    appName=`ls -t |grep .jar$ |head -n1`
fi

function start()
{
        count=`ps -ef |grep java|grep $appName|wc -l`
        if [ $count != 0 ];then
                echo "Maybe $appName is running, please check it..."
        else
                echo "The $appName is starting..."
                nohup $jdkPath/java -jar $param $JVM ./$appName > $logPath 2>&1 &
        fi
}
 
 
function stop()
{
        appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`
        if [ -z $appId ];then
            echo "Maybe $appName not running, please check it..."
        else
        echo "The $appName is stopping..."
        kill $appId
        fi
}

function restart()
{
    # get release version
    releaseApp=`ls -t |grep .jar$ |head -n1`
     
    # get last version
    lastVersionApp=`ls -t |grep .jar$ |head -n2 |tail -n1`
 
 
    appName=$lastVersionApp
    stop
    for i in {5..1}
    do
        echo -n "$i "
        sleep 1
    done
    echo 0
     
    # backup
     
    appName=$releaseApp
    start
}

function status()
{
    appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`
        if [ -z $appId ]
        then
            echo -e "\033[31m Not running \033[0m"
        else
            echo -e "\033[32m Running [$appId] \033[0m"
        fi
}
 
 
 
 
function usage()
{
    echo "Usage: $0 {start|stop|restart|status|stop -f}"
    echo "Example: $0 start"
    exit 1
}
case $1 in
        start)
        start;;
 
 
        stop)
        stop;;
 
 
        restart)
        restart;;
 
 
        status)
        status;;
 
 
        *)
        usage;;
esac


启动服务

./start_web.sh start
#停止服务
./start_web.sh stop

5.部署pinpoint-agent

  • 环境依赖:jdk8即可
  1. 将pinpoint-agent-2.5.0.tar.gz 解压至目标服务器
  2. 修改配置:pinpoint-agent-2.5.0/pinpoint-root.config
profiler.transport.module=GRPC
###########################################################
# gRPC Configuration                                      #
###########################################################
profiler.transport.grpc.collector.ip=172.16.xx.xx

3.tomcat配置agent
编辑tomcat/bin/catalina.sh文件(linux)

#配置agent路径
CATALINA_OPTS="$CATALINA_OPTS -javaagent:/temp/app/pinpoint-new/pinpoint-agent-2.5.0/pinpoint-bootstrap-2.5.0.jar"
#配置服务节点名称(注意同一服务底下不要重复)
CATALINA_OPTS="$CATALINA_OPTS -Dpinpoint.agentId=demo-1"
#配置服务名称
CATALINA_OPTS="$CATALINA_OPTS -Dpinpoint.applicationName=demo-web"
#配置采样频率方式,PERCENT-百分比,COUNTING-计数
CATALINA_OPTS="$CATALINA_OPTS -Dprofiler.sampling.type=PERCENT"
#配置采样频率-百分比方式,1-1%,100-100%,区间0.01-100
CATALINA_OPTS="$CATALINA_OPTS -Dprofiler.sampling.percent.sampling-rate=100"
#配置采样频率-计数方式,1-100%,100-1%
#CATALINA_OPTS="$CATALINA_OPTS -Dprofiler.sampling.counting.sampling-rate=1"

编辑tomcat/bin/catalina.bat文件(windows)

set CATALINA_OPTS=%CATALINA_OPTS% -javaagent:E:/ewell/pinpoint-agent-2.5.0/pinpoint-bootstrap-2.5.0.jar
set CATALINA_OPTS=%CATALINA_OPTS% -Dpinpoint.agentId=demoo-2
set CATALINA_OPTS=%CATALINA_OPTS% -Dpinpoint.applicationName=demo-web
set CATALINA_OPTS=%CATALINA_OPTS% -Dprofiler.sampling.type=PERCENT
set CATALINA_OPTS=%CATALINA_OPTS% -Dprofiler.sampling.percent.sampling-rate=100

正常启动tomcat即可

  1. springboot项目配置agent
#!/bin/bash
appName=$2

param="-Dspring.config.additional-location=./config/application.properties -javaagent:/app/pinpoint-agent-2.5.0/pinpoint-bootstrap-2.5.0.jar -Dpinpoint.agentId=demo-1 -Dpinpoint.applicationName=demo-web"
# JVM="-XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -Xms512m -Xmx1G"
JVM="-XX:+UseParallelGC -XX:+HeapDumpOnOutOfMemoryError -Xms2048m -Xmx2048m"
logPath="./logs/app.log"

if [ -z $appName ];then
    appName=`ls -t |grep .jar$ |head -n1`
fi

function start()
{
        count=`ps -ef |grep java|grep $appName|wc -l`
        if [ $count != 0 ];then
                echo "Maybe $appName is running, please check it..."
        else
                echo "The $appName is starting..."
                nohup java -jar $param $JVM ./$appName > $logPath 2>&1 &
        fi
}
 
 
function stop()
{
        appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`
        if [ -z $appId ];then
            echo "Maybe $appName not running, please check it..."
        else
        echo "The $appName is stopping..."
        kill $appId
        fi
}

function restart()
{
    # get release version
    releaseApp=`ls -t |grep .jar$ |head -n1`
     
    # get last version
    lastVersionApp=`ls -t |grep .jar$ |head -n2 |tail -n1`
 
 
    appName=$lastVersionApp
    stop
    for i in {5..1}
    do
        echo -n "$i "
        sleep 1
    done
    echo 0
     
    # backup
     
    appName=$releaseApp
    start
}

function status()
{
    appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`
        if [ -z $appId ]
        then
            echo -e "\033[31m Not running \033[0m"
        else
            echo -e "\033[32m Running [$appId] \033[0m"
        fi
}
 
 
 
 
function usage()
{
    echo "Usage: $0 {start|stop|restart|status|stop -f}"
    echo "Example: $0 start"
    exit 1
}
case $1 in
        start)
        start;;
 
 
        stop)
        stop;;
 
 
        restart)
        restart;;
 
 
        status)
        status;;
 
 
        *)
        usage;;
esac


6. 部署pinpoint-batch

  • 环境依赖:JDK11
  • 服务说明:监控Aram管理服务,若需要自动推送监控预警信息则需要部署该服务
  • 功能说明:该服务已内置邮件推送服务,以及标准webhook推送服务(具体webhook服务对接需自己拓展)

部署文件目录
image.png
准备配置文件:config/batch.properties

batch.server.env=release
pinpoint.zookeeper.address=172.16.xx.xx
#smtp config\
#pinpoint-web服务地址(推送消息时需要)
pinpoint.url=http://172.16.xx.xx:8080
#邮箱服务地址
alarm.mail.server.url=smtp.xx.xx.com
#邮箱端口
alarm.mail.server.port=465
#邮箱账户名
alarm.mail.server.username=xxx@xxx.xx
#邮箱账户密码
alarm.mail.server.password=xxxx
#邮箱地址
alarm.mail.sender.address=xxx@xxx.xx

alarm.mail.transport.protocol=smtp
alarm.mail.smtp.port=25
alarm.mail.smtp.auth=true
alarm.mail.smtp.starttls.enable=false
alarm.mail.smtp.starttls.required=false
#邮箱SSl认证开关
alarm.mail.smtp.ssl.enable=true
alarm.mail.debug=true

# webhook开关,需要开启
webhook.enable=true

#flink server list
batch.flink.server=
batch.flink.rest.port=8081

#cleanup inactive agents job
job.cleanup.inactive.agents=false

# "0 0 3 * * WED" = 3:00 AM on every Wednesday.
# "0 0 0 10 * *" = 0:00 AM on the 10th of every month.
# "0 0 16 * * MON-FRI" = 4:00 PM on every weekdays.
#  There is no default value.
job.cleanup.inactive.agents.cron=

# Default value is 30 (minimum value is 30)
#job.cleanup.inactive.agents.duration.days=

###########################################################
# BANNER                                                  #
###########################################################
# Pinpoint Banner Settings
# Pinpoint banner mode : OFF, CONSOLE, LOG
pinpoint.banner.mode=console
pinpoint.banner.configs=batch.server.env,\
                        pinpoint.url,\
                        alarm.mail.server.url,\
                        jdbc.url,\
                        meta.jdbc.url,\
                        batch.flink.server,\
                        job.cleanup.inactive.agents,\
                        job.cleanup.inactive.agents.cron,\
                        pinpoint.zookeeper.address,\
                        hbase.client.host,\
                        hbase.client.port,\
                        hbase.zookeeper.znode.parent,\
                        hbase.namespace

准备配置文件:config/jdbc.properties

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/pinpoint?characterEncoding=UTF-8
jdbc.username=root
jdbc.password=123456

准备启动脚本:start_batch.sh

#!/bin/bash
appName=$2

param="-Dspring.config.additional-location=./config/batch.properties,./config/jdbc.properties"
jdkPath=/usr/lib/java-11/jdk-11/bin
# JVM="-XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -Xms512m -Xmx1G"
JVM=""
logPath="./logs/app.log"

if [ -z $appName ];then
    appName=`ls -t |grep .jar$ |head -n1`
fi

function start()
{
        count=`ps -ef |grep java|grep $appName|wc -l`
        if [ $count != 0 ];then
                echo "Maybe $appName is running, please check it..."
        else
                echo "The $appName is starting..."
                nohup $jdkPath/java -jar $param $JVM ./$appName > $logPath 2>&1 &
        fi
}
 
 
function stop()
{
        appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`
        if [ -z $appId ];then
            echo "Maybe $appName not running, please check it..."
        else
        echo "The $appName is stopping..."
        kill $appId
        fi
}

function restart()
{
    # get release version
    releaseApp=`ls -t |grep .jar$ |head -n1`
     
    # get last version
    lastVersionApp=`ls -t |grep .jar$ |head -n2 |tail -n1`
 
 
    appName=$lastVersionApp
    stop
    for i in {5..1}
    do
        echo -n "$i "
        sleep 1
    done
    echo 0
     
    # backup
     
    appName=$releaseApp
    start
}

function status()
{
    appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`
        if [ -z $appId ]
        then
            echo -e "\033[31m Not running \033[0m"
        else
            echo -e "\033[32m Running [$appId] \033[0m"
        fi
}
 
 
 
 
function usage()
{
    echo "Usage: $0 {start|stop|restart|status|stop -f}"
    echo "Example: $0 start"
    exit 1
}
case $1 in
        start)
        start;;
 
 
        stop)
        stop;;
 
 
        restart)
        restart;;
 
 
        status)
        status;;
 
 
        *)
        usage;;
esac


启动服务

./start_batch.sh start
./start_batch.sh stop

7.监控预警自动推送钉钉消息

pinpoint 官方提供了标准的webhook推送demo项目(slack-receiver),可基于该项目拓展对接钉钉机器人、短信、企业微信等其他需要推送消息的渠道,下面以钉钉为例展开介绍。

7.1 接入钉钉机器人

详见钉钉自定义机器人接入文档
引入钉钉SDK:maven配置

        <!--钉钉SDK-->
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>alibaba-dingtalk-service-sdk</artifactId>
            <version>2.0.0</version>
        </dependency>

slack-receiver 项目拓展实现钉钉推送

package com.webhook.receiver.slack.sender;

import com.webhook.receiver.slack.vo.WebhookPayload;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.dingtalk.api.response.OapiRobotSendResponse;
import com.taobao.api.ApiException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;


@Component
public class DingTalkNotifier implements Notifier {

    private final Logger logger = LoggerFactory.getLogger(DingTalkNotifier.class.getName());
    private final String dingTalkWebhookUrl;
    private final String noticePicUrl;
    private static final String SCATTER_CHART_LINK_FORMAT = "%s/main/%s@%s/5m/%s";

    @Autowired
    public DingTalkNotifier(@Value("${webhook.ding.notify.url}") final String dingTalkWebhookUrl, @Value("${webhook.ding.pic.url}") final String noticePicUrl) {
        this.dingTalkWebhookUrl = dingTalkWebhookUrl;
        this.noticePicUrl = noticePicUrl;
    }

    @Override
    public boolean send(WebhookPayload webhookPayload) {
        DingTalkClient client = new DefaultDingTalkClient(this.dingTalkWebhookUrl);
        OapiRobotSendRequest request = new OapiRobotSendRequest();

        request.setMsgtype("link");
        OapiRobotSendRequest.Link link = new OapiRobotSendRequest.Link();

        link.setMessageUrl(String.format(SCATTER_CHART_LINK_FORMAT, webhookPayload.getPinpointUrl(), webhookPayload.getApplicationId(), webhookPayload.getServiceType(), getCurrentTime()));
        link.setPicUrl(this.noticePicUrl);
        link.setTitle(webhookPayload.getNotes());
        StringBuilder builder = new StringBuilder();
        builder.append("【钉钉关键字】").append(webhookPayload.getChecker().getName()).append(" value is ").append(webhookPayload.getChecker().getDetectedValueString()).append(webhookPayload.getUnit()).append(" during the past 5 mins.");
        link.setText(builder.toString());
        request.setLink(link);
        try {
            OapiRobotSendResponse response = client.execute(request);
            logger.info("Sent dingTalk message to {}", dingTalkWebhookUrl);
            return true;
        } catch (ApiException e) {
            logger.error(e.getMessage());
        }
        return false;
    }
}

7.2 pinpoint-web 配置webhook

在Configuration->Webhook中配置自己的webhook服务
image.png
选择应用,配置对应的webhook地址
image.png

7.3 pinpoint-web 配置预警推送规则

在Configuration->Alaram中配置自己的预警推送规则
image.png
预警类型Type选择webhook,再勾选目标webhook
image.png

7.4 钉钉推送效果

钉钉推送效果

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值