Created
July 23, 2013 00:53
-
-
Save masayuki5160/6059017 to your computer and use it in GitHub Desktop.
Hadoop streaming用のmapper
アクセスログからリファラーとかきりだし。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# アクセスログ解析用 mapper | |
accessLog = Hash.new | |
tmpLink = Array.new | |
tmpReferer = Array.new | |
#アクセスログを分割してReducerに渡す形式にする | |
ARGF.each do |log| | |
#末尾の改行コードを削除 | |
log.chomp! | |
#ださいけどこれで遷移先のアクションを取得 | |
/&/ =~ log | |
/action=/ =~ $` | |
tmpLink = $' | |
if tmpLink.nil? then | |
tmpLink= 'none' | |
end | |
#これもださいけどrefererからアクションを取得 | |
/http:/ =~ log | |
/&/ =~ $' | |
/action=/ =~ $` | |
tmpReferer = $' | |
if tmpReferer.nil? then | |
tmpReferer = 'none' | |
end | |
# Reducerに渡すように形式を整えて出力 | |
puts "#{tmpReferer}\t#{tmpLink}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment