• R/O
  • SSH
  • HTTPS

p2pbbs: Commit


Commit MetaInfo

Revision27 (tree)
Time2010-01-21 18:41:15
Authorspark_xp

Log Message

ログ解析に利用するスクリプトを追加

Change Summary

Incremental Difference

--- P2PBBS/trunk/script/logtranslate_10.rb (nonexistent)
+++ P2PBBS/trunk/script/logtranslate_10.rb (revision 27)
@@ -0,0 +1,43 @@
1+#ログデータを解析する際に利用
2+#10秒ごとにどれだけのアクセスがあったのかを出力する
3+
4+require 'time'
5+require 'parsedate'
6+
7+if( ARGV.size != 3 )
8+ puts "Filename, 基準となる時刻, countTime"
9+ exit
10+end
11+
12+f = open(ARGV[0])
13+basicTime = Time.parse(ARGV[1])
14+countTime = ARGV[2].to_i
15+#10秒あたり何アクセスあったかを保持する
16+logTimeTable = Hash::new
17+
18+f.each do |line|
19+ logs = line.split(",")
20+ if( logs[1] != nil ) then
21+ date = Time.parse( logs[3] )
22+ #記録時間から基準時間を引いた値
23+ subtime = date.to_i - basicTime.to_i
24+ subtime = (subtime / 10).to_i
25+ #一番最後の時間
26+ $lastsubtime = date
27+ #puts subtime.to_s
28+ if( logTimeTable[ subtime ] == nil ) then
29+ logTimeTable[ subtime ] = logs[2].to_i
30+ else
31+ logTimeTable[ subtime ] = logTimeTable[ subtime ] + logs[2].to_i
32+ end
33+ end
34+end
35+f.close
36+
37+countTime.times do |i|
38+ if logTimeTable[ i ] == nil then
39+ puts i.to_s + " 0"
40+ else
41+ puts i.to_s + " " + logTimeTable[ i ].to_s
42+ end
43+end
--- P2PBBS/trunk/script/access.rb (nonexistent)
+++ P2PBBS/trunk/script/access.rb (revision 27)
@@ -0,0 +1,42 @@
1+#指定したホストの指定したトピックにアクセスを繰り返す
2+#agrs[0] = ホストアドレス, [1] = ポート番号, [2] = 何回アクセスするか, [3] = カテゴリID, [4] = トピックID
3+
4+require "net/http"
5+require "uri"
6+
7+puts "ReadNodeAddress, ReadNodePort, numOfRead, CategoryID, TopicID"
8+if ARGV.size != 5
9+ exit
10+end
11+
12+ReadNodeAddress = ARGV[0]
13+ReadNodePort = ARGV[1]
14+NumOfRead = ARGV[2].to_i
15+CategoryID = ARGV[3]
16+TopicID = ARGV[4]
17+
18+def access(address, port, numofread,category,topic)
19+ begin
20+ response = Net::HTTP.get( address, "/command/read/" \
21+ + category +"/"+topic+"/0-0", port )
22+ rescue
23+ puts "Error"
24+ end
25+end
26+
27+puts "\a"
28+
29+NumOfRead.times{|i|
30+ puts "" + i.to_s + "回目のアクセス"
31+ startTime = Time.now.to_f
32+ access( ReadNodeAddress, ReadNodePort, NumOfRead, CategoryID, TopicID)
33+ endTime = Time.now.to_f
34+ execTime = endTime - startTime
35+ waitTime = 0.1 - execTime
36+ if( waitTime <= 0.0 ) then
37+ waitTime = 0.0
38+ end
39+ puts "start: " + startTime.to_s + " endTime: " + endTime.to_s + " wait:" + waitTime.to_s
40+ sleep waitTime
41+}
42+
--- P2PBBS/trunk/script/getstatus.rb (nonexistent)
+++ P2PBBS/trunk/script/getstatus.rb (revision 27)
@@ -0,0 +1,32 @@
1+#指定したノードからログを出力する
2+#例えば,hosts.txtの中身が
3+# http://localhost:40001/
4+# http://localhost:40002/
5+#
6+#とした場合,
7+#cat hosts.txt | ruby getstatus.rb
8+#とすることで,指定したホストの状態が取得できる
9+
10+while line = gets
11+ #末尾の改行削除
12+ line = line.chomp
13+ filename = line.gsub(":","")
14+ filename = filename.gsub(".","")
15+ filename = filename.gsub("/","")
16+ filename = "./data/" + filename
17+ command = 'wget ' + line + 'command/status -o log.log -O' + filename + '_status.txt'
18+ #wget コマンド実行
19+ system( command )
20+ #ノード名
21+
22+ #infile = open("status.txt", "r")
23+ #puts "NODE:" + line.chomp
24+ #while l = infile.gets
25+ #ログ表示
26+ # print l
27+ #end
28+ #puts "NODEEND"
29+ #infile.close
30+ #status.txtを削除
31+ #system( 'rm status.txt' )
32+end
--- P2PBBS/trunk/script/postTopic.rb (revision 26)
+++ P2PBBS/trunk/script/postTopic.rb (revision 27)
@@ -1,38 +1,54 @@
1+#指定したホストに向かって沢山のトピック・コメントを投稿するスクリプト
2+#使い方
3+
4+#hosts.txt を用意
5+#このtxtには ホストアドレス:ポート番号が記述されている
6+#
7+#hosts.txtの例)
8+# 133.23.222.179:40001
9+# 133.23.222.179:40002
10+#
11+#その後, cat hosts.txt | ruby postTopic.rb 等と指定すればよい
12+
113 require "net/http"
214 require "uri"
315
4-host = "localhost:3997"
5-uri = URI.parse("http://" + host + "/command/manage/")
6-writeuri = URI.parse("http://" + host + "/command/write/")
7-10.times {|i|
8- category = nil
9- topic = nil
16+while line = gets
17+ #末尾の改行削除
18+ line.chomp!
1019
11- Net::HTTP.start(uri.host, uri.port){ |http|
12- body = "category=テストカテゴリ&title=テストトピック" \
13- + i.to_s \
14- + " from " \
15- + host \
16- + "&mail=test@test.com&password=test&message=" \
17- + "これはテストトピックです."
18- #データ送信
19- response = http.post(uri.path, body)
20- res = response.body.split(" ")
21- category = res[2]
22- topic = res[4]
23- }
24- 20.times{|j|
25- Net::HTTP.start(writeuri.host, writeuri.port){ |http|
26- body = "category=" + category \
27- + "&topic=" + topic \
28- + "&author=System" \
29- + "&mail=test@test.com" \
30- + "&message=これはテストメッセージ" \
31- + j.to_s \
32- + "です."
20+ host = line
21+ uri = URI.parse("http://" + host + "/command/manage/")
22+ writeuri = URI.parse("http://" + host + "/command/write/")
23+ 10.times {|i|
24+ category = nil
25+ topic = nil
3326
34- response = http.post(writeuri.path, body)
27+ Net::HTTP.start(uri.host, uri.port){ |http|
28+ body = "category=テストカテゴリ&title=テストトピック" \
29+ + i.to_s \
30+ + " from " \
31+ + host \
32+ + "&mail=test@test.com&password=test&message=" \
33+ + "これはテストトピックです."
34+ #データ送信
35+ response = http.post(uri.path, body)
36+ res = response.body.split(" ")
37+ category = res[2]
38+ topic = res[4]
3539 }
40+ 20.times{|j|
41+ Net::HTTP.start(writeuri.host, writeuri.port){ |http|
42+ body = "category=" + category \
43+ + "&topic=" + topic \
44+ + "&author=System" \
45+ + "&mail=test@test.com" \
46+ + "&message=これはテストメッセージ" \
47+ + j.to_s \
48+ + "です."
49+
50+ response = http.post(writeuri.path, body)
51+ }
52+ }
3653 }
37-}
38-
54+end
\ No newline at end of file
--- P2PBBS/trunk/script/logtime_trans.rb (nonexistent)
+++ P2PBBS/trunk/script/logtime_trans.rb (revision 27)
@@ -0,0 +1,33 @@
1+#ログデータを解析する際に利用
2+#ログに記録されている時間を経過時間に変換するスクリプト
3+
4+require 'time'
5+require 'parsedate'
6+
7+if( ARGV.size != 2 )
8+ puts "Filename, 基準となる時刻"
9+ exit
10+end
11+
12+f = open(ARGV[0])
13+basicTime = Time.parse(ARGV[1])
14+countTime = ARGV[2].to_i
15+
16+outputFile = File.open(ARGV[0] + "_trans.log", 'w')
17+
18+f.each do |line|
19+ logs = line.split(",")
20+ if( logs[1] != nil ) then
21+ date = Time.parse( logs[3] )
22+ #記録時間から基準時間を引いた値
23+ subtime = date.to_i - basicTime.to_i
24+
25+ #データ出力
26+ outputFile.puts logs[0].to_s + "," + logs[1].to_s + "," + logs[2].to_s + "," + subtime.to_s
27+ else
28+ outputFile.puts line + "\n\n\n"
29+ end
30+end
31+outputFile.close
32+f.close
33+
Show on old repository browser