文章目录

Eureka应用监控

根据Eureka监控应用状态 当应用不可用时报警 ,前提引入spring cloud 健康检查相关模块

健康检查

#!/usr/bin/env bash
#配置中心一直未注册 未被监控
SERVICES_LIST="youngblog-gateway youngblog-commons youngblog-sms youngblog-email youngblog-file youngblog-im youngblog-notify youngblog-enterprise youngblog-approval youngblog-reports youngblog-clockin youngblog-training youngblog-notice youngblog-storage youngblog-recruit youngblog-management youngblog-message youngblog-job tx-manager youngblog-rabbitmq youngblog-user youngblog-pay"
REPORT_USER="18983359239 15215196117"
EUREKA="http://register.youngblog.cc/eureka/apps/"
#健康檢查地址

for i in $SERVICES_LIST; do
    #statements
    CHECK_URL=`curl -s  http://register.youngblog.cc/eureka/apps/$i|grep healthCheckUrl|awk -F '>|<' '{print $3}'`
    # echo $CHECK_URL
    for url in $CHECK_URL; do
        #多個服務下的健康檢查
        echo "檢查地址$url"
        requst=`curl -I -s $url|grep HTTP/1.1|awk '{print $2}'`
        if [[ $requst == 200 ]]; then
            echo "$url is ok"
        else
            echo "$url is down"
             python /data/bin/sendsms.py $i
        fi
    done
done

短信发送
#!/usr/bin/env python
#-*- coding: utf-8 -*-
# import requests
# import re
# import json
import sys
from aliyunsdkdysmsapi.request.v20170525 import SendSmsRequest
from aliyunsdkdysmsapi.request.v20170525 import QuerySendDetailsRequest
from aliyunsdkcore.client import AcsClient
import uuid
from aliyunsdkcore.profile import region_provider
from aliyunsdkcore.http import method_type as MT
from aliyunsdkcore.http import format_type as FT
# import const
ACCESS_KEY_ID = "ccccccccccccccccccc"
ACCESS_KEY_SECRET = "xxxxxxxxxxxxxxxx"
#配置中心一直未注册 未被监控
SERVICES_LIST=["youngblog-gateway","youngblog-register","youngblog-common","youngblog-sms","youngblog-email","youngblog-file","youngblog-im","youngblog-notify","youngblog-enterprise","youngblog-approval","youngblog-reports","youngblog-clockin","youngblog-training","youngblog-notice","youngblog-storage","youngblog-recruit","youngblog-management","youngblog-message","youngblog-monitor","youngblog-txmanager","youngblog-rabbitmq","youngblog-user"]
REPORT_USER=["18983359239","15215196117"]
EUREKA="http://register.test.youngblog.cc/eureka/apps/"


try:
    reload(sys)
    sys.setdefaultencoding('utf8')
except NameError:
    pass
except Exception as err:
    raise err

# 注意:不要更改
REGION = "cn-hangzhou"
PRODUCT_NAME = "Dysmsapi"
DOMAIN = "dysmsapi.aliyuncs.com"

acs_client = AcsClient(ACCESS_KEY_ID, ACCESS_KEY_SECRET, REGION)
region_provider.add_endpoint(PRODUCT_NAME, REGION, DOMAIN)

def send_sms(business_id, phone_numbers, sign_name, template_code, template_param=None):
    smsRequest = SendSmsRequest.SendSmsRequest()
    # 申请的短信模板编码,必填
    smsRequest.set_TemplateCode(template_code)
    # 短信模板变量参数
    if template_param is not None:
        smsRequest.set_TemplateParam(template_param)
    # 设置业务请求流水号,必填。
    smsRequest.set_OutId(business_id)
    # 短信签名
    smsRequest.set_SignName(sign_name)
    # 数据提交方式
    # smsRequest.set_method(MT.POST)
    # 数据提交格式
    # smsRequest.set_accept_format(FT.JSON)
    # 短信发送的号码列表,必填。
    smsRequest.set_PhoneNumbers(phone_numbers)
    # 调用短信发送接口,返回json
    smsResponse = acs_client.do_action_with_exception(smsRequest)
    # TODO 业务处理
    return smsResponse

service = sys.argv[1]
# f = sys.argv[2]
__business_id = uuid.uuid1()
params = {"env":"test","service":service}
print send_sms(__business_id,"{your_phone}","{短信签名}","SMS_144943701",params)