最新消息:

multitail 监控多个文件或命令

multitail admin 3414浏览 0评论

之前有同事希望在终端下开多个窗口查看服务状态,后来用xterm解决。
multitail可以很好的实现该功能,示例如下:
multitail --label "baidu.com: " -l 'ping baidu.com' --label "sina.com: " -l 'ping sina.com' --label "taobao.com: " -l "ping taobao.com" --label "sohu.com: " -l "ping sohu.com" --label "syslog: " /var/log/syslog -l "vmstat 1" -sw 100,100 -sn 3,3

-sw 用来设置有多少列,每列的大小
-sn 配合-sw/-s使用,设置每列的窗口数
-C 放在multitail后面,输出颜色

%E9%80%89%E5%8C%BA_007
进入后,按h帮助,大写O清屏,更多功能大家自己发掘把,比如:只显示差异

安装使用yum或者apt, apt-get install multitail
更多例子:

    Merge 2 logfiles in one window:

    multitail /var/log/apache/access.log -I /var/log/apache/error.log

    Show 3 logfiles in 2 columns:

    multitail -s 2 /var/log/apache/access.log /var/log/messages /var/log/mail.log

    Show 5 logfiles while merging 2 and put them in 2 columns with only one in the left column:

    multitail -s 2 -sn 1,3  /var/log/apache/access.log -I /var/log/apache/error.log /var/log/messages 
                            /var/log/mail.log /var/log/syslog

    Merge the output of 2 ping commands while removing "64 bytes received from" from only 1 of them:

    multitail -l "ping 192.168.0.1" -ke "64 bytes from" -L "ping 192.168.0.2"

    Show the output of a ping-command and if it displays a timeout, send a message to all users
    currently logged in

    multitail -ex timeout "echo timeout | wall" -l "ping 192.168.0.1"

    In one window show all new TCP connections and their state changes using netstat while in
    the other window displaying the merged access and error logfiles of apache

    multitail -R 2 -l "netstat -t" /var/log/apache/access.log -I /var/log/apache/error.log

    As the previosu example but also copy the output to the file netstat.log

    multitail -a netstat.log -R 2 -l "netstat -t tcp" /var/log/apache/access.log -I /var/log/apache/error.log

    Show 2 logfiles merged in one window but give each logfile a different color so that you
    can easily see what lines are for what logfile:

    multitail -ci green /var/log/apache/access.log -ci red -I /var/log/apache/error.log

    Show 3 rssfeeds merged in one window using rsstail

    multitail -cS rsstail -l "rsstail -n 1 -z -l -d -u http://setiathome.berkeley.edu/rss_main.php" 
        -cS rsstail -L "rsstail -n 1 -z -l -d -u http://www.biglumber.com/index.rss" -cS rsstail 
        -L "rsstail -n 1 -z -l -u http://kernel.org/kdist/rss.xml"

    Show a Squid (proxy server) logfile while converting timestamps to something readable

    multitail -cv squid /var/log/squid/access.log

    Display Q-Mail logging while converting the timestamp into human readable format

    multitail -cv qmailtimestr /var/log/qmail/qmail.smtpd.log

    Merge ALL apache logfiles (*access_log/*error_log) into one window:

    multitail -cS apache --mergeall /var/log/apache/*access_log --no-mergeall -cS apache_error 
        --mergeall /var/log/apache/*error_log --no-mergeall

    Monitor the logfile of an other system:
    For this you need to setup a couple of things. MultiTail runs on system A, the logfile on system B.
    In this example we're going to monitor the apache logfile. Add the following to /etc/services:

    apachelog       20000/tcp

    Add this to /etc/inetd.conf:

    apachelog stream tcp nowait root /usr/local/sbin/tail_apache_log /usr/local/sbin/tail_apache_log

    and create the file /usr/local/sbin/tail_apache_log with the following content:

    #!/bin/sh

    /usr/bin/tail -f /var/log/apache2/access.log

    make sure that you don't forget to make that script executable (chmod +x filename).
    Then on host A start MultiTail like this:

    multitail -cS apache -l "telnet B 20000"

    Please note that logfiles go in plaintext across the network. You may also need to adjust
    the files /etc/hosts.[allow|deny] on host B to only allow host A to connect.
    Monitoring Tomcat

    multitail -cS apache -cS log4j "${TOMCAT_HOME}/logs/catalina.out"

转载请注明:爱开源 » multitail 监控多个文件或命令

您必须 登录 才能发表评论!