Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
analyze_logs_by_rake
Search
namu
February 06, 2014
Technology
1
2.1k
analyze_logs_by_rake
ログ解析にRakeを使うことをオススメします
M3 Tech Talk #18 2014/01/31 #m3dev
namu
February 06, 2014
Tweet
Share
More Decks by namu
See All by namu
How To Create Chrome Extensions
namutaka
3
2.3k
Other Decks in Technology
See All in Technology
SREの前に
nwiizo
11
2.7k
マイベストのデータ基盤の現在と未来 / mybest-data-infra-asis-tobe
mybestinc
2
1.9k
[FOSS4G 2024 Japan LT] LLMを使ってGISデータ解析を自動化したい!
nssv
1
180
音声×Copilot オンコパの世界
kasada
1
110
SREの組織類型に応じた リーダシップの考察
kenta_hi
PRO
1
630
dev 補講: プロダクトセキュリティ / Product security overview
wa6sn
0
1.6k
Terraform未経験の御様に対してどの ように導⼊を進めていったか
tkikuchi
1
290
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
120
Redmine 6.0 新機能評価ガイド
vividtone
0
270
透過型SMTPプロキシによる送信メールの可観測性向上: Update Edition / Improved observability of outgoing emails with transparent smtp proxy: Update edition
linyows
2
190
Datadog RUM を用いた UX 指標の監視・顧客対応への活用
imamura_ko_0314
0
110
フロントエンド メタフレームワーク 選定の際に考えたこと
yuppeeng
0
600
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
264
13k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Thoughts on Productivity
jonyablonski
67
4.3k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
Why Our Code Smells
bkeepers
PRO
334
57k
A Philosophy of Restraint
colly
203
16k
Teambox: Starting and Learning
jrom
133
8.8k
Speed Design
sergeychernyshev
24
600
The Cult of Friendly URLs
andyhume
78
6k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Transcript
Rake Ͱϩάղੳ M3 Teck Talk #18 2014.01.31 தଜوࢤ
Rakeͱ • make ͷruby൛ • JavaͰ͍͏ͱ͜Ζͷant • Rakefileͱ͍͏ϑΝΠϧ໊ͰλεΫΛఆٛ • rakeίϚϯυͰλεΫΛ࣮ߦ
rakeͷ֓ཁ • ʮRakefileʯͱ͍͏ϑΝΠϧ໊ͰॲཧΛهड़ • هࡌશͳRuby • taskϝιουͰλεΫΛఆٛ • ґଘؔΛఆٛͯ͠Ұ࿈ͷॲཧͷྲྀΕΛ࡞ΕΔ •
fileϝιουͰϑΝΠϧΛ࡞͢ΔλεΫΛఆٛ • ϑΝΠϧ͕͋ͬͨΓɺґଘ͢ΔϑΝΠϧΑΓ৽͚͠ΕεΩοϓ ͢Δ • shϝιουͰγΣϧίϚϯυΛ࣮ߦͰ͖Δ
؆୯ͳྫ͔Β
$ rake -P #λεΫҰཡ rake hello rake world hello !
$ rake hello # hello Λ࣮ߦ Hello ! $ rake world # worldΛ࣮ߦ Hello World ! $ rake file1.txt ˌfile1.txtΛ࡞ $ ls file1.txt ! $ cat file1.txt 11111 # Rakefile ! task :hello do puts "Hello" end ! task :world => [:hello] do puts "World" end ! file "file1.txt" do |t| sh "echo 1111 > #{t.name}" end
$ rake all.txt << create file1.txt >> complete file1.txt <<
create file2.txt echo 2222 > file2.txt >> complete file2.txt << create all.txt cat file1.txt file2.txt > all.txt >> complete all.txt ! $ cat file1.txt 1111 ! $ cat file2.txt 2222 ! $ cat all.txt 1111 2222 file "file1.txt" do |t| puts "<< create file1.txt" File.open(t.name, "w") do |file| file.puts("1111") end puts ">> complete file1.txt" end ! file "file2.txt" do |t| puts "<< create file2.txt" sh "echo 2222 > #{t.name}" puts ">> complete file2.txt" end ! file "all.txt" => ["file1.txt", "file2.txt"] do |t| ! puts "<< create all.txt" sh "cat #{t.prerequisites.join(' ')} > #{t.name}" puts ">> complete all.txt" end
RakeΛ͏͓͢͢ΊϙΠϯτ
͓͢͢ΊϙΠϯτ • RubyͰॻ͚Δ • ̍ͭͷλεΫΛখ͍͞ػೳʹɺґଘؔͰҰ࿈ͷྲྀΕΛ ࡞Δͱɺػೳ͝ͱʹ࣮ߦͰ͖ͯσόοά͍͢͠ • ಈ࡞֬ೝ༻ͷॲཧΛఆ͍ٛ͢͠ • ్தͰࢭΊ࣮ͯߦࡁΈͷfileλεΫεΩοϓͯ͠ɺଓ
͖͔Β࣮ߦͰ͖Δ
ฒྻ࣮ߦ
ฒྻ࣮ߦ file1.txt ࡞ file2.txt ࡞ all.txt࡞ ͜͜ฒྻͰ࣮ߦͰ͖Δ
Pwrake https://github.com/masa16/Pwrake/ • ฒྻ࣮ߦ൛rake • ͦͷ··ͷRakefileͰฒྻ࣮ߦ͕Ͱ͖Δ • ࢦఆͨ͠λεΫʹґଘ͢ΔλεΫ܈ΛεϨουͰฒྻԽ ! •
Πϯετʔϧํ๏ $ gem install pwrake • ͍ํ $ pwrake -j <ฒྻ> <λεΫ໊>
$ pwrake -j 2 all.txt << create file1.txt << create
file2.txt echo 2222 > file2.txt >> complete file1.txt >> complete file2.txt << create all.txt cat file1.txt file2.txt > all.txt >> complete all.txt file "file1.txt" do |t| puts "<< create file1.txt" File.open(t.name, "w") do |file| file.puts("1111") end puts ">> complete file1.txt" end ! file "file2.txt" do |t| puts "<< create file2.txt" sh "echo 2222 > #{t.name}" puts ">> complete file2.txt" end ! file "all.txt" => ["file1.txt", "file2.txt"] do |t| ! puts "<< create all.txt" sh "cat #{t.prerequisites.join(' ')} > #{t.name}" puts ">> complete all.txt" end
ϩάղੳͷ࣮ํ๏
ϩάղੳ access.01.log access.02.log access.03.log access.04.log result.01.csv result.02.csv result.03.csv result.04.csv result_all.csv
$ rake -P rake data/result.1.txt rake data/result.2.txt rake data/result.3.txt rake
data/result_all.log data/result.1.txt data/result.2.txt data/result.3.txt ! $ pwrake -j 2 run # # log/access.1.log => data/result.1.log # log/access.2.log => data/result.2.log # log/access.3.log => data/result.3.log # results = [] (1..3).each do |num| logfile = "data/result.#{num}.txt" results << logfile ! file logfile do |t| sh "grep 'iPad' log/access.#{num}.log > #{t.name}" end end ! # # data/result.1.log # data/result.2.log => data/result_all.log # data/result.3.log # file “data/result_all.log" => results do |t| sh "cat #{t.prerequisites.join(' ‘)} > #{t.name}" end ! task :run => [“data/result_all.log"]
͓·͚
Tips • fileλεΫͷλʔήοτ ͱ͢ΔϑΝΠϧɺॲཧ ͷ࠷ޙʹmvͰ࡞Δ • ్தͰఀࢭͨ͠ͱ͖ʹɺ ࡞Γ͔͚ϑΝΠϧ͕͋Δ ͨΊʹɺεΩοϓ͞Εͳ ͍Α͏ʹ͢ΔͨΊ
file “target.txt” do |t| ! sh “grep HOGE src.log > “ + “ #{t.name}.tmp “ ! sh “mv #{t.name}.tmp #{t.name}” end