通過shell和redis來實現叢集業務中日誌的即時收集分析

來源:互聯網
上載者:User

在統計項目中,最難實施的就是日誌資料的收集。日誌分布在全國各個機房,而且資料量比較大,像rsync+inotify這種方式顯然不能滿足快速日誌同步的要求。 當然大家也可以用fluentd和flume採集日誌資料,除了這個我們也可以自己寫一套簡單的。

我寫的這個日誌分析系統 流程是:

在用戶端收集資料,然後通過redis pub方式把資料發給服務端

2   伺服器端是redis的sub    他會把資料統一存放在一個檔案,或者當前就過濾出來

用戶端收集日誌的更新資料

#!/bin/bash               DATE=`date +%s`     LOGFILE=$1     if [ ! -f $1 ];then      echo "LOG file did not give or it's not a file"fi     sleep_time="2"          count_init=`wc -l ${LOGFILE}|awk '{print $1}'`     while truedoDATE_NEW=`date +%s`     #    DATE=$(date +%s)         count_new=`wc -l ${LOGFILE}|awk '{print $1}'`         add_count=$((${count_new} - ${count_init}))         count_init=${count_new}             if [ ! -n "${add_count}" ]             then                 add_count=0             fi          QPS=$((${add_count}/${sleep_time}))          info=`tail -n ${add_count} ${LOGFILE}`              echo $info          #    我們可以把info這個值傳出去          echo " Then QPS at `date -d "1970-01-01 UTC ${DATE_NEW} seconds" +"%Y-%m-%d %H:%M:%S"` is "${QPS}     #    echo " DATE_NEW: " $DATE_NEW " DATE_PLUS :" $DATE_PLUS     sleep $sleep_time     done

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.