• 沒有找到結果。

第四章 系統實做

4.5 WebServer的Througthput及效能分析

4.5.4 SNMP的裝設

用ports裝snmp

安裝完成後,我們必須先新增一個可以讀取SNMP資訊的

community name。所謂community name是一個明碼的字串,我們可以 將它視為management station和agent之間的密碼,是MRTG和

net-SNMP溝通時必須要先傳送的字串。

我們可以依不同的網域或主機給予不同的權限,依community name的設定來決定不同權限。一個網路元件可以有多個community name,一般SNMP Agent所預設公開的community name 是public。我 們不一定要將community name設定為public,因為public是一般SNMP 的預設值,為了安全問題,我們不將它設為public。

這裡我們設定community name為mrtg,而且只有read only的權 限。

要設定community name就要先新增一個文字檔 /usr/local/share/snmp/snmpd.conf並加入下列設定:

上面的設定中,mrtg為唯讀的community name,Your_Host_Name 是你機器所在的位置,而syscontact所接的字串是你的E-mail。

rocommunity mrtg

syslocation Your_Host_Name syscontact mrtg@localhost

# cd /usr/ports/net/net-snmp

# make install clean

另外我們還須在/etc/rc.conf中加入

啟動snmp

net_snmp_enable="YES"

/usr/local/etc/rc.d/snmpd.sh start

4.5.5 v的裝設

用ports裝mrtg

產生mrtg設定檔在/home/mrtg/public_html資料夾

接著在設定檔/usr/local/etc/mrtg/mrtg.cfg 裡加入我們要的設 定,如中文化、用 byte 或 bit 統計 … 等等。

我們的設定檔請見<附錄 F>

接著把MRTG的一些圖片複製到mrtg的目錄裡

最後,啟動mrtg

# cd /usr/ports/net/mrtg

# make install clean

# cfgmaker --global "WorkDir:

/home/mrtg/public_html" \

--global "Options[_]: growright" \ --ifref=nr mrtg@localhost >

/usr/local/etc/mrtg/mrtg.cfg

# cd /usr/ports/net/mrtg/work/mrtg*

# cd images

# cp * /home/www/mrtg/

# /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg

MRTG所分析的cpu使用量可以分為 每日 圖表 (5 分鐘 平均)

圖三十一

每週 圖表 (30 分鐘 平均)

圖三十二

每月 圖表 (2 小時 平均)

圖三十三 每年 圖表 (1 天 平均)

圖三十四

MRTG所分析的Memory使用量可以分為

每日 圖表 (5 分鐘 平均)

圖三十五

每週 圖表 (30 分鐘 平均)

圖三十六

每月 圖表 (2 小時 平均)

圖三十七

每年 圖表 (1 天 平均)

圖三十八

那我們以每日 圖表 (5 分鐘 平均)來看一下分析,在圖中可以 有最大.平均.目前的流量分析並以藍.綠色來分辨user和 Idle CPU 狀態圖,當使用者在使用cpu時,cpu不一定會忙碌中,且和在free memory中的圖比較一下,一定可以發現使用cpu時free memory必大大 降低,所以為了讓cpu在閒置的後能多做些些事情,在每週 圖表 (30 分鐘 平均),可以看出每日user使用cpu負荷直飆上漲,

那時候正在整合程式與測試信件的效能所以cpu的資源吃的非常兇,

因為本系統中因為隨時保有3個程式在執行(cparser 與 jconnect與 Dispatcher),通常要等到一項行程一直執行等到他必須等待什麼的 時候才停止,

一般來講都是等待一些I/O的要求,在一個簡單的系統之中,

此刻cpu只能為閒置狀態,所以這類的等待都是浪費時間的,

一點有用的工作也沒有,所以在cparser做I/O儲存到資料夾的同時,

會把cpu的控制存轉交給jconnect,等到cpu處理jconnect程式中判斷 有沒有信件進來eml的資料夾,後cparser所使用的I/O會發出中斷訊 息給cpu,並此時jconnect正處於停止一分鐘狀態,且把cpu經查詢中 斷向量表後,在繼續處理cparser的I/O處理,在組合信件的時候也一 樣,所以在cpu使用率可以比沒有使用一分鐘的機制好,不會cpu常常 閒置在那邊。

第五章 結 論 5.1 遭遇困難與解決方法

