码迷,mamicode.com
首页 > 其他好文 > 详细

pinpoint 1.8.4告警

时间:2020-01-20 14:47:26      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:point   tcl   net   dem   ddr   author   element   ram   rop   

官方文档

https://naver.github.io/pinpoint/alarm.html

 修改  batch.properties文件,batch.enable设置为true.ip能连接的ip

#batch enable config
batch.enable=true

#batch server ip to execute batch
batch.server.ip=127.0.0.127
/*
 * Copyright 2018 NAVER Corp.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.navercorp.pinpoint.web.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;
import java.util.Enumeration;

/**
 * @author minwoo.jung
 */
public class BatchUtils {

    private final static Logger logger = LoggerFactory.getLogger(BatchUtils.class);
    public static boolean decisionBatchServer(String ip) {
        Enumeration<NetworkInterface> interfaces;

        try {
            interfaces = NetworkInterface.getNetworkInterfaces();
        } catch (SocketException e) {
            logger.error("not found network interface", e);
            return false;
        }

        if (interfaces == null) {
            return false;
        }

        while (interfaces.hasMoreElements()) {
            NetworkInterface network = interfaces.nextElement();
            Enumeration<InetAddress> inets = network.getInetAddresses();

            while (inets.hasMoreElements()) {
                InetAddress next = inets.nextElement();

                if (next instanceof Inet4Address) {
                    if (next.getHostAddress().equals(ip)) {
                        return true;
                    }
                }
            }
        }

        return false;
    }
}

BatchUtils类有对IP进行校验。

com.navercorp.pinpoint.web.config.ConfigProperties读取配置文件

com.navercorp.pinpoint.web.alarm.AlarmWriter 默认配置的EmptyMessageSender,需要自定义个发送对象需要继承AlarmMessageSender,修改AlarmWriter为自己定义对象

@Autowired(required = false)
private AlarmMessageSender alarmMessageSender = new AlarmMessageSenderImple();

  

新建AlarmMessageSenderImple

package com.navercorp.pinpoint.web.alarm;

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 java.util.List;

public class AlarmMessageSenderImple implements AlarmMessageSender {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserGroupService userGroupService;

    @Override
    public void sendSms(AlarmChecker checker, int sequenceCount) {

        List<String> receivers = userGroupService.selectPhoneNumberOfMember(checker.getuserGroupId());

        if (receivers.size() == 0) {
            return;
        }

        List<String> sms = checker.getSmsMessage();

        for (String message : sms) {
            logger.info("send SMS : {}", message);
            System.out.println("send SMS : {}" + message);
        }
    }

    @Override
    public void sendEmail(AlarmChecker checker, int sequenceCount) {
        List<String> receivers = userGroupService.selectPhoneNumberOfMember(checker.getuserGroupId());

        if (receivers.size() == 0) {
            return;
        }
        for (String receiver : receivers) {
            System.out.println("receiver:"+receiver);
        }
        String mail = checker.getEmailMessage();
        logger.info("mail : {}", mail);
    }
}

 

 

 

 

batch.server.ip

pinpoint 1.8.4告警

标签:point   tcl   net   dem   ddr   author   element   ram   rop   

原文地址:https://www.cnblogs.com/zhanchaohan/p/12217684.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!