環境
cross.tw 192.168.1.93
cross2.tw 192.168.1.93

1.) 下載 http://updates.interworx.info/iworx/legacy/sources/
2.) 安裝 mod_watch 給 Apache
a.) 在編譯時讓程式知道 apxs 在那裡
vi Makefile.dso

#
# The location of apxs utility.
#
APXS=/usr/sbin/apxs

b.) 開始編譯

make -f Makefile.dso install

c.) 設定 conf 檔,mod_watch.so 已在安裝後放於 httpd.conf 了,我們只要加入可以在網頁上要看到結果的參數設定
vi /etc/httpd/conf.d/mod_watch.conf

<IfModule mod_watch.c>
# Allows the URL used to query virtual host data:
#
#     http://www.snert.com/watch-info
#
<Location /watch-info>
SetHandler watch-info
</Location>

# Allows the URL used to query file owner and web
# server data:
#
#     http://www.snert.com/~achowe/watch-info
#     http://www.snert.com/~SERVER/watch-info
#
<LocationMatch “^/~.+/watch-info$”>
SetHandler watch-info
</LocationMatch>

# Intended for debugging and analysis of shared memory
# hash table and weenie files:
#
#     http://www.snert.com/watch-table
#
<Location /watch-table>
SetHandler watch-table
</Location>

<Location /watch-flush>
SetHandler watch-flush
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>

<Location /watch-list>
SetHandler watch-list
</Location>
</IfModule>

apachectl configtest

參數說明
watch-flush – 可用 script 來控制清空與另存舊資料吧!!

This handler allows a remote script to request that the shared hash table be flushed and saved to disk for the purpose of backing up the data, without having to restart Apache

watch-info   –

This handler is used to display a line of plain text containing the following space separated fields
ifName ifUptime ifInOctets ifOutOctets ifRequests ifDocuments ifActive ifOutRate

Quote:

Name             Type                      Description
ifInOctets       32-bit                    Counter bytes received from requests (except chunked input)
ifOutOctets     32-bit                    Counter bytes sent in response to requests
ifRequests      32-bit                    Counter number of requests (raw hits) received
ifDocuments    32-bit                    Counter number of documents sent
ifActive            16-bit                    Signed number of active (concurrent) connections
ifOutRate         Float                     approx. 5 minute average of bytes sent per second
periodOctets   32-bit Unsigned     bytes sent during the current 5 minute period
periodMarker   32-bit Unsigned     start time() of the current 5 minute period

瀏覽: http://cross.tw/watch-info

cross.tw            143244         14290           102946               37                    2                         1                     0.144           139180128      15861077
# 名稱               # 啟動時間      # 流入封包      # 流出封包          # 要求數量         # 讀取頁面量       # 同時間連線數
# ifName          # ifUptime      # ifInOctets   # ifOutOctets    # ifRequests    # ifDocuments   # ifActive          # ifOutRate

watch-list –

This handler is similar to watch-info, but presents a plain text list of all the entries that would appear in watch-table

瀏覽: http://cross.tw/watch-list

SERVER 143248 48667 209748 142 11 1 4.011 13 15861077
cross.tw 143248 3742 43916 13 1 0 0.000 13 15861077
192.168.1.93 143248 14290 102946 37 2 1 0.144 13 15861077
lo93 143248 0 0 0 0 0 0.000 13 15861077
cross2.tw 143248 30635 62886 92 8 0 0.000 13 15861077

watch-table –

This handler is intended for debugging and analysis of the shared memory hash table performance and weenie files

瀏覽: http://cross.tw/watch-table

問題:

Cannot load /usr/lib/httpd/modules/mod_watch.so into server: /usr/lib/httpd/modules/mod_watch.so: undefined symbol: apr_get_username

答案 ???
Quote: http://marc.info/?l=apr-dev&m=116888688719561&w=2

apr 1.x renamed apr_get_username to apr_uid_name_get.  So, this sounds
like your mod_watch module is expecting an APR 0.9.x interface while
you have APR 1.x available.  Hence, I’d recommend recompiling with
httpd 2.2+ with APR 1.2+ – or you’d need to use httpd 2.0.x and APR
0.9.x instead.

It seems that the author of mod_watch has yanked the code, so I can’t
find it easily to tell you how easy it’d be to make mod_watch work
with httpd 2.2+ and APR 1.2+.

結合 MRTG
mod_watch tarbll 裡面有個 apache2mrtg.pl 可以用來將 apache 裡的 virtual host 設定以 mrtg cfg 形式輸出
./apache2mrtg.pl /etc/httpd/conf/httpd.conf

Title[cross.tw:80]: cross.tw:80 Data Traffic
Target[cross.tw:80]: `/usr/local/sbin/mod_watch.pl http://cross.tw:80/watch-info`
MaxBytes[cross.tw:80]: 1250000
PageTop[cross.tw:80]: <h2><a href=”http://cross.tw:80/”>cross.tw:80</a> Data Traffic</h2>

Title[cross2.tw:80]: cross2.tw:80 Data Traffic
Target[cross2.tw:80]: `/usr/local/sbin/mod_watch.pl http://cross2.tw:80/watch-info`
MaxBytes[cross2.tw:80]: 1250000
PageTop[cross2.tw:80]: <h2><a href=”http://cross2.tw:80/”>cross2.tw:80</a> Data Traffic</h2>

預設會抓取流入(InOctets)與流出(OutOctets)值
如果要抓 Requests 與 Documents 的話,要手動修改 mrtg cfg 檔,黑字體是重點

Options[cross.tw]: growright, perhour
Title[cross.tw]: cross.tw Request &amp; Document Traffic
Target[cross.tw]: `/usr/local/sbin/mod_watch.pl -f ifRequests,ifDocuments http://cross.tw/watch-info`
MaxBytes[cross.tw]: 1250000
PageTop[cross.tw]: <h2>cross.tw Request &amp; Document Traffic</h2>
YLegend[cross.tw]: Hits per Hour
ShortLegend[cross.tw]: H/h
Legend1[cross.tw]: Requests (raw hits) received per Hour
Legend2[cross.tw]: Documents sent per Hour
Legend3[cross.tw]: Maximal 5 Minute Incoming Request Traffic
Legend4[cross.tw]: Maximal 5 Minute Outgoing Document Traffic
LegendI[cross.tw]: &nbsp;Hits:
LegendO[cross.tw]: &nbsp;Docs:
Related posts 相關文章
apache httpd 2.4.58 有些安全性更新
More...
使用 Grafana 與 Prometheus 監控主機
More...
Apache 有 path traversal 目錄遍歷的漏洞
More...
CentOS7 透過 systemd 自動讓服務 restart 重啟
More...

作者

留言

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。