在這一次的專題裡,遭遇最多的困難應該是在規格的定義,因為 信件的規格形式有太多種,且欄位的順序與規格都不一。至於我們內 部程式所遇到比較困難的問題是在判斷一封信裡面的欄位,因為一封 Email裡面的欄位值可能有重複,像是boundary可以出現在內文與附 加檔案的邊界,那如何來判別哪一個是內文和哪一個是附加檔,使用 Content-Type:來分別,但Content-Type:又可以出現在內文與附加檔 裡,所以又用了name:這個欄位來分出內文與附加檔案,因為name:

這個欄位只有出現在附加檔案有;且在Cparser與Jconnect程式內部 中所遇到同步的問題我們是以時間來控制以及temp檔案來解決,因為 當parser一封信變成3個eml的途中,如果Jconnect來讀取pasrer的 eml,一定會發生同步的問題且檔案儲存到資料庫會不完全,所以利 用了一分鐘的時間來控制;當parser在讀取信件時,Jconnect就會去 判斷parser後暫存資料夾是否為空,如果為空,則表示信件已經完全 parser與儲存到真正要被資料庫讀取的資料夾,反之從資料庫讀取出 來的信件也事先存成temp檔在轉成eml並加入一分鐘機制來判斷同步 的問題,因此檔案就可以被正常處理,系統正常運作。

5.2 心得

此專題完成到現在,花了最久的時間是去研究那個一分鐘的同步 機制和暫存檔的運用也是花了很久的時間來制定的,且MIME格式都是 原文說明,更需要花一番功夫來研究。還有此專題的原本環境是在 Windows發展的,但後來因為發生疾風病毒的影響,原本用Asp來發展 的東西,改成了Jsp,並且在Unix-like下的環境發展,一剛開始對於 這種環境陌生的我們,去圖書館借了好幾本書回來研讀,才有能力來 發展程式,一路走來所看的書應該不少於十幾二十本,感覺獲益良多。

除此之外,在分工與溝通之間,我們彼此有學到了不少東西,像是程 式不懂的地方都會互相研討並加以溝通,所以到最後不會因為各自完 成的程式到最後無法整合,這些都是我們在此專題中學到的。

附錄 A 使用手冊

1.1 The java Connect Database Engine (jConnector)

jConnector 利用到了 Sybase 提供的 jconnect55 的 API, 來做 Sybase Database 存取 1. 它包含以下幾支類別檔:

轉換 Database 的 M_MAIN_OUT Table 的待寄出郵件 --> cParser 和 jConnector 的中間檔。

轉換 cParser 和 jConnector 的中間檔 --> Database 的 M_MAIN_IN 和 M_RECEIVER 二 Table。

Step:

1.取 Database 的 table 裡每一 row 值, 存成存成 files, 2.然後清空已被取出的 row

1.2 The java Dispatcher (DP)

ContentFilter.java 利用 Java1.4 的 Reglar Expression,

可以從~/conf/filter.conf 裡讀出所有要過濾的關鍵字 信件裡只要符合關鍵字, 就可以做過濾的動作

1.3 jConnector 和 DP 共用的類別檔

jConnector 和 DP 用到的共用類別檔:

=======================

FileNameFilter.java 設計用來做附檔名過濾用,因為 jConnector 只處理.eml,並不對其它檔案做動 作。

loadParameter.java 設計來對 system.conf 與 cparser 和 jConnector 的中間檔做處理的 要得到 system.conf 裡 index 值,

用 String getIndexOf(String fileIndex)要得到中間檔 index 的值,

用 Map collect(FileReader file, String table_name)。

eap.getMailDist(Mail_Str)

範例:

...

emlAddrParser eap = new emlAddrParser();

String Mail_Str = "\"aaa\" <[email protected]>";

System.out.println(eap.getNickName(Mail_Str) + ", " + eap.getAddr(Mail_Str) + ", " + eap.getID(Mail_Str) + ", " + eap.getDomain(Mail_Str) + ", " + eap.getMailDist(Mail_Str));

1.4 The Lex Parser (cParser)

mail_to_txt.l 使用方式:

lex mail_to_txt.l (之後會產生一個 lex.yy.c) cc lex.yy.c -o start_parser -ll (之後會產生一個 mail_to_txt 執行檔),

之後在把 lex.yy.c 改成 mail_to_txt.c

txt_to_mail.l 使用方式:

lex txt_to_mail.l (之後會產生一個 lex.yy.c) cc lex.yy.c -o txt_to_mail -ll (之後會產生一個 txt_to_mail 執行檔),

之後在把 lex.yy.c 改成 txt_to_mail.c

parser 和 unparser start_parser(表示開始執行 parser email) start_unparser(表示開始執行 unparser email)

附錄 B 過濾設定檔 - filter.conf

##############################################################

# #

# File: Content Filter Keywords #

# Group: DP (Dispatcher) #

# Introduce: #

# This is a set of keywords #

# that is not allowed in any e-mails. #

# 使用上請注意: #

# 1. 英文字母大小寫是當作不同來區分 #

# 2. 請以 "," 隔開每個 KeyWord #

# 3. 如在 KeyWord 這行裡要換行, 但下一行內容也是 KeyWord 的 #

# 則請在 KeyWord 的最後加 "," 或下一行的行頭加上 "," #

# #

##############################################################

KeyWord= 幹, fuck, damage ,陳水扁是笨蛋,

附錄 C 用到的相關 RFC 及整理

===========================================================

Internet Official Protocol Standards

中的 STD11(http://www.sri.ucl.ac.be/normes/rfc/rfc822.txt)裡面的定義 了 E-Mail 的標準架構

===========================================================

RFC 822

STD 11, defines a message representation protocol specifying considerable detail about US-ASCII message headers, and leaves the message content, or message body, as flat US-ASCII text. This set of

documents, collectively called the Multipurpose Internet Mail Extensions, or MIME, redefines the format of messages to allow for (1) textual message bodies in character sets other than

US-ASCII,

(2) an extensible set of different formats for non-textual message bodies,

(3) multi-part message bodies, and

(4) textual header information in character sets other than US-ASCII.

RFC 2046

defines the general structure of the MIME media typing system and defines an initial set of media types

RFC 2047

describes extensions to RFC 822 to allow non-US-ASCII text data in Internet mail header fields

===========================================================

RFC822(ARPA INTERNET TEXT MESSAGES)裡的 [Page16]MESSAGE SPECIFICATION 所定義的

1.when present, some fields, must be in a particular order 2.Header fields are NOT required to occur in any particular order, except that the message body must occur AFTER the headers 3.It is recommended that, if present, headers be sent in the order "Return-Path", "Received", "Date", "From", "Subject",

"Sender", "To", "cc", etc.

4.This specification permits multiple occurrences of most fields.

Except as noted, their interpretation is not specified here, and their use is discouraged.

5.Header 有 prefix 的, 也有不是 prefix 的

6.occurrence of legal "Resent-" fields are treated identically with

the occurrence of fields whose names do not contain this prefix.

各 Field 的 Header 功能:

01.MIME Header Fields

a)TRACE FIELDS - it indicates a route back to the sender of the message.

"Return-Path" - is used to identify a path back to the originator

"Reply-To" - is added by the originator and serves to direct replies

"Received" - A copy of this field is added by each transport

service that relays the message b)ORIGINATOR FIELDS

"From"

"Sender"

"Reply-To"

c)RECEIVER FIELDS

"To" - the primary recipients of the message.

"Cc" - the secondary(informa-tional) recipients of the message.

"Bcc" - additional recipients of the message.

d)REFERENCE FIELDS

"Message-ID" - This field contains a unique identifier (the local-part address unit)

which refers to THIS version of THIS message.

The uniqueness of the message identifier is guaranteed by the

host which generates it.

"In-Reply-To" - The contents of this field identify previous

correspon-dence which this message answers.

"References" - The contents of this field identify other correspondence

which this message references.

"Keywords" - This field contains keywords or phrases, separated by commas.

e)OTHER FIELDS

"Subject"

"Comments"

"Encrypted"

f)Extension-FIeld

"X-"

f)USER-DEFINED-FIELD - Non-Multiple with other header

"***:"

g)DATE AND TIME SPECIFICATION

"Date"

02.MIME-Version Header Field

"MIME-Version"

03.Content-Type Header Field

"Content-Type"

04.Content-Transfer-Encoding Header Field

"Content-Transfer-Encoding"

05.Content-ID Header Field

"Content-ID"

06.Content-Description Header Field

"Content-Description"

07.Additional MIME Header Fields - Any RFC 822 header field which begins with the string "Content-">

"Content-"

內文的部份:

Multipart:

-- Recognize the mixed subtype. Display all relevant

information on the message level and the body part header level and then display or offer to display each of the body parts individually.

-- Recognize the "alternative" subtype, and avoid showing the user redundant parts of

multipart/alternative mail.

-- Recognize the "multipart/digest" subtype, specifically using "message/rfc822" rather than

"text/plain" as the default media type for body parts inside "multipart/digest" entities.

-- Treat any unrecognized subtypes as if they were

"mixed".

=====================================================================

有關編碼:

RFC2047, RFC2049

=====================================================================

RFC 2047 Message Header Extensions

Generally, an "encoded-word" is a sequence of printable ASCII characters that begins with "=?", ends with "?=", and has two "?"s in between. It specifies a character set and an encoding method, and also includes the original text encoded as graphic ASCII characters, according to the rules for that encoding method.

附錄D X-Window的XF86Config設定檔

Section "ServerLayout"

Identifier "XFree86 Configured"

Screen 0 "Screen0" 0 0

InputDevice "Mouse0" "CorePointer"

InputDevice "Keyboard0" "CoreKeyboard"

EndSection Section "Files"

RgbPath "/usr/X11R6/lib/X11/rgb"

ModulePath "/usr/X11R6/lib/modules"

FontPath "/usr/X11R6/lib/X11/fonts/TrueType"

FontPath "/usr/X11R6/lib/X11/fonts/local"

FontPath "/usr/X11R6/lib/X11/fonts/misc/"

FontPath "/usr/X11R6/lib/X11/fonts/Speedo/"

FontPath "/usr/X11R6/lib/X11/fonts/Type1/"

FontPath "/usr/X11R6/lib/X11/fonts/75dpi/"

FontPath "/usr/X11R6/lib/X11/fonts/100dpi/"

EndSection

Section "Module"

Load "xtt"

Load "extmod"

Load "xie"

Load "dbe"

Load "dri"

Load "glx"

Load "record"

Load "xtrap"

Load "speedo"

Load "type1"

EndSection

Section "InputDevice"

Identifier "Keyboard0"

Driver "keyboard"

EndSection

Section "InputDevice"

Identifier "Mouse0"

Driver "mouse"

Option "Protocol" "auto"

Option "Device" "/dev/sysmouse"

EndSection

Section "Monitor"

Identifier "Monitor0"

VendorName "Monitor Vendor"

ModelName "Monitor Model"

Horizsync 31.5-57.0 VertRefresh 50-100 EndSection

Section "Device"

### Available Driver options are:-

### Values: <i>: integer, <f>: float, <bool>: "True"/"False", ### <string>: "String", <freq>: "<f> Hz/kHz/MHz"

### [arg]: arg optional

Identifier "Card0"

Driver "nv"

VendorName "nVidia Corporation"

BoardName "NV5M64 [RIVA TNT2 Model 64/Model 64 Pro]"

BusID "PCI:1:0:0"

EndSection

Section "Screen"

Identifier "Screen0"

Device "Card0"

Monitor "Monitor0"

DefaultColorDepth 16 SubSection "Display"

Depth 1 EndSubSection

SubSection "Display"

Depth 4 EndSubSection

SubSection "Display"

Depth 8 EndSubSection

SubSection "Display"

Depth 15 EndSubSection

SubSection "Display"

Depth 16

Modes "800x600" "1024x768"

Virtual 800 600 ViewPort 0 0 EndSubSection

SubSection "Display"

Depth 24 EndSubSection EndSection

附錄 E MRTG 設定檔

# Created by

# /usr/local/bin/cfgmaker --global 'WorkDir: /home/mrtg/public_html' --global 'Options[_]: growright' --ifref=nr mrtg@localhost

### Global Config Options

# for UNIX

# WorkDir: /home/http/mrtg

# or for NT

# WorkDir: c:\mrtgdata

### Global Defaults

# to get bits instead of bytes and graphs growing to the right

# Options[_]: growright, bits WorkDir: /home/mrtg/public_html Options[_]: growright

Language: big5

#####################################################################

#

# System: checkme.adsldns.org

# Description: FreeBSD checkme.adsldns.org 4.9-STABLE FreeBSD 4.9-STABLE

#0: Fri Oct i386

# Contact: mrtg@localhost

# Location: checkme.adsldns.org

#####################################################################

#

### Interface 1 >> Descr: 'vr0' | Name: '' | Ip: '10.0.0.1' | Eth: '' ###

Target[localhost_1]: 1:mrtg@localhost:

SetEnv[localhost_1]: MRTG_INT_IP="10.0.0.1" MRTG_INT_DESCR="vr0"

MaxBytes[localhost_1]: 130000

Title[localhost_1]: Traffic Analysis for 1 -- checkme.adsldns.org PageTop[localhost_1]: <H1>Traffic Analysis for 1 --

checkme.adsldns.org</H1>

<TABLE>

<TR><TD>System:</TD> <TD>checkme.adsldns.org in checkme.adsldns.org</TD></TR>

<TR><TD>System:</TD> <TD>checkme.adsldns.org in checkme.adsldns.org</TD></TR>

相關文件