zoukankan      html  css  js  c++  java
  • shell脚本监控

    一、进程服务检测自动拉取

    运用知识点

    . /etc/bashrc   加载用户的环境变量
    打点到falcon 里面
    执行的日志输出

    脚本内容

    #!/bin/bash
    . /etc/bashrc
    region=shdl
    host=`hostname`
    end_timestamp=`date +%s`
    status_num=`yarn application --list|grep AppPre|wc -l`
    status=`yarn application --list|grep Pre|awk '{print $6}'`
    stream_lock=`cat /home/eos/monitor/stream_lock.log`
    
    if [ $status_num = '1' ] ;then
        > /home/eos/monitor/stream_lock.log    
        if [ $status = 'RUNNING' ] ;then    
            echo -e "33[32mss_pre process is running33[0m"
            curl -X POST -d "[{"metric": "eniot_${region}_pre_status", "endpoint": "eniot_${region}_pre_status", "timestamp": $end_timestamp,"step": 60,"value": 1,"counterType": "GAUGE","tags": "region=$region,host=${host}"}]" http://127.0.0.1:1988/v1/push &> /dev/null
            
        else
            echo -e "33[32mss_pre process is error33[0m"
        curl -X POST -d "[{"metric": "eniot_${region}_pre_status", "endpoint": "eniot_${region}_pre_status", "timestamp": $end_timestamp,"step": 60,"value": 2,"counterType": "GAUGE","tags": "region=$region,host=${host}"}]" http://127.0.0.1:1988/v1/push &> /dev/null
        fi    
        
    else
        if [ $stream_lock = 0 ] ;then
            echo -e "33[32mss_pre process is error33[0m"
            curl -X POST -d "[{"metric": "eniot_${region}_pre_status", "endpoint": "eniot_${region}_pre_status", "timestamp": $end_timestamp,"step": 60,"value": 2,"counterType": "GAUGE","tags": "region=$region,host=${host}"}]" http://127.0.0.1:1988/v1/push &> /dev/null
        else
    
            echo -e "33[32mss_pre process not running33[0m"
            curl -X POST -d "[{"metric": "eniot_${region}_pre_status", "endpoint": "eniot_${region}_pre_status", "timestamp": $end_timestamp,"step": 60,"value": 0,"counterType": "GAUGE","tags": "region=$region,host=${host}"}]" http://127.0.0.1:1988/v1/push &> /dev/null
            cd /home/eos/energy-os/ss_pre ;sh bin/submit_yarn.sh
            echo 0 > /home/eos/monitor/stream_lock.log
        fi
    fi

    定时任务中写入

    [root@streaming-app0001 cron.d]# cat stream_pre 
    */2 * * * * eos /bin/sh /home/eos/monitor/watchdog_stream.sh >> /home/eos/monitor/watchdog_stream.log 2>&1

    二、针对一些特殊输出,如java 版本的输出

    java输出的问题
    
    java -version >> 1.log 不输出到文件
    java -version >> 1.log 2>&1    会输出到文件

     三、shell的dubug调试模式

    1)在指定shell运行版本时加上 '-x'

    如。#!/bin/bash   -x

    测试脚本如下

    demo git:(master) ✗ cat debug.sh
    #!/bin/bash -x
     
     
    echo "hi"
    date
    sleep 1
    echo "hi"
    date

    调试结果如下

    ➜  demo git:(master) ✗ ./debug.sh
    + echo hi
    hi
    + date
    2019年 1月 7日 星期一 13时24分18秒 CST
    + sleep 1
    + echo hi
    hi
    + date
  • 相关阅读:
    前端模块化,AMD,CMD 总结
    前端基本网络协议知识整合
    websocket心跳机制
    js 数组方法的作用,各方法是否改变原有的数组
    React函数组件和类组件的区别
    js 单线程、宏任务与微任务的执行顺序
    js为什么是单线程
    allure清空上一次运行的记录(--clean-alluredir)
    allure的Tag标记(allure.story、allure.feature、severity)
    allure集成缺陷管理系统和测试管理系统(allure.link、allure.issue、allure.testcase)
  • 原文地址:https://www.cnblogs.com/linu/p/12452529.html
Copyright © 2011-2022 走看看