使用MRTG觀察VPN(pptpd)上線人數

我的VPN伺服器是使用Poptop套件架設在Debian上,一旦有新的服務在手上,自然會好奇到底有多少人在使用,馬上浮現在腦海中的便是利用MRTG來做,實作起來也相當簡單,只需要編輯一個專屬的MRTG config檔以及自行撰寫一個shell script即可完成。

在開始前先來個真相一下:

Monthly VPN online user by MRTG

Monthly VPN online user by MRTG

首先編輯MRTG config檔案: /etc/mrtg.person.cfg

#option
WorkDir: /var/www/mrtg
Options[_]:growright

Target[vpn]: `/path/to/your/script/mrtg_person.sh`
MaxBytes[vpn]: 64
Options[vpn]: gauge, nopercent, growright
YLegend[vpn]: Online Users
ShortLegend[vpn]: %
LegendI[vpn]:   Online User:
LegendO[vpn]:   Online User:
Title[vpn]: clyang.net VPN Online User
PageTop[vpn]:
<h1>clyang.net VPN Online User</h1>
<table border="0">
<tbody>
<tr>
<td>System:</td>
<td>clyang.net VPN</td>
</tr>
<tr>
<td>Maintainer:</td>
<td>your@email.net.tw</td>
</tr>
</tbody></table>

接著編輯mrtg_person.sh,編輯完成後請記得chmod 755 mrtg_person.sh

#!/bin/sh
echo `netstat -a | grep gre|awk '{print $5}'|sort | wc -l|awk '{print$1}'`
echo `netstat -a | grep gre|awk '{print $5}'|sort | wc -l|awk '{print$1}'`
UPtime=`/usr/bin/uptime | awk '{print $3 " " $4 " " $5}'`
echo $UPtime
echo clyang.net

最後編輯crontab檔案,加上一行:

*/5 *   * * *   root    mrtg /etc/mrtg.person.cfg

就大功告成了。

本篇發表於 Linux, 技術 並標籤為 , , , 。將永久鏈結加入書籤。

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>