﻿# 介紹好用工具：Monitorix ( 詳細的監控你的 Linux 主機狀況 )

最近在我管理的 Linux 主機上安裝了 [Monitorix](http://www.monitorix.org/) 工具，這是一套可以監控系統狀態的工具，可監控的項目非常的多，你也可以自行設定要監控的服務，預設就可以分析 CPU 與記憶體使用率、磁碟存取使用率(Disk I/O Usage)、網路使用率(Network traffic and usage)、各服務使用需求(network services demand)、使用者登入的狀況、....等等，而且還提供非常詳盡的 Web 報表，以下是我其中一台主機的報表。

[![Monitorix Reports](https://stwillblogassets.blob.core.windows.net/files/images/external/stwillblogassets.blob.core.windows.net/e4ca42969d5bc904a0ae-image_thumb.png)](https://stwillblogassets.blob.core.windows.net/files/images/external/stwillblogassets.blob.core.windows.net/fa1186a03094789725f7-image_2.png)

雖然網站上有提供 [Ubuntu Linux 7.10/8.04 的安裝說明](https://web.archive.org/web/20120511233700/http://www.monitorix.org:80/doc_ubuntu.html)，但我安裝在我的 Ubuntu Linux 8.04 的時候還是有些步驟不太一樣，以下是安裝的筆記：

**安裝相關套件** ( 記得一定要安裝 Apache 否則沒辦法看報表 )

```
apt-get install apache2 rrdtool and librrds-perl procmail
```

**下載最新版 Monitorix 套件** ( 可到[這裡](http://www.monitorix.org/downloads.html)查詢下載連結 )

```
wget http://www.monitorix.org/monitorix-1.2.2.tar.gz
```

**解壓縮**

```
tar zxvf monitorix-1.2.2.tar.gz
cd monitorix-1.2.2
vi install.sh
```

**修改 install.sh 安裝程式的第 63 到 69 行**

把

```
SBIN="/usr/local/sbin"
ETC="/usr/local/etc"
INIT="/usr/local/etc/rc.d"
LIB="/usr/local/lib"
DOC="/usr/local/share"
HTDOCS="/usr/local/www/data"
CGIBIN="/usr/local/www/cgi-bin"
```

改成

```
SBIN="/usr/sbin"
ETC="/etc"
INIT="/etc/init.d"
LIB="/usr/local/lib"
DOC="/usr/local/share"
HTDOCS="/var/www"
CGIBIN="/usr/lib/cgi-bin"
```

**正式進行安裝**

```
# ./install.sh

Welcome to Monitorix v1.2.1 installation process.

This install script has detected that this is a Linux operating system.

Currently Monitorix supports only the following Linux distributions:
        1 - RedHat/Fedora/CentOS
        2 - Generic
        3 - Debian
        4 - Gentoo
        5 - Slackware

        Please select your option: 2

The following is a list of the default paths where to install the Monitorix
components:

        1 - /usr/sbin
        2 - /etc
        3 - /etc/init.d
        4 - /usr/local/lib
        5 - /usr/local/share
        6 - /var/www
        7 - /usr/lib/cgi-bin

        Please type ENTER if all it's correct:

Last chance to stop the installation.
Are you sure to install Monitorix on the paths shown? [y/n]: y
```

**建立一個漏掉的目錄**

```
mkdir -p /var/lib/monitorix
```

**修正 vi /etc/monitorix.conf 的問題（第264行）**

將

```
our %BASE_WWW = ("Linux-RHFC"   => "/var/www/html",
```

改成

```
our %BASE_WWW = ("Linux-RHFC"   => "/var/www",
```

**啟動 Monitorix 服務**

```
/etc/init.d/monitorix.sh start
```

**變更排程的程式加上執行旗標**

```
chmod +x /etc/cron.d/monitorix
```

安裝完成！

**相關連結**

-   [Welcome to The Monitorix Project](http://www.monitorix.org/)
