repo
string
commit
string
message
string
diff
string
bryanwoods/portfolio
c8f9cbfe9ed077b98ce02d56acc3fcbe126f54b3
Updating screenshots
diff --git a/screenshots/krubrix/screenshot.png b/screenshots/krubrix/screenshot.png index 2a561d5..cf4cff4 100644 Binary files a/screenshots/krubrix/screenshot.png and b/screenshots/krubrix/screenshot.png differ diff --git a/screenshots/wedding_planner/screenshot.png b/screenshots/wedding_planner/screenshot.png deleted file mode 100644 index dac4618..0000000 Binary files a/screenshots/wedding_planner/screenshot.png and /dev/null differ
bryanwoods/portfolio
109e78f5e00c56822398f4f0ea4ce1b2d2addb47
Adding MusicForReason
diff --git a/screenshots/music_for_reason/screenshot.png b/screenshots/music_for_reason/screenshot.png new file mode 100644 index 0000000..b8aab22 Binary files /dev/null and b/screenshots/music_for_reason/screenshot.png differ
bryanwoods/portfolio
2aedcc239cd958bb78f71b6e33fc47d3aff17908
Updating project name
diff --git a/screenshots/invitedtoourwedding/screenshot.png b/screenshots/invitedtoourwedding/screenshot.png new file mode 100644 index 0000000..dac4618 Binary files /dev/null and b/screenshots/invitedtoourwedding/screenshot.png differ
bryanwoods/portfolio
cc02d6a4199aff13719a049f1d89d30b8d38b8ea
New screenshot
diff --git a/screenshots/wedding_planner/screenshot.png b/screenshots/wedding_planner/screenshot.png index 0c74389..dac4618 100644 Binary files a/screenshots/wedding_planner/screenshot.png and b/screenshots/wedding_planner/screenshot.png differ
bryanwoods/portfolio
24e14becb1ddbcb4eefaf6018c045a9a622b52ed
Adding wedding_planner screenshot
diff --git a/screenshots/wedding_planner/screenshot.png b/screenshots/wedding_planner/screenshot.png new file mode 100644 index 0000000..0c74389 Binary files /dev/null and b/screenshots/wedding_planner/screenshot.png differ
caspian311/xsem-parser
eb4183a565e734e855b40a2d848e6edff6280c1a
rake file now takes arguments for the various data files in the data directory to load into the database when using the install task
diff --git a/Rakefile b/Rakefile index 0a6b870..c7aa898 100644 --- a/Rakefile +++ b/Rakefile @@ -1,19 +1,20 @@ require 'rake' require 'rake/testtask' require 'rake/packagetask' require 'find' desc 'Default: run unit tests.' task :default => :test desc 'Test ASV Parser' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.pattern = 'test/**/*_test.rb' t.verbose = true end desc 'Install the ASV Bible into the db (takes a while)' task :install do - sh "ruby -Ilib lib/load.rb" + ARGV.shift + sh "ruby -Ilib lib/load.rb " + ARGV.join(" ") end diff --git a/lib/load.rb b/lib/load.rb index 76c1331..34a81a1 100644 --- a/lib/load.rb +++ b/lib/load.rb @@ -1,23 +1,22 @@ require 'active_record' require "xsem_parser" require "xsem_stream_listener" require "bible_model" require "db_importer" require "bible" require "book" require "chapter" require "verse" db_config = YAML::load(File.open(File.dirname(__FILE__) + '/../config/prod.yml')) ActiveRecord::Base.establish_connection(db_config) parser = XsemParser.new ARGV.each do |data_file| bible = parser.parse data_file importer = DbImporter.new bible importer.import_into_db end -
caspian311/xsem-parser
b0ce27b32cbea6eb9bc367c18f77ccccf937a44f
changed the api of the parser to give back the actual bible model instead of a list of books
diff --git a/lib/bible.rb b/lib/bible.rb index dfe0257..8aca438 100644 --- a/lib/bible.rb +++ b/lib/bible.rb @@ -1,5 +1,5 @@ -require 'active_record' - -class Bible<ActiveRecord::Base - has_many :books, :dependent => :destroy -end +require 'active_record' + +class Bible<ActiveRecord::Base + has_many :books, :dependent => :destroy +end diff --git a/lib/book_model.rb b/lib/book_model.rb index db14403..d28d8c3 100644 --- a/lib/book_model.rb +++ b/lib/book_model.rb @@ -1,14 +1,14 @@ -class BookModel - attr_reader :title - attr_reader :chapters - - def initialize(title) - @title = title - @chapters = [] - end - - def add_chapter(chapter) - @chapters << chapter - end -end - +class BookModel + attr_reader :title + attr_reader :chapters + + def initialize(title) + @title = title + @chapters = [] + end + + def add_chapter(chapter) + @chapters << chapter + end +end + diff --git a/lib/chapter_model.rb b/lib/chapter_model.rb index da1029c..853147b 100644 --- a/lib/chapter_model.rb +++ b/lib/chapter_model.rb @@ -1,13 +1,13 @@ -class ChapterModel - attr_reader :reference - attr_reader :verses - - def initialize(reference) - @reference = reference - @verses = [] - end - - def add_verse(verse) - @verses << verse - end -end +class ChapterModel + attr_reader :reference + attr_reader :verses + + def initialize(reference) + @reference = reference + @verses = [] + end + + def add_verse(verse) + @verses << verse + end +end diff --git a/lib/verse_model.rb b/lib/verse_model.rb index eb72361..cf6e5a9 100644 --- a/lib/verse_model.rb +++ b/lib/verse_model.rb @@ -1,9 +1,9 @@ -class VerseModel - attr_reader :reference - attr_accessor :text - - def initialize(reference) - @reference = reference - end -end - +class VerseModel + attr_reader :reference + attr_accessor :text + + def initialize(reference) + @reference = reference + end +end + diff --git a/lib/xsem_parser.rb b/lib/xsem_parser.rb index 0af93cb..c830b7e 100644 --- a/lib/xsem_parser.rb +++ b/lib/xsem_parser.rb @@ -1,12 +1,11 @@ require 'rexml/document' class XsemParser attr_reader :books def parse(filename) - @books = [] stream_listener = XsemStreamListener.new REXML::Document.parse_stream(File.open(filename), stream_listener) - @books = stream_listener.books.values + @bible = stream_listener.bible end end diff --git a/lib/xsem_stream_listener.rb b/lib/xsem_stream_listener.rb index c6dff88..a48e4d6 100644 --- a/lib/xsem_stream_listener.rb +++ b/lib/xsem_stream_listener.rb @@ -1,62 +1,82 @@ require 'rexml/streamlistener' +require "lib/bible_model" require "lib/book_model" require "lib/chapter_model" require "lib/verse_model" class XsemStreamListener include REXML::StreamListener - attr_reader :books - - def initialize - @books = {} - end + def initialize + @books = {} + end def tag_start(name, attributes) - if name == 'bookDecl' - @book_id = attribute_val(attributes, 'id') + if name == 'versionName' + @getting_long_name = true; + elsif name == 'versionAbbreviation' + @getting_short_name = true; + elsif name == 'bookDecl' + @book_id = attribute_value(attributes, 'id') elsif name == 'shortName' @in_book_title = true elsif name == 'book' - @current_book = @books[attribute_val(attributes, 'value')] + @current_book = @books[attribute_value(attributes, 'value')] elsif name == 'chapter' - @current_chapter = ChapterModel.new attribute_val(attributes, 'value') + @current_chapter = ChapterModel.new attribute_value(attributes, 'value') @current_book.add_chapter @current_chapter elsif name == 'verse' - @current_verse = VerseModel.new attribute_val(attributes, 'value') + @current_verse = VerseModel.new attribute_value(attributes, 'value') @current_chapter.add_verse @current_verse @in_verse = true elsif name == 'verseEnd' @in_verse = false end end def tag_end(name) if name == 'bookDecl' @books[@book_id] = BookModel.new @book_title - end + elsif name == 'versionAbbreviation' + @getting_short_name = false + elsif name == 'versionName' + @getting_long_name = false + elsif name == 'shortName' + @in_book_title = false + end end def text(text) - if @in_book_title + if @getting_long_name + @long_name = text.strip + elsif @getting_short_name + @short_name = text.strip + elsif @in_book_title @book_title = text.strip - @in_book_title = false elsif @in_verse @current_verse.text = text.strip end end + def bible + bible = BibleModel.new @short_name + bible.long_name = @long_name + bible.books = @books.values + + return bible + end + private - def attribute_val(attributes, key) + def attribute_value(attributes, key) value = nil attributes.each do |attribute_pair| if attribute_pair[0] == key value = attribute_pair[1] break end end return value end end diff --git a/test/test.xml b/test/test.xml index 186a909..4a371bd 100644 --- a/test/test.xml +++ b/test/test.xml @@ -1,56 +1,63 @@ +<?xml version="1.0" encoding="utf-8"?> <scripture> - <scriptureHeader> - <bookDecl id="GEN"> - <shortName>Genesis</shortName> - <longName>blah blah</longName> - </bookDecl> - <bookDecl id="MAT"> - <shortName>Matthew</shortName> - <longName>blah blah blah</longName> - </bookDecl> - </scriptureHeader> - <canon id="OT" value="OT"> - <book value="GEN"> - <text> - <chapter value="1" /> - <verse value="1" /> + <scriptureHeader> + <versionStmt> + <versionDecl id="ASV"> + <versionName>The American Standard Version of the Holy Bible (1901)</versionName> + <versionAbbreviation>ASV</versionAbbreviation> + </versionDecl> + </versionStmt> + <bookDecl id="GEN"> + <shortName>Genesis</shortName> + <longName>blah blah</longName> + </bookDecl> + <bookDecl id="MAT"> + <shortName>Matthew</shortName> + <longName>blah blah blah</longName> + </bookDecl> + </scriptureHeader> + <canon id="OT" value="OT"> + <book value="GEN"> + <text> + <chapter value="1" /> + <verse value="1" /> In the beginning God created the heavens and the earth. - <verseEnd /> - <verse value="2" /> + <verseEnd /> + <verse value="2" /> And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters. - <verseEnd /> - <chapterEnd /> - <chapter value="2" /> - <verse value="1" /> + <verseEnd /> + <chapterEnd /> + <chapter value="2" /> + <verse value="1" /> And the heavens and the earth were finished, and all the host of them. - <verseEnd /> - <verse value="2" /> + <verseEnd /> + <verse value="2" /> And on the seventh day God finished his work which he had made; and he rested on the seventh day from all his work which he had made. - <verseEnd /> - <chapterEnd /> - </text> - </book> - </canon> - <canon id="NT" value="NT"> - <book value="MAT"> - <text> - <chapter value="1" /> - <verse value="1" /> + <verseEnd /> + <chapterEnd /> + </text> + </book> + </canon> + <canon id="NT" value="NT"> + <book value="MAT"> + <text> + <chapter value="1" /> + <verse value="1" /> The book of the generation of Jesus Christ, the son of David, the son of Abraham. - <verseEnd /> - <verse value="2" /> + <verseEnd /> + <verse value="2" /> Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judah and his brethren; - <verseEnd /> - <chapterEnd /> - <chapter value="2" /> - <verse value="1" /> + <verseEnd /> + <chapterEnd /> + <chapter value="2" /> + <verse value="1" /> Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, Wise-men from the east came to Jerusalem, saying, - <verseEnd /> - <verse value="2" /> + <verseEnd /> + <verse value="2" /> Where is he that is born King of the Jews? for we saw his star in the east, and are come to worship him. - <verseEnd /> - <chapterEnd /> - </text> - </book> - </canon> + <verseEnd /> + <chapterEnd /> + </text> + </book> + </canon> </scripture> \ No newline at end of file diff --git a/test/xsem_parser_test.rb b/test/xsem_parser_test.rb index ccefbdf..2854c3a 100644 --- a/test/xsem_parser_test.rb +++ b/test/xsem_parser_test.rb @@ -1,36 +1,39 @@ require File.dirname(__FILE__) + "/test_helper" require "rexml/document" class XsemParserTest < Test::Unit::TestCase def test_parsing_test_file parser = XsemParser.new - parser.parse File.dirname(__FILE__) + '/test.xml' + bible = parser.parse File.dirname(__FILE__) + '/test.xml' - parser.books.each do |book| + assert_equal "ASV", bible.short_name + assert_equal "The American Standard Version of the Holy Bible (1901)", bible.long_name + + bible.books.each do |book| if book.title == 'Genesis' check_genesis book elsif book.title == 'Matthew' check_matthew book else flunk 'unrecognized book' end end end def check_genesis(book) assert_equal('Genesis', book.title) assert_equal('In the beginning God created the heavens and the earth.', book.chapters[0].verses[0].text) assert_equal('And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters.', book.chapters[0].verses[1].text) assert_equal('And the heavens and the earth were finished, and all the host of them.', book.chapters[1].verses[0].text) assert_equal('And on the seventh day God finished his work which he had made; and he rested on the seventh day from all his work which he had made.', book.chapters[1].verses[1].text) end def check_matthew(book) assert_equal('Matthew', book.title) assert_equal('The book of the generation of Jesus Christ, the son of David, the son of Abraham.', book.chapters[0].verses[0].text) assert_equal('Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judah and his brethren;', book.chapters[0].verses[1].text) assert_equal('Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, Wise-men from the east came to Jerusalem, saying,', book.chapters[1].verses[0].text) end end
caspian311/xsem-parser
89e6b4a24ba938776db2c638ffafe10187aecfdc
added rubygems to tests to see if it would fix the build on my cruise box
diff --git a/test/test_helper.rb b/test/test_helper.rb index d9e9cf2..1b4d36c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,13 +1,15 @@ $:.unshift File.join(File.dirname(__FILE__),'..','lib') +require "rubygems" +require "test/unit" + require File.dirname(__FILE__) + "/../lib/bible" require File.dirname(__FILE__) + "/../lib/book" require File.dirname(__FILE__) + "/../lib/chapter" require File.dirname(__FILE__) + "/../lib/verse" require File.dirname(__FILE__) + "/../lib/db_importer" require File.dirname(__FILE__) + "/../lib/xsem_parser" require File.dirname(__FILE__) + "/../lib/xsem_stream_listener" require File.dirname(__FILE__) + "/../lib/sql_builder" -require "test/unit" require File.dirname(__FILE__) + "/../test/test_connection_info"
caspian311/xsem-parser
a5b136aa1a6364c290b336a291f874c35879c615
renamed run to load
diff --git a/Rakefile b/Rakefile index 18235ce..0a6b870 100644 --- a/Rakefile +++ b/Rakefile @@ -1,19 +1,19 @@ require 'rake' require 'rake/testtask' require 'rake/packagetask' require 'find' desc 'Default: run unit tests.' task :default => :test desc 'Test ASV Parser' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.pattern = 'test/**/*_test.rb' t.verbose = true end desc 'Install the ASV Bible into the db (takes a while)' task :install do - sh "ruby -Ilib lib/run.rb" + sh "ruby -Ilib lib/load.rb" end diff --git a/lib/run.rb b/lib/load.rb similarity index 100% rename from lib/run.rb rename to lib/load.rb
caspian311/xsem-parser
332d774ac7a0c3bb93db6e7c02818e6a6170f350
setting up run to be able to load multiple data files
diff --git a/lib/run.rb b/lib/run.rb index bbb9890..76c1331 100644 --- a/lib/run.rb +++ b/lib/run.rb @@ -1,23 +1,23 @@ require 'active_record' require "xsem_parser" require "xsem_stream_listener" require "bible_model" require "db_importer" require "bible" require "book" require "chapter" require "verse" db_config = YAML::load(File.open(File.dirname(__FILE__) + '/../config/prod.yml')) ActiveRecord::Base.establish_connection(db_config) parser = XsemParser.new -parser.parse File.dirname(__FILE__) + '/../data/asv.xml' -bible_model = BibleModel.new 'ASV' -bible_model.long_name = 'American Standard Version' -bible_model.books = parser.books +ARGV.each do |data_file| + bible = parser.parse data_file + + importer = DbImporter.new bible + importer.import_into_db +end -importer = DbImporter.new bible_model -importer.import_into_db \ No newline at end of file diff --git a/lib/xsem_parser.rb b/lib/xsem_parser.rb index e09178b..0af93cb 100644 --- a/lib/xsem_parser.rb +++ b/lib/xsem_parser.rb @@ -1,15 +1,12 @@ require 'rexml/document' class XsemParser attr_reader :books - def initialize - @stream_listener = XsemStreamListener.new - end - def parse(filename) - file = File.open(filename) - REXML::Document.parse_stream(file, @stream_listener) - @books = @stream_listener.books.values + @books = [] + stream_listener = XsemStreamListener.new + REXML::Document.parse_stream(File.open(filename), stream_listener) + @books = stream_listener.books.values end end
caspian311/xsem-parser
a083b793b79b03b64e2a14493f22e411cba06228
added yml config file to store prod and test db connection infos
diff --git a/config/prod.yml b/config/prod.yml new file mode 100644 index 0000000..cb213d3 --- /dev/null +++ b/config/prod.yml @@ -0,0 +1,5 @@ +adapter: mysql +database: bible +host: 127.0.0.1 +username: root +password: root diff --git a/config/test.yml b/config/test.yml new file mode 100644 index 0000000..6e42ba8 --- /dev/null +++ b/config/test.yml @@ -0,0 +1,5 @@ +adapter: mysql +database: bible_test +host: 127.0.0.1 +username: root +password: root diff --git a/lib/run.rb b/lib/run.rb index 42c2955..bbb9890 100644 --- a/lib/run.rb +++ b/lib/run.rb @@ -1,27 +1,23 @@ require 'active_record' require "xsem_parser" require "xsem_stream_listener" require "bible_model" require "db_importer" require "bible" require "book" require "chapter" require "verse" -ActiveRecord::Base.establish_connection( - :adapter => 'mysql', - :database => 'bible', - :host => '127.0.0.1', - :username => 'root', - :password => 'root') +db_config = YAML::load(File.open(File.dirname(__FILE__) + '/../config/prod.yml')) +ActiveRecord::Base.establish_connection(db_config) parser = XsemParser.new parser.parse File.dirname(__FILE__) + '/../data/asv.xml' bible_model = BibleModel.new 'ASV' bible_model.long_name = 'American Standard Version' bible_model.books = parser.books importer = DbImporter.new bible_model importer.import_into_db \ No newline at end of file diff --git a/test/test_connection_info.rb b/test/test_connection_info.rb index 235fa76..b927ce0 100644 --- a/test/test_connection_info.rb +++ b/test/test_connection_info.rb @@ -1,8 +1,4 @@ require 'active_record' -ActiveRecord::Base.establish_connection( - :adapter => 'mysql', - :database => 'bible_test', - :host => '127.0.0.1', - :username => 'root', - :password => 'root') +db_config = YAML::load(File.open(File.dirname(__FILE__) + '/../config/test.yml')) +ActiveRecord::Base.establish_connection(db_config)
caspian311/xsem-parser
d43aea02c825a4780b9ab7108906ad1641652642
again changed the parser api to take a string path to file rather than a file
diff --git a/lib/run.rb b/lib/run.rb index 5cd3be6..42c2955 100644 --- a/lib/run.rb +++ b/lib/run.rb @@ -1,27 +1,27 @@ require 'active_record' require "xsem_parser" require "xsem_stream_listener" require "bible_model" require "db_importer" require "bible" require "book" require "chapter" require "verse" ActiveRecord::Base.establish_connection( :adapter => 'mysql', :database => 'bible', :host => '127.0.0.1', :username => 'root', :password => 'root') parser = XsemParser.new -parser.parse File.open(File.dirname(__FILE__) + '/../data/asv-xsem.xml') +parser.parse File.dirname(__FILE__) + '/../data/asv.xml' bible_model = BibleModel.new 'ASV' bible_model.long_name = 'American Standard Version' bible_model.books = parser.books importer = DbImporter.new bible_model importer.import_into_db \ No newline at end of file diff --git a/lib/xsem_parser.rb b/lib/xsem_parser.rb index 02bd5a0..e09178b 100644 --- a/lib/xsem_parser.rb +++ b/lib/xsem_parser.rb @@ -1,14 +1,15 @@ require 'rexml/document' class XsemParser attr_reader :books def initialize @stream_listener = XsemStreamListener.new end - def parse(file) + def parse(filename) + file = File.open(filename) REXML::Document.parse_stream(file, @stream_listener) @books = @stream_listener.books.values end end diff --git a/test/xsem_parser_test.rb b/test/xsem_parser_test.rb index 5e1135a..ccefbdf 100644 --- a/test/xsem_parser_test.rb +++ b/test/xsem_parser_test.rb @@ -1,36 +1,36 @@ require File.dirname(__FILE__) + "/test_helper" require "rexml/document" class XsemParserTest < Test::Unit::TestCase def test_parsing_test_file parser = XsemParser.new - parser.parse File.open(File.dirname(__FILE__) + '/test.xml') + parser.parse File.dirname(__FILE__) + '/test.xml' parser.books.each do |book| if book.title == 'Genesis' check_genesis book elsif book.title == 'Matthew' check_matthew book else flunk 'unrecognized book' end end end def check_genesis(book) assert_equal('Genesis', book.title) assert_equal('In the beginning God created the heavens and the earth.', book.chapters[0].verses[0].text) assert_equal('And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters.', book.chapters[0].verses[1].text) assert_equal('And the heavens and the earth were finished, and all the host of them.', book.chapters[1].verses[0].text) assert_equal('And on the seventh day God finished his work which he had made; and he rested on the seventh day from all his work which he had made.', book.chapters[1].verses[1].text) end def check_matthew(book) assert_equal('Matthew', book.title) assert_equal('The book of the generation of Jesus Christ, the son of David, the son of Abraham.', book.chapters[0].verses[0].text) assert_equal('Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judah and his brethren;', book.chapters[0].verses[1].text) assert_equal('Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, Wise-men from the east came to Jerusalem, saying,', book.chapters[1].verses[0].text) end end
caspian311/xsem-parser
1775e974f1d43db6551f37ed5794a446047fa8e4
renamed the asv to xsem
diff --git a/lib/run.rb b/lib/run.rb index a56b8c4..5cd3be6 100644 --- a/lib/run.rb +++ b/lib/run.rb @@ -1,27 +1,27 @@ require 'active_record' -require "asv_parser" -require "asv_stream_listener" +require "xsem_parser" +require "xsem_stream_listener" require "bible_model" require "db_importer" require "bible" require "book" require "chapter" require "verse" ActiveRecord::Base.establish_connection( :adapter => 'mysql', :database => 'bible', :host => '127.0.0.1', :username => 'root', :password => 'root') -parser = AsvParser.new +parser = XsemParser.new parser.parse File.open(File.dirname(__FILE__) + '/../data/asv-xsem.xml') bible_model = BibleModel.new 'ASV' bible_model.long_name = 'American Standard Version' bible_model.books = parser.books importer = DbImporter.new bible_model -importer.import_into_db +importer.import_into_db \ No newline at end of file diff --git a/lib/asv_parser.rb b/lib/xsem_parser.rb similarity index 72% rename from lib/asv_parser.rb rename to lib/xsem_parser.rb index 667e924..02bd5a0 100644 --- a/lib/asv_parser.rb +++ b/lib/xsem_parser.rb @@ -1,14 +1,14 @@ require 'rexml/document' -class AsvParser +class XsemParser attr_reader :books def initialize - @stream_listener = AsvStreamListener.new + @stream_listener = XsemStreamListener.new end def parse(file) REXML::Document.parse_stream(file, @stream_listener) @books = @stream_listener.books.values end end diff --git a/lib/asv_stream_listener.rb b/lib/xsem_stream_listener.rb similarity index 98% rename from lib/asv_stream_listener.rb rename to lib/xsem_stream_listener.rb index 764b5ae..c6dff88 100644 --- a/lib/asv_stream_listener.rb +++ b/lib/xsem_stream_listener.rb @@ -1,62 +1,62 @@ require 'rexml/streamlistener' require "lib/book_model" require "lib/chapter_model" require "lib/verse_model" -class AsvStreamListener +class XsemStreamListener include REXML::StreamListener attr_reader :books def initialize @books = {} end def tag_start(name, attributes) if name == 'bookDecl' @book_id = attribute_val(attributes, 'id') elsif name == 'shortName' @in_book_title = true elsif name == 'book' @current_book = @books[attribute_val(attributes, 'value')] elsif name == 'chapter' @current_chapter = ChapterModel.new attribute_val(attributes, 'value') @current_book.add_chapter @current_chapter elsif name == 'verse' @current_verse = VerseModel.new attribute_val(attributes, 'value') @current_chapter.add_verse @current_verse @in_verse = true elsif name == 'verseEnd' @in_verse = false end end def tag_end(name) if name == 'bookDecl' @books[@book_id] = BookModel.new @book_title end end def text(text) if @in_book_title @book_title = text.strip @in_book_title = false elsif @in_verse @current_verse.text = text.strip end end private def attribute_val(attributes, key) value = nil attributes.each do |attribute_pair| if attribute_pair[0] == key value = attribute_pair[1] break end end return value end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 1da600f..d9e9cf2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,13 +1,13 @@ $:.unshift File.join(File.dirname(__FILE__),'..','lib') require File.dirname(__FILE__) + "/../lib/bible" require File.dirname(__FILE__) + "/../lib/book" require File.dirname(__FILE__) + "/../lib/chapter" require File.dirname(__FILE__) + "/../lib/verse" require File.dirname(__FILE__) + "/../lib/db_importer" -require File.dirname(__FILE__) + "/../lib/asv_parser" -require File.dirname(__FILE__) + "/../lib/asv_stream_listener" +require File.dirname(__FILE__) + "/../lib/xsem_parser" +require File.dirname(__FILE__) + "/../lib/xsem_stream_listener" require File.dirname(__FILE__) + "/../lib/sql_builder" require "test/unit" require File.dirname(__FILE__) + "/../test/test_connection_info" diff --git a/test/asv_parser_test.rb b/test/xsem_parser_test.rb similarity index 95% rename from test/asv_parser_test.rb rename to test/xsem_parser_test.rb index f615b71..5e1135a 100644 --- a/test/asv_parser_test.rb +++ b/test/xsem_parser_test.rb @@ -1,36 +1,36 @@ require File.dirname(__FILE__) + "/test_helper" require "rexml/document" -class AsvParserTest < Test::Unit::TestCase +class XsemParserTest < Test::Unit::TestCase def test_parsing_test_file - parser = AsvParser.new + parser = XsemParser.new parser.parse File.open(File.dirname(__FILE__) + '/test.xml') parser.books.each do |book| if book.title == 'Genesis' check_genesis book elsif book.title == 'Matthew' check_matthew book else flunk 'unrecognized book' end end end def check_genesis(book) assert_equal('Genesis', book.title) assert_equal('In the beginning God created the heavens and the earth.', book.chapters[0].verses[0].text) assert_equal('And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters.', book.chapters[0].verses[1].text) assert_equal('And the heavens and the earth were finished, and all the host of them.', book.chapters[1].verses[0].text) assert_equal('And on the seventh day God finished his work which he had made; and he rested on the seventh day from all his work which he had made.', book.chapters[1].verses[1].text) end def check_matthew(book) assert_equal('Matthew', book.title) assert_equal('The book of the generation of Jesus Christ, the son of David, the son of Abraham.', book.chapters[0].verses[0].text) assert_equal('Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judah and his brethren;', book.chapters[0].verses[1].text) assert_equal('Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, Wise-men from the east came to Jerusalem, saying,', book.chapters[1].verses[0].text) end end
caspian311/xsem-parser
cb4f397d539733fe38dcbf86f20c1e271b5fbe8e
changed the api for the asv parser
diff --git a/Rakefile b/Rakefile index 93aca35..18235ce 100644 --- a/Rakefile +++ b/Rakefile @@ -1,21 +1,19 @@ require 'rake' require 'rake/testtask' require 'rake/packagetask' require 'find' desc 'Default: run unit tests.' task :default => :test desc 'Test ASV Parser' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.pattern = 'test/**/*_test.rb' t.verbose = true end -desc 'Install all into the db (takes a while)' -task :install do |t| - t.libs << 'lib' - t.pattern = 'lib/run.rb' - t.verbose = true +desc 'Install the ASV Bible into the db (takes a while)' +task :install do + sh "ruby -Ilib lib/run.rb" end diff --git a/lib/asv_parser.rb b/lib/asv_parser.rb index 3347e6c..667e924 100644 --- a/lib/asv_parser.rb +++ b/lib/asv_parser.rb @@ -1,14 +1,14 @@ require 'rexml/document' class AsvParser attr_reader :books - def initialize(stream_listener) - @stream_listener = stream_listener + def initialize + @stream_listener = AsvStreamListener.new end def parse(file) REXML::Document.parse_stream(file, @stream_listener) @books = @stream_listener.books.values end end diff --git a/lib/run.rb b/lib/run.rb index 513febc..a56b8c4 100644 --- a/lib/run.rb +++ b/lib/run.rb @@ -1,18 +1,27 @@ -require 'lib/AsvParser' -require 'lib/AsvStreamListener' -require 'lib/DbImporter' -require 'lib/BibleModel' +require 'active_record' -Bible.all.each do |bible| - bible.destroy -end +require "asv_parser" +require "asv_stream_listener" +require "bible_model" +require "db_importer" +require "bible" +require "book" +require "chapter" +require "verse" -parser = AsvParser.new(AsvStreamListener.new) +ActiveRecord::Base.establish_connection( + :adapter => 'mysql', + :database => 'bible', + :host => '127.0.0.1', + :username => 'root', + :password => 'root') + +parser = AsvParser.new parser.parse File.open(File.dirname(__FILE__) + '/../data/asv-xsem.xml') bible_model = BibleModel.new 'ASV' bible_model.long_name = 'American Standard Version' bible_model.books = parser.books importer = DbImporter.new bible_model importer.import_into_db diff --git a/test/asv_parser_test.rb b/test/asv_parser_test.rb index 844b689..f615b71 100644 --- a/test/asv_parser_test.rb +++ b/test/asv_parser_test.rb @@ -1,36 +1,36 @@ require File.dirname(__FILE__) + "/test_helper" require "rexml/document" class AsvParserTest < Test::Unit::TestCase def test_parsing_test_file - parser = AsvParser.new(AsvStreamListener.new) + parser = AsvParser.new parser.parse File.open(File.dirname(__FILE__) + '/test.xml') parser.books.each do |book| if book.title == 'Genesis' check_genesis book elsif book.title == 'Matthew' check_matthew book else flunk 'unrecognized book' end end end def check_genesis(book) assert_equal('Genesis', book.title) assert_equal('In the beginning God created the heavens and the earth.', book.chapters[0].verses[0].text) assert_equal('And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters.', book.chapters[0].verses[1].text) assert_equal('And the heavens and the earth were finished, and all the host of them.', book.chapters[1].verses[0].text) assert_equal('And on the seventh day God finished his work which he had made; and he rested on the seventh day from all his work which he had made.', book.chapters[1].verses[1].text) end def check_matthew(book) assert_equal('Matthew', book.title) assert_equal('The book of the generation of Jesus Christ, the son of David, the son of Abraham.', book.chapters[0].verses[0].text) assert_equal('Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judah and his brethren;', book.chapters[0].verses[1].text) assert_equal('Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, Wise-men from the east came to Jerusalem, saying,', book.chapters[1].verses[0].text) end end
caspian311/xsem-parser
36ae50965932570d46a3f95abd262bee11ebeb61
removed the integration test and tried to create an install task in the rake file
diff --git a/Rakefile b/Rakefile index a43b455..93aca35 100644 --- a/Rakefile +++ b/Rakefile @@ -1,14 +1,21 @@ require 'rake' require 'rake/testtask' require 'rake/packagetask' require 'find' desc 'Default: run unit tests.' task :default => :test desc 'Test ASV Parser' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.pattern = 'test/**/*_test.rb' t.verbose = true end + +desc 'Install all into the db (takes a while)' +task :install do |t| + t.libs << 'lib' + t.pattern = 'lib/run.rb' + t.verbose = true +end diff --git a/lib/run.rb b/lib/run.rb new file mode 100644 index 0000000..513febc --- /dev/null +++ b/lib/run.rb @@ -0,0 +1,18 @@ +require 'lib/AsvParser' +require 'lib/AsvStreamListener' +require 'lib/DbImporter' +require 'lib/BibleModel' + +Bible.all.each do |bible| + bible.destroy +end + +parser = AsvParser.new(AsvStreamListener.new) +parser.parse File.open(File.dirname(__FILE__) + '/../data/asv-xsem.xml') + +bible_model = BibleModel.new 'ASV' +bible_model.long_name = 'American Standard Version' +bible_model.books = parser.books + +importer = DbImporter.new bible_model +importer.import_into_db diff --git a/test/end_to_end_integration_test.rb b/test/end_to_end_integration_test.rb deleted file mode 100644 index fff82f7..0000000 --- a/test/end_to_end_integration_test.rb +++ /dev/null @@ -1,35 +0,0 @@ -require File.dirname(__FILE__) + "/test_helper" - -class EndToEndIntegrationTest < Test::Unit::TestCase - def setup - cleanup - end - - def teardown - cleanup - end - - def cleanup - Bible.all.each do |bible| - bible.destroy - end - end - - def test_import_actual_file - parser = AsvParser.new(AsvStreamListener.new) - parser.parse File.open(File.dirname(__FILE__) + '/../data/asv-xsem.xml') - - bible_model = BibleModel.new 'ASV' - bible_model.long_name = 'American Standard Version' - bible_model.books = parser.books - - importer = DbImporter.new bible_model - importer.import_into_db - - assert_equal 1, Bible.all.size - asv_bible = Bible.all[0] - - # this is not right but it should show how many books in the failure message - assert_equal 3, asv_bible.books.size - end -end
caspian311/xsem-parser
963447d736ff687fbe24b7ab6d3f25fe8efb6983
added a test that would actually populate the entire database and then clear it out again... not sure if i want to keep it, but it's a good demostration of the tool working
diff --git a/test/end_to_end_integration_test.rb b/test/end_to_end_integration_test.rb new file mode 100644 index 0000000..fff82f7 --- /dev/null +++ b/test/end_to_end_integration_test.rb @@ -0,0 +1,35 @@ +require File.dirname(__FILE__) + "/test_helper" + +class EndToEndIntegrationTest < Test::Unit::TestCase + def setup + cleanup + end + + def teardown + cleanup + end + + def cleanup + Bible.all.each do |bible| + bible.destroy + end + end + + def test_import_actual_file + parser = AsvParser.new(AsvStreamListener.new) + parser.parse File.open(File.dirname(__FILE__) + '/../data/asv-xsem.xml') + + bible_model = BibleModel.new 'ASV' + bible_model.long_name = 'American Standard Version' + bible_model.books = parser.books + + importer = DbImporter.new bible_model + importer.import_into_db + + assert_equal 1, Bible.all.size + asv_bible = Bible.all[0] + + # this is not right but it should show how many books in the failure message + assert_equal 3, asv_bible.books.size + end +end
caspian311/xsem-parser
0b72e7ffabf3474c3eeece5e60b78d1737134808
a small change in api
diff --git a/lib/asv_parser.rb b/lib/asv_parser.rb index 667e924..3347e6c 100644 --- a/lib/asv_parser.rb +++ b/lib/asv_parser.rb @@ -1,14 +1,14 @@ require 'rexml/document' class AsvParser attr_reader :books - def initialize - @stream_listener = AsvStreamListener.new + def initialize(stream_listener) + @stream_listener = stream_listener end def parse(file) REXML::Document.parse_stream(file, @stream_listener) @books = @stream_listener.books.values end end diff --git a/test/asv_parser_test.rb b/test/asv_parser_test.rb index b6419e5..844b689 100644 --- a/test/asv_parser_test.rb +++ b/test/asv_parser_test.rb @@ -1,42 +1,36 @@ require File.dirname(__FILE__) + "/test_helper" require "rexml/document" class AsvParserTest < Test::Unit::TestCase def test_parsing_test_file - parser = AsvParser.new + parser = AsvParser.new(AsvStreamListener.new) parser.parse File.open(File.dirname(__FILE__) + '/test.xml') parser.books.each do |book| if book.title == 'Genesis' check_genesis book elsif book.title == 'Matthew' check_matthew book else flunk 'unrecognized book' end end end - + def check_genesis(book) assert_equal('Genesis', book.title) - assert_equal(2, book.chapters.size) - assert_equal(2, book.chapters[0].verses.size) - assert_equal(2, book.chapters[1].verses.size) assert_equal('In the beginning God created the heavens and the earth.', book.chapters[0].verses[0].text) assert_equal('And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters.', book.chapters[0].verses[1].text) assert_equal('And the heavens and the earth were finished, and all the host of them.', book.chapters[1].verses[0].text) assert_equal('And on the seventh day God finished his work which he had made; and he rested on the seventh day from all his work which he had made.', book.chapters[1].verses[1].text) end def check_matthew(book) assert_equal('Matthew', book.title) - assert_equal(2, book.chapters.size) - assert_equal(2, book.chapters[0].verses.size) - assert_equal(2, book.chapters[1].verses.size) assert_equal('The book of the generation of Jesus Christ, the son of David, the son of Abraham.', book.chapters[0].verses[0].text) assert_equal('Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judah and his brethren;', book.chapters[0].verses[1].text) assert_equal('Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, Wise-men from the east came to Jerusalem, saying,', book.chapters[1].verses[0].text) end end
caspian311/xsem-parser
f793ccbd75b0d232f67232b1e8577f439140ca5a
don't need pools in this app
diff --git a/test/test_connection_info.rb b/test/test_connection_info.rb index 288f721..235fa76 100644 --- a/test/test_connection_info.rb +++ b/test/test_connection_info.rb @@ -1,10 +1,8 @@ require 'active_record' ActiveRecord::Base.establish_connection( :adapter => 'mysql', :database => 'bible_test', :host => '127.0.0.1', :username => 'root', - :password => 'root', - :pool => '5', - :timeout => '5000') \ No newline at end of file + :password => 'root')
caspian311/xsem-parser
171cc429fa0ac0ba1178533af58ddd556f8bbf7b
got the importer working for all the models
diff --git a/lib/bible.rb b/lib/bible.rb index e3edf4f..dfe0257 100644 --- a/lib/bible.rb +++ b/lib/bible.rb @@ -1,3 +1,5 @@ +require 'active_record' + class Bible<ActiveRecord::Base has_many :books, :dependent => :destroy end diff --git a/lib/bible_model.rb b/lib/bible_model.rb new file mode 100644 index 0000000..05a445e --- /dev/null +++ b/lib/bible_model.rb @@ -0,0 +1,11 @@ +class BibleModel + attr_accessor :short_name + attr_accessor :long_name + attr_accessor :publisher + attr_accessor :books + + def initialize(short_name) + @short_name = short_name + @books = [] + end +end diff --git a/lib/book_model.rb b/lib/book_model.rb index d19e26a..db14403 100644 --- a/lib/book_model.rb +++ b/lib/book_model.rb @@ -1,14 +1,14 @@ class BookModel attr_reader :title attr_reader :chapters def initialize(title) @title = title @chapters = [] end def add_chapter(chapter) - @chapters += [chapter] + @chapters << chapter end end diff --git a/lib/chapter.rb b/lib/chapter.rb index 95c288e..1264559 100644 --- a/lib/chapter.rb +++ b/lib/chapter.rb @@ -1,4 +1,6 @@ +require 'active_record' + class Chapter < ActiveRecord::Base belongs_to :book has_many :verses, :dependent => :destroy end diff --git a/lib/chapter_model.rb b/lib/chapter_model.rb index 7eb4baa..da1029c 100644 --- a/lib/chapter_model.rb +++ b/lib/chapter_model.rb @@ -1,13 +1,13 @@ class ChapterModel - attr_reader :id + attr_reader :reference attr_reader :verses - def initialize(id) - @id = id + def initialize(reference) + @reference = reference @verses = [] end def add_verse(verse) - @verses += [verse] + @verses << verse end end diff --git a/lib/db_importer.rb b/lib/db_importer.rb index 49b3288..b3830db 100644 --- a/lib/db_importer.rb +++ b/lib/db_importer.rb @@ -1,13 +1,31 @@ class DbImporter - def initialize(book_provider) - @book_provider = book_provider + def initialize(bible_model) + @bible_model = bible_model end def import_into_db - @book_provider.books.each do |book| + bible = Bible.new + bible.shortName = @bible_model.short_name + bible.longName = @bible_model.long_name + bible.publisher = @bible_model.publisher + + @bible_model.books.each do |book| b = Book.new b.title = book.title - b.save + bible.books << b + book.chapters.each do |chapter| + chap = Chapter.new + chap.reference = chapter.reference + b.chapters << chap + chapter.verses.each do |verse| + ver = Verse.new + ver.reference = verse.reference + ver.text = verse.text + chap.verses << ver + end + end end + + bible.save end end diff --git a/lib/verse.rb b/lib/verse.rb index 016b7ee..2069821 100644 --- a/lib/verse.rb +++ b/lib/verse.rb @@ -1,3 +1,5 @@ +require 'active_record' + class Verse < ActiveRecord::Base belongs_to :chapter, :dependent => :destroy end diff --git a/lib/verse_model.rb b/lib/verse_model.rb index 6f64fea..eb72361 100644 --- a/lib/verse_model.rb +++ b/lib/verse_model.rb @@ -1,9 +1,9 @@ class VerseModel - attr_reader :id + attr_reader :reference attr_accessor :text - def initialize(id) - @id = id + def initialize(reference) + @reference = reference end end diff --git a/test/book_model_test.rb b/test/book_model_test.rb index 9d0ddbc..50a22df 100644 --- a/test/book_model_test.rb +++ b/test/book_model_test.rb @@ -1,24 +1,24 @@ require File.dirname(__FILE__) + "/test_helper" class BookModelTest < Test::Unit::TestCase def test_book_title_is_set b = BookModel.new "sometext" assert_equal(b.title, "sometext") end def test_add_chapter c1 = ChapterModel.new 1 c2 = ChapterModel.new 2 c3 = ChapterModel.new 3 b = BookModel.new "sometext" b.add_chapter c1 b.add_chapter c2 b.add_chapter c3 assert_equal(3, b.chapters.size) - assert_equal(1, b.chapters[0].id) - assert_equal(2, b.chapters[1].id) - assert_equal(3, b.chapters[2].id) + assert_equal(1, b.chapters[0].reference) + assert_equal(2, b.chapters[1].reference) + assert_equal(3, b.chapters[2].reference) end end \ No newline at end of file diff --git a/test/chapter_model_test.rb b/test/chapter_model_test.rb index 67e6963..bbe3286 100644 --- a/test/chapter_model_test.rb +++ b/test/chapter_model_test.rb @@ -1,30 +1,30 @@ require File.dirname(__FILE__) + "/test_helper" class ChapterModelTest < Test::Unit::TestCase def test_chapter_is_set c1 = ChapterModel.new 1 c2 = ChapterModel.new 2 c3 = ChapterModel.new 999 - assert_equal(1, c1.id) - assert_equal(2, c2.id) - assert_equal(999, c3.id) + assert_equal(1, c1.reference) + assert_equal(2, c2.reference) + assert_equal(999, c3.reference) end def test_add_verse v1 = VerseModel.new 1 v2 = VerseModel.new 2 v3 = VerseModel.new 999 c1 = ChapterModel.new 1 c1.add_verse v1 c1.add_verse v2 c1.add_verse v3 assert_equal(3, c1.verses.size) - assert_equal(1, c1.verses[0].id) - assert_equal(2, c1.verses[1].id) - assert_equal(999, c1.verses[2].id) + assert_equal(1, c1.verses[0].reference) + assert_equal(2, c1.verses[1].reference) + assert_equal(999, c1.verses[2].reference) end end \ No newline at end of file diff --git a/test/db_importer_test.rb b/test/db_importer_test.rb index 224b339..bd731a1 100644 --- a/test/db_importer_test.rb +++ b/test/db_importer_test.rb @@ -1,44 +1,88 @@ require File.dirname(__FILE__) + "/test_helper" +require File.dirname(__FILE__) + "/../lib/bible_model" + class DbImporterTest < Test::Unit::TestCase def setup - Book.all.each do |book| - book.destroy + Bible.all.each do |bible| + bible.destroy end end def teardown - Book.all.each do |book| - book.destroy + Bible.all.each do |bible| + bible.destroy end end def test_import + bible1 = BibleModel.new 'ShortName' + bible1.long_name = 'This is the long name' + bible1.publisher = 'Bible Publishers Extrordinaire' + book1 = BookModel.new 'book 1' book2 = BookModel.new 'book 2' - book_provider = MockBookProvider.new - book_provider.books << book1 - book_provider.books << book2 + chap1 = ChapterModel.new 1 + chap2 = ChapterModel.new 2 + + verse1 = VerseModel.new 1 + verse1.text = 'this is verse 1' + + verse2 = VerseModel.new 2 + verse2.text = 'this is verse 2' + + chap1.verses << verse1 + chap1.verses << verse2 + + verse1 = VerseModel.new 1 + verse1.text = 'this is another verse 1' + + verse2 = VerseModel.new 2 + verse2.text = 'this is another verse 2' - importer = DbImporter.new book_provider + chap2.verses << verse1 + chap2.verses << verse2 + book1.chapters << chap1 + book1.chapters << chap2 + + chap1 = ChapterModel.new 3 + chap2 = ChapterModel.new 4 + + book2.chapters << chap1 + book2.chapters << chap2 + + bible1.books << book1 + bible1.books << book2 + + importer = DbImporter.new bible1 + + assert_equal 0, Bible.all.size assert_equal 0, Book.all.size + assert_equal 0, Chapter.all.size + assert_equal 0, Verse.all.size importer.import_into_db + assert_equal 1, Bible.all.size assert_equal 2, Book.all.size - + assert_equal 4, Chapter.all.size + assert_equal 4, Verse.all.size + + assert_equal 'ShortName', Bible.all[0].shortName + assert_equal 'Bible Publishers Extrordinaire', Bible.all[0].publisher + assert_equal 'This is the long name', Bible.all[0].longName assert_equal 'book 1', Book.all[0].title assert_equal 'book 2', Book.all[1].title end end class MockBookProvider attr_accessor :books def initialize @books = [] end end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 28e5377..1da600f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,12 +1,13 @@ $:.unshift File.join(File.dirname(__FILE__),'..','lib') +require File.dirname(__FILE__) + "/../lib/bible" require File.dirname(__FILE__) + "/../lib/book" require File.dirname(__FILE__) + "/../lib/chapter" require File.dirname(__FILE__) + "/../lib/verse" require File.dirname(__FILE__) + "/../lib/db_importer" require File.dirname(__FILE__) + "/../lib/asv_parser" require File.dirname(__FILE__) + "/../lib/asv_stream_listener" require File.dirname(__FILE__) + "/../lib/sql_builder" require "test/unit" require File.dirname(__FILE__) + "/../test/test_connection_info" diff --git a/test/verse_model_test.rb b/test/verse_model_test.rb index 8eebffc..7e4b1ab 100644 --- a/test/verse_model_test.rb +++ b/test/verse_model_test.rb @@ -1,20 +1,20 @@ require File.dirname(__FILE__) + "/test_helper" class VerseModelTest < Test::Unit::TestCase def test_initialize_with_id v1 = VerseModel.new 1 v2 = VerseModel.new 2 v3 = VerseModel.new 999 - assert_equal(1, v1.id) - assert_equal(2, v2.id) - assert_equal(999, v3.id) + assert_equal(1, v1.reference) + assert_equal(2, v2.reference) + assert_equal(999, v3.reference) end def test_set_text v1 = VerseModel.new 1 v1.text = "blah blah blah" assert_equal("blah blah blah", v1.text) end end \ No newline at end of file
caspian311/xsem-parser
e380144172c65e1f2af8e4a0ef44ec164766440d
added the other active record models
diff --git a/lib/bible.rb b/lib/bible.rb new file mode 100644 index 0000000..e3edf4f --- /dev/null +++ b/lib/bible.rb @@ -0,0 +1,3 @@ +class Bible<ActiveRecord::Base + has_many :books, :dependent => :destroy +end diff --git a/lib/book.rb b/lib/book.rb index 024d6bc..10f4666 100644 --- a/lib/book.rb +++ b/lib/book.rb @@ -1,4 +1,6 @@ require 'active_record' class Book < ActiveRecord::Base + has_many :chapters, :dependent => :destroy + belongs_to :bible end diff --git a/lib/chapter.rb b/lib/chapter.rb new file mode 100644 index 0000000..95c288e --- /dev/null +++ b/lib/chapter.rb @@ -0,0 +1,4 @@ +class Chapter < ActiveRecord::Base + belongs_to :book + has_many :verses, :dependent => :destroy +end diff --git a/lib/verse.rb b/lib/verse.rb new file mode 100644 index 0000000..016b7ee --- /dev/null +++ b/lib/verse.rb @@ -0,0 +1,3 @@ +class Verse < ActiveRecord::Base + belongs_to :chapter, :dependent => :destroy +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 8df6547..28e5377 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,10 +1,12 @@ $:.unshift File.join(File.dirname(__FILE__),'..','lib') require File.dirname(__FILE__) + "/../lib/book" +require File.dirname(__FILE__) + "/../lib/chapter" +require File.dirname(__FILE__) + "/../lib/verse" require File.dirname(__FILE__) + "/../lib/db_importer" require File.dirname(__FILE__) + "/../lib/asv_parser" require File.dirname(__FILE__) + "/../lib/asv_stream_listener" require File.dirname(__FILE__) + "/../lib/sql_builder" -require File.dirname(__FILE__) + "/../test/test_connection_info" -require "test/unit" \ No newline at end of file +require "test/unit" +require File.dirname(__FILE__) + "/../test/test_connection_info"
caspian311/xsem-parser
aa4ca4d6ad2c621540abcc084c51311b0acf9319
moved some stuff around
diff --git a/test/db_importer_test.rb b/test/db_importer_test.rb index 6b63636..224b339 100644 --- a/test/db_importer_test.rb +++ b/test/db_importer_test.rb @@ -1,48 +1,44 @@ require File.dirname(__FILE__) + "/test_helper" -require 'test/unit' -require 'db_importer' -require 'connection_info' - class DbImporterTest < Test::Unit::TestCase def setup Book.all.each do |book| book.destroy end end def teardown Book.all.each do |book| book.destroy end end def test_import book1 = BookModel.new 'book 1' book2 = BookModel.new 'book 2' book_provider = MockBookProvider.new book_provider.books << book1 book_provider.books << book2 importer = DbImporter.new book_provider assert_equal 0, Book.all.size importer.import_into_db assert_equal 2, Book.all.size assert_equal 'book 1', Book.all[0].title assert_equal 'book 2', Book.all[1].title end end class MockBookProvider attr_accessor :books def initialize @books = [] end end \ No newline at end of file diff --git a/lib/connection_info.rb b/test/test_connection_info.rb similarity index 77% rename from lib/connection_info.rb rename to test/test_connection_info.rb index b982abb..288f721 100644 --- a/lib/connection_info.rb +++ b/test/test_connection_info.rb @@ -1,10 +1,10 @@ require 'active_record' ActiveRecord::Base.establish_connection( :adapter => 'mysql', - :database => 'bible_dev', + :database => 'bible_test', :host => '127.0.0.1', :username => 'root', :password => 'root', :pool => '5', :timeout => '5000') \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index f4f84c0..8df6547 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,9 +1,10 @@ $:.unshift File.join(File.dirname(__FILE__),'..','lib') require File.dirname(__FILE__) + "/../lib/book" require File.dirname(__FILE__) + "/../lib/db_importer" require File.dirname(__FILE__) + "/../lib/asv_parser" require File.dirname(__FILE__) + "/../lib/asv_stream_listener" require File.dirname(__FILE__) + "/../lib/sql_builder" +require File.dirname(__FILE__) + "/../test/test_connection_info" require "test/unit" \ No newline at end of file
caspian311/xsem-parser
ba325a5a4bebfeccba00dcf40667f8a1f638f6a2
added activerecord mapping for books
diff --git a/lib/book.rb b/lib/book.rb new file mode 100644 index 0000000..024d6bc --- /dev/null +++ b/lib/book.rb @@ -0,0 +1,4 @@ +require 'active_record' + +class Book < ActiveRecord::Base +end diff --git a/lib/connection_info.rb b/lib/connection_info.rb new file mode 100644 index 0000000..b982abb --- /dev/null +++ b/lib/connection_info.rb @@ -0,0 +1,10 @@ +require 'active_record' + +ActiveRecord::Base.establish_connection( + :adapter => 'mysql', + :database => 'bible_dev', + :host => '127.0.0.1', + :username => 'root', + :password => 'root', + :pool => '5', + :timeout => '5000') \ No newline at end of file diff --git a/lib/db_importer.rb b/lib/db_importer.rb index 9ca6c4d..49b3288 100644 --- a/lib/db_importer.rb +++ b/lib/db_importer.rb @@ -1,9 +1,13 @@ class DbImporter def initialize(book_provider) - + @book_provider = book_provider end def import_into_db - + @book_provider.books.each do |book| + b = Book.new + b.title = book.title + b.save + end end end diff --git a/test/db_importer_test.rb b/test/db_importer_test.rb index 6b16bae..6b63636 100644 --- a/test/db_importer_test.rb +++ b/test/db_importer_test.rb @@ -1,17 +1,48 @@ require File.dirname(__FILE__) + "/test_helper" require 'test/unit' require 'db_importer' +require 'connection_info' class DbImporterTest < Test::Unit::TestCase + def setup + Book.all.each do |book| + book.destroy + end + end + + def teardown + Book.all.each do |book| + book.destroy + end + end + def test_import - book_provider = BookProvider.new + book1 = BookModel.new 'book 1' + book2 = BookModel.new 'book 2' + + book_provider = MockBookProvider.new + book_provider.books << book1 + book_provider.books << book2 importer = DbImporter.new book_provider + + assert_equal 0, Book.all.size + importer.import_into_db + + assert_equal 2, Book.all.size + + assert_equal 'book 1', Book.all[0].title + assert_equal 'book 2', Book.all[1].title end end -class BookProvider - +class MockBookProvider + attr_accessor :books + + def initialize + @books = [] + end + end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 9f429f8..f4f84c0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,8 +1,9 @@ $:.unshift File.join(File.dirname(__FILE__),'..','lib') +require File.dirname(__FILE__) + "/../lib/book" require File.dirname(__FILE__) + "/../lib/db_importer" require File.dirname(__FILE__) + "/../lib/asv_parser" require File.dirname(__FILE__) + "/../lib/asv_stream_listener" require File.dirname(__FILE__) + "/../lib/sql_builder" require "test/unit" \ No newline at end of file
caspian311/xsem-parser
3696313b6c2852422f28ef355b7c5fbf3a7bd199
renamed the book, chapter, verse classes to be models as activerecord's naming convention will have name conflicts
diff --git a/lib/asv_stream_listener.rb b/lib/asv_stream_listener.rb index a746a80..764b5ae 100644 --- a/lib/asv_stream_listener.rb +++ b/lib/asv_stream_listener.rb @@ -1,62 +1,62 @@ require 'rexml/streamlistener' -require "lib/book" -require "lib/chapter" -require "lib/verse" +require "lib/book_model" +require "lib/chapter_model" +require "lib/verse_model" class AsvStreamListener include REXML::StreamListener attr_reader :books def initialize @books = {} end def tag_start(name, attributes) if name == 'bookDecl' @book_id = attribute_val(attributes, 'id') elsif name == 'shortName' @in_book_title = true elsif name == 'book' @current_book = @books[attribute_val(attributes, 'value')] elsif name == 'chapter' - @current_chapter = Chapter.new attribute_val(attributes, 'value') + @current_chapter = ChapterModel.new attribute_val(attributes, 'value') @current_book.add_chapter @current_chapter elsif name == 'verse' - @current_verse = Verse.new attribute_val(attributes, 'value') + @current_verse = VerseModel.new attribute_val(attributes, 'value') @current_chapter.add_verse @current_verse @in_verse = true elsif name == 'verseEnd' @in_verse = false end end def tag_end(name) if name == 'bookDecl' - @books[@book_id] = Book.new @book_title + @books[@book_id] = BookModel.new @book_title end end def text(text) if @in_book_title @book_title = text.strip @in_book_title = false elsif @in_verse @current_verse.text = text.strip end end private def attribute_val(attributes, key) value = nil attributes.each do |attribute_pair| if attribute_pair[0] == key value = attribute_pair[1] break end end return value end end diff --git a/lib/book.rb b/lib/book_model.rb similarity index 84% rename from lib/book.rb rename to lib/book_model.rb index e15aee6..d19e26a 100644 --- a/lib/book.rb +++ b/lib/book_model.rb @@ -1,14 +1,14 @@ -class Book +class BookModel attr_reader :title attr_reader :chapters def initialize(title) @title = title @chapters = [] end def add_chapter(chapter) @chapters += [chapter] end end diff --git a/lib/chapter.rb b/lib/chapter_model.rb similarity index 81% rename from lib/chapter.rb rename to lib/chapter_model.rb index 5be264f..7eb4baa 100644 --- a/lib/chapter.rb +++ b/lib/chapter_model.rb @@ -1,13 +1,13 @@ -class Chapter +class ChapterModel attr_reader :id attr_reader :verses def initialize(id) @id = id @verses = [] end def add_verse(verse) @verses += [verse] end end diff --git a/lib/db_importer.rb b/lib/db_importer.rb new file mode 100644 index 0000000..9ca6c4d --- /dev/null +++ b/lib/db_importer.rb @@ -0,0 +1,9 @@ +class DbImporter + def initialize(book_provider) + + end + + def import_into_db + + end +end diff --git a/lib/sql_builder.rb b/lib/sql_builder.rb index bf9c19d..3c5d44e 100644 --- a/lib/sql_builder.rb +++ b/lib/sql_builder.rb @@ -1,27 +1,24 @@ -# To change this template, choose Tools | Templates -# and open the template in the editor. - class SqlBuilder def initialize(books) @books = books end def generate_sql generated_sql = [] @books.each do |book| book.chapters.each do |chapter| chapter.verses.each do |verse| sql = create_insert_statement(book, chapter, verse) generated_sql << sql end end end return generated_sql end private def create_insert_statement(book, chapter, verse) return 'create this...' end end diff --git a/lib/verse.rb b/lib/verse_model.rb similarity index 75% rename from lib/verse.rb rename to lib/verse_model.rb index 283b6fd..6f64fea 100644 --- a/lib/verse.rb +++ b/lib/verse_model.rb @@ -1,9 +1,9 @@ -class Verse +class VerseModel attr_reader :id attr_accessor :text def initialize(id) @id = id end end diff --git a/test/book_test.rb b/test/book_model_test.rb similarity index 62% rename from test/book_test.rb rename to test/book_model_test.rb index 1c292d4..9d0ddbc 100644 --- a/test/book_test.rb +++ b/test/book_model_test.rb @@ -1,24 +1,24 @@ require File.dirname(__FILE__) + "/test_helper" -class BookTest < Test::Unit::TestCase +class BookModelTest < Test::Unit::TestCase def test_book_title_is_set - b = Book.new "sometext" + b = BookModel.new "sometext" assert_equal(b.title, "sometext") end def test_add_chapter - c1 = Chapter.new 1 - c2 = Chapter.new 2 - c3 = Chapter.new 3 + c1 = ChapterModel.new 1 + c2 = ChapterModel.new 2 + c3 = ChapterModel.new 3 - b = Book.new "sometext" + b = BookModel.new "sometext" b.add_chapter c1 b.add_chapter c2 b.add_chapter c3 assert_equal(3, b.chapters.size) assert_equal(1, b.chapters[0].id) assert_equal(2, b.chapters[1].id) assert_equal(3, b.chapters[2].id) end end \ No newline at end of file diff --git a/test/chapter_test.rb b/test/chapter_model_test.rb similarity index 59% rename from test/chapter_test.rb rename to test/chapter_model_test.rb index 38969a6..67e6963 100644 --- a/test/chapter_test.rb +++ b/test/chapter_model_test.rb @@ -1,30 +1,30 @@ require File.dirname(__FILE__) + "/test_helper" -class ChapterTest < Test::Unit::TestCase +class ChapterModelTest < Test::Unit::TestCase def test_chapter_is_set - c1 = Chapter.new 1 - c2 = Chapter.new 2 - c3 = Chapter.new 999 + c1 = ChapterModel.new 1 + c2 = ChapterModel.new 2 + c3 = ChapterModel.new 999 assert_equal(1, c1.id) assert_equal(2, c2.id) assert_equal(999, c3.id) end def test_add_verse - v1 = Verse.new 1 - v2 = Verse.new 2 - v3 = Verse.new 999 - c1 = Chapter.new 1 + v1 = VerseModel.new 1 + v2 = VerseModel.new 2 + v3 = VerseModel.new 999 + c1 = ChapterModel.new 1 c1.add_verse v1 c1.add_verse v2 c1.add_verse v3 assert_equal(3, c1.verses.size) assert_equal(1, c1.verses[0].id) assert_equal(2, c1.verses[1].id) assert_equal(999, c1.verses[2].id) end end \ No newline at end of file diff --git a/test/db_importer_test.rb b/test/db_importer_test.rb new file mode 100644 index 0000000..6b16bae --- /dev/null +++ b/test/db_importer_test.rb @@ -0,0 +1,17 @@ +require File.dirname(__FILE__) + "/test_helper" + +require 'test/unit' +require 'db_importer' + +class DbImporterTest < Test::Unit::TestCase + def test_import + book_provider = BookProvider.new + + importer = DbImporter.new book_provider + importer.import_into_db + end +end + +class BookProvider + +end \ No newline at end of file diff --git a/test/sql_builder_test.rb b/test/sql_builder_test.rb index 8209f94..a1feced 100644 --- a/test/sql_builder_test.rb +++ b/test/sql_builder_test.rb @@ -1,47 +1,47 @@ require File.dirname(__FILE__) + "/test_helper" class SqlBuilderTest < Test::Unit::TestCase def setup - v1_1_1 = Verse.new 1 - v1_1_2 = Verse.new 2 - v1_2_1 = Verse.new 1 - v1_2_2 = Verse.new 2 + v1_1_1 = VerseModel.new 1 + v1_1_2 = VerseModel.new 2 + v1_2_1 = VerseModel.new 1 + v1_2_2 = VerseModel.new 2 - ch1_1 = Chapter.new 1 - ch1_2 = Chapter.new 2 + ch1_1 = ChapterModel.new 1 + ch1_2 = ChapterModel.new 2 ch1_1.add_verse(v1_1_1) ch1_1.add_verse(v1_1_2) ch1_2.add_verse(v1_2_1) ch1_2.add_verse(v1_2_2) - book1 = Book.new 'First Book' + book1 = BookModel.new 'First Book' book1.add_chapter(ch1_1) book1.add_chapter(ch1_2) - v2_1_1 = Verse.new 1 - v2_1_2 = Verse.new 2 - v2_2_1 = Verse.new 1 - v2_2_2 = Verse.new 2 + v2_1_1 = VerseModel.new 1 + v2_1_2 = VerseModel.new 2 + v2_2_1 = VerseModel.new 1 + v2_2_2 = VerseModel.new 2 - ch2_1 = Chapter.new 1 - ch2_2 = Chapter.new 2 + ch2_1 = ChapterModel.new 1 + ch2_2 = ChapterModel.new 2 ch2_1.add_verse(v2_1_1) ch2_1.add_verse(v2_1_2) ch2_2.add_verse(v2_2_1) ch2_2.add_verse(v2_2_2) - book2 = Book.new 'Second Book' + book2 = BookModel.new 'Second Book' book2.add_chapter(ch1_1) book2.add_chapter(ch1_2) @books = [book1, book2] end def test_generate_sql builder = SqlBuilder.new @books lines = builder.generate_sql assert_equal(8, lines.size) end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 6c1e6a6..9f429f8 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,7 +1,8 @@ $:.unshift File.join(File.dirname(__FILE__),'..','lib') +require File.dirname(__FILE__) + "/../lib/db_importer" require File.dirname(__FILE__) + "/../lib/asv_parser" require File.dirname(__FILE__) + "/../lib/asv_stream_listener" require File.dirname(__FILE__) + "/../lib/sql_builder" require "test/unit" \ No newline at end of file diff --git a/test/verse_test.rb b/test/verse_model_test.rb similarity index 61% rename from test/verse_test.rb rename to test/verse_model_test.rb index f117fa2..8eebffc 100644 --- a/test/verse_test.rb +++ b/test/verse_model_test.rb @@ -1,20 +1,20 @@ require File.dirname(__FILE__) + "/test_helper" -class VerseTest < Test::Unit::TestCase +class VerseModelTest < Test::Unit::TestCase def test_initialize_with_id - v1 = Verse.new 1 - v2 = Verse.new 2 - v3 = Verse.new 999 + v1 = VerseModel.new 1 + v2 = VerseModel.new 2 + v3 = VerseModel.new 999 assert_equal(1, v1.id) assert_equal(2, v2.id) assert_equal(999, v3.id) end def test_set_text - v1 = Verse.new 1 + v1 = VerseModel.new 1 v1.text = "blah blah blah" assert_equal("blah blah blah", v1.text) end end \ No newline at end of file
caspian311/xsem-parser
5b1d2986c61cdc354ff717deaebeab9f0b1fc765
minor refactoring...
diff --git a/lib/asv_parser.rb b/lib/asv_parser.rb index 1294b95..667e924 100644 --- a/lib/asv_parser.rb +++ b/lib/asv_parser.rb @@ -1,12 +1,14 @@ require 'rexml/document' class AsvParser attr_reader :books - def initialize(file) - stream_listener = AsvStreamListener.new - REXML::Document.parse_stream(file, stream_listener) + def initialize + @stream_listener = AsvStreamListener.new + end - @books = stream_listener.books.values + def parse(file) + REXML::Document.parse_stream(file, @stream_listener) + @books = @stream_listener.books.values end end diff --git a/run.rb b/run.rb index b703062..ffcd389 100644 --- a/run.rb +++ b/run.rb @@ -1,8 +1,9 @@ -require 'REXML/document' -require 'app/stream_parser' +require "lib/sql_builder" +require "lib/asv_parser" +require "lib/asv_stream_listener" -include REXML - -parser = StreamParser.new -Document.parse_stream(File.open('data/asv-xsem.xml'), parser) -parser.print \ No newline at end of file +parser = AsvParser.new "data/asv-xsem.xml" +sql_builder = SqlBuilder.new parser.books +sql_builder.generate_sql.each do |statement| + puts statement +end diff --git a/test/asv_parser_test.rb b/test/asv_parser_test.rb index 0adb680..b6419e5 100644 --- a/test/asv_parser_test.rb +++ b/test/asv_parser_test.rb @@ -1,41 +1,42 @@ require File.dirname(__FILE__) + "/test_helper" require "rexml/document" class AsvParserTest < Test::Unit::TestCase def test_parsing_test_file - parser = AsvParser.new File.open(File.dirname(__FILE__) + '/test.xml') + parser = AsvParser.new + parser.parse File.open(File.dirname(__FILE__) + '/test.xml') parser.books.each do |book| if book.title == 'Genesis' check_genesis book elsif book.title == 'Matthew' check_matthew book else flunk 'unrecognized book' end end end def check_genesis(book) assert_equal('Genesis', book.title) assert_equal(2, book.chapters.size) assert_equal(2, book.chapters[0].verses.size) assert_equal(2, book.chapters[1].verses.size) assert_equal('In the beginning God created the heavens and the earth.', book.chapters[0].verses[0].text) assert_equal('And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters.', book.chapters[0].verses[1].text) assert_equal('And the heavens and the earth were finished, and all the host of them.', book.chapters[1].verses[0].text) assert_equal('And on the seventh day God finished his work which he had made; and he rested on the seventh day from all his work which he had made.', book.chapters[1].verses[1].text) end def check_matthew(book) assert_equal('Matthew', book.title) assert_equal(2, book.chapters.size) assert_equal(2, book.chapters[0].verses.size) assert_equal(2, book.chapters[1].verses.size) assert_equal('The book of the generation of Jesus Christ, the son of David, the son of Abraham.', book.chapters[0].verses[0].text) assert_equal('Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judah and his brethren;', book.chapters[0].verses[1].text) assert_equal('Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, Wise-men from the east came to Jerusalem, saying,', book.chapters[1].verses[0].text) end end
caspian311/xsem-parser
ddeb9673f69a2a9a73a823b2220c35c3728b68eb
made private methods private
diff --git a/lib/sql_builder.rb b/lib/sql_builder.rb index f18dcff..bf9c19d 100644 --- a/lib/sql_builder.rb +++ b/lib/sql_builder.rb @@ -1,25 +1,27 @@ # To change this template, choose Tools | Templates # and open the template in the editor. class SqlBuilder def initialize(books) @books = books end def generate_sql generated_sql = [] @books.each do |book| book.chapters.each do |chapter| chapter.verses.each do |verse| sql = create_insert_statement(book, chapter, verse) generated_sql << sql end end end return generated_sql end + private + def create_insert_statement(book, chapter, verse) - '' + return 'create this...' end end
caspian311/xsem-parser
de8d6a16c98e578832fda1689a48daaf18d49209
created a sql builder to create the sql that will be inserted into the db
diff --git a/lib/sql_builder.rb b/lib/sql_builder.rb new file mode 100644 index 0000000..f18dcff --- /dev/null +++ b/lib/sql_builder.rb @@ -0,0 +1,25 @@ +# To change this template, choose Tools | Templates +# and open the template in the editor. + +class SqlBuilder + def initialize(books) + @books = books + end + + def generate_sql + generated_sql = [] + @books.each do |book| + book.chapters.each do |chapter| + chapter.verses.each do |verse| + sql = create_insert_statement(book, chapter, verse) + generated_sql << sql + end + end + end + return generated_sql + end + + def create_insert_statement(book, chapter, verse) + '' + end +end diff --git a/test/sql_builder_test.rb b/test/sql_builder_test.rb new file mode 100644 index 0000000..8209f94 --- /dev/null +++ b/test/sql_builder_test.rb @@ -0,0 +1,47 @@ +require File.dirname(__FILE__) + "/test_helper" + +class SqlBuilderTest < Test::Unit::TestCase + def setup + v1_1_1 = Verse.new 1 + v1_1_2 = Verse.new 2 + v1_2_1 = Verse.new 1 + v1_2_2 = Verse.new 2 + + ch1_1 = Chapter.new 1 + ch1_2 = Chapter.new 2 + + ch1_1.add_verse(v1_1_1) + ch1_1.add_verse(v1_1_2) + ch1_2.add_verse(v1_2_1) + ch1_2.add_verse(v1_2_2) + + book1 = Book.new 'First Book' + book1.add_chapter(ch1_1) + book1.add_chapter(ch1_2) + + v2_1_1 = Verse.new 1 + v2_1_2 = Verse.new 2 + v2_2_1 = Verse.new 1 + v2_2_2 = Verse.new 2 + + ch2_1 = Chapter.new 1 + ch2_2 = Chapter.new 2 + + ch2_1.add_verse(v2_1_1) + ch2_1.add_verse(v2_1_2) + ch2_2.add_verse(v2_2_1) + ch2_2.add_verse(v2_2_2) + + book2 = Book.new 'Second Book' + book2.add_chapter(ch1_1) + book2.add_chapter(ch1_2) + + @books = [book1, book2] + end + + def test_generate_sql + builder = SqlBuilder.new @books + lines = builder.generate_sql + assert_equal(8, lines.size) + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 9c368c3..6c1e6a6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,6 +1,7 @@ $:.unshift File.join(File.dirname(__FILE__),'..','lib') require File.dirname(__FILE__) + "/../lib/asv_parser" require File.dirname(__FILE__) + "/../lib/asv_stream_listener" +require File.dirname(__FILE__) + "/../lib/sql_builder" require "test/unit" \ No newline at end of file
caspian311/xsem-parser
d8779369bbdb23b059e2a1538c81b4a2d91f847a
minor changes to the includes
diff --git a/lib/asv_parser.rb b/lib/asv_parser.rb index e836b7b..1294b95 100644 --- a/lib/asv_parser.rb +++ b/lib/asv_parser.rb @@ -1,16 +1,12 @@ require 'rexml/document' -require "lib/book" - -include REXML - class AsvParser attr_reader :books def initialize(file) stream_listener = AsvStreamListener.new REXML::Document.parse_stream(file, stream_listener) @books = stream_listener.books.values end end diff --git a/lib/asv_stream_listener.rb b/lib/asv_stream_listener.rb index fbce49c..a746a80 100644 --- a/lib/asv_stream_listener.rb +++ b/lib/asv_stream_listener.rb @@ -1,62 +1,62 @@ require 'rexml/streamlistener' require "lib/book" require "lib/chapter" require "lib/verse" class AsvStreamListener - include StreamListener + include REXML::StreamListener attr_reader :books def initialize @books = {} end def tag_start(name, attributes) if name == 'bookDecl' @book_id = attribute_val(attributes, 'id') elsif name == 'shortName' @in_book_title = true elsif name == 'book' @current_book = @books[attribute_val(attributes, 'value')] elsif name == 'chapter' @current_chapter = Chapter.new attribute_val(attributes, 'value') @current_book.add_chapter @current_chapter elsif name == 'verse' @current_verse = Verse.new attribute_val(attributes, 'value') @current_chapter.add_verse @current_verse @in_verse = true elsif name == 'verseEnd' @in_verse = false end end def tag_end(name) if name == 'bookDecl' @books[@book_id] = Book.new @book_title end end def text(text) if @in_book_title @book_title = text.strip @in_book_title = false elsif @in_verse @current_verse.text = text.strip end end private def attribute_val(attributes, key) value = nil attributes.each do |attribute_pair| if attribute_pair[0] == key value = attribute_pair[1] break end end return value end end
caspian311/xsem-parser
0780c013925930b3e3978d01fbdb148b1f16c7fb
pulled the stream listener out from the parser
diff --git a/lib/asv_parser.rb b/lib/asv_parser.rb index 12f6761..e836b7b 100644 --- a/lib/asv_parser.rb +++ b/lib/asv_parser.rb @@ -1,68 +1,16 @@ require 'rexml/document' -require 'rexml/streamlistener' require "lib/book" -require "lib/chapter" -require "lib/verse" include REXML class AsvParser - include StreamListener + attr_reader :books - def initialize(file) - @books = {} - REXML::Document.parse_stream(file, self) - end + def initialize(file) + stream_listener = AsvStreamListener.new + REXML::Document.parse_stream(file, stream_listener) - def all_books - @books.values + @books = stream_listener.books.values end - - def tag_start(name, attributes) - if name == 'bookDecl' - @book_id = attribute_val(attributes, 'id') - elsif name == 'shortName' - @in_book_title = true - elsif name == 'book' - @current_book = @books[attribute_val(attributes, 'value')] - elsif name == 'chapter' - @current_chapter = Chapter.new attribute_val(attributes, 'value') - @current_book.add_chapter @current_chapter - elsif name == 'verse' - @current_verse = Verse.new attribute_val(attributes, 'value') - @current_chapter.add_verse @current_verse - @in_verse = true - elsif name == 'verseEnd' - @in_verse = false - end - end - - def tag_end(name) - if name == 'bookDecl' - @books[@book_id] = Book.new @book_title - end - end - - def text(text) - if @in_book_title - @book_title = text.strip - @in_book_title = false - elsif @in_verse - @current_verse.text = text.strip - end - end - - private - - def attribute_val(attributes, key) - value = nil - attributes.each do |attribute_pair| - if attribute_pair[0] == key - value = attribute_pair[1] - break - end - end - return value - end end diff --git a/lib/asv_stream_listener.rb b/lib/asv_stream_listener.rb new file mode 100644 index 0000000..fbce49c --- /dev/null +++ b/lib/asv_stream_listener.rb @@ -0,0 +1,62 @@ +require 'rexml/streamlistener' + +require "lib/book" +require "lib/chapter" +require "lib/verse" + +class AsvStreamListener + include StreamListener + + attr_reader :books + + def initialize + @books = {} + end + + def tag_start(name, attributes) + if name == 'bookDecl' + @book_id = attribute_val(attributes, 'id') + elsif name == 'shortName' + @in_book_title = true + elsif name == 'book' + @current_book = @books[attribute_val(attributes, 'value')] + elsif name == 'chapter' + @current_chapter = Chapter.new attribute_val(attributes, 'value') + @current_book.add_chapter @current_chapter + elsif name == 'verse' + @current_verse = Verse.new attribute_val(attributes, 'value') + @current_chapter.add_verse @current_verse + @in_verse = true + elsif name == 'verseEnd' + @in_verse = false + end + end + + def tag_end(name) + if name == 'bookDecl' + @books[@book_id] = Book.new @book_title + end + end + + def text(text) + if @in_book_title + @book_title = text.strip + @in_book_title = false + elsif @in_verse + @current_verse.text = text.strip + end + end + + private + + def attribute_val(attributes, key) + value = nil + attributes.each do |attribute_pair| + if attribute_pair[0] == key + value = attribute_pair[1] + break + end + end + return value + end +end diff --git a/test/asv_parser_test.rb b/test/asv_parser_test.rb index b20e947..0adb680 100644 --- a/test/asv_parser_test.rb +++ b/test/asv_parser_test.rb @@ -1,41 +1,41 @@ require File.dirname(__FILE__) + "/test_helper" require "rexml/document" class AsvParserTest < Test::Unit::TestCase def test_parsing_test_file parser = AsvParser.new File.open(File.dirname(__FILE__) + '/test.xml') - parser.all_books.each do |book| + parser.books.each do |book| if book.title == 'Genesis' check_genesis book elsif book.title == 'Matthew' check_matthew book else flunk 'unrecognized book' end end end def check_genesis(book) assert_equal('Genesis', book.title) assert_equal(2, book.chapters.size) assert_equal(2, book.chapters[0].verses.size) assert_equal(2, book.chapters[1].verses.size) assert_equal('In the beginning God created the heavens and the earth.', book.chapters[0].verses[0].text) assert_equal('And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters.', book.chapters[0].verses[1].text) assert_equal('And the heavens and the earth were finished, and all the host of them.', book.chapters[1].verses[0].text) assert_equal('And on the seventh day God finished his work which he had made; and he rested on the seventh day from all his work which he had made.', book.chapters[1].verses[1].text) end def check_matthew(book) assert_equal('Matthew', book.title) assert_equal(2, book.chapters.size) assert_equal(2, book.chapters[0].verses.size) assert_equal(2, book.chapters[1].verses.size) assert_equal('The book of the generation of Jesus Christ, the son of David, the son of Abraham.', book.chapters[0].verses[0].text) assert_equal('Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judah and his brethren;', book.chapters[0].verses[1].text) assert_equal('Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, Wise-men from the east came to Jerusalem, saying,', book.chapters[1].verses[0].text) end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 6050467..9c368c3 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,5 +1,6 @@ $:.unshift File.join(File.dirname(__FILE__),'..','lib') require File.dirname(__FILE__) + "/../lib/asv_parser" +require File.dirname(__FILE__) + "/../lib/asv_stream_listener" require "test/unit" \ No newline at end of file
caspian311/xsem-parser
c71c6b92430df8a7fadf287225aefcb71e910f6c
changed the api on the parser a bit
diff --git a/lib/asv_parser.rb b/lib/asv_parser.rb index 512f466..12f6761 100644 --- a/lib/asv_parser.rb +++ b/lib/asv_parser.rb @@ -1,80 +1,68 @@ require 'rexml/document' require 'rexml/streamlistener' require "lib/book" require "lib/chapter" require "lib/verse" include REXML class AsvParser include StreamListener - attr_reader :books - - def initialize + def initialize(file) @books = {} + REXML::Document.parse_stream(file, self) end - + + def all_books + @books.values + end + def tag_start(name, attributes) if name == 'bookDecl' @book_id = attribute_val(attributes, 'id') elsif name == 'shortName' @in_book_title = true elsif name == 'book' - @current_book = books[attribute_val(attributes, 'value')] + @current_book = @books[attribute_val(attributes, 'value')] elsif name == 'chapter' @current_chapter = Chapter.new attribute_val(attributes, 'value') @current_book.add_chapter @current_chapter elsif name == 'verse' @current_verse = Verse.new attribute_val(attributes, 'value') @current_chapter.add_verse @current_verse @in_verse = true elsif name == 'verseEnd' @in_verse = false end end def tag_end(name) if name == 'bookDecl' @books[@book_id] = Book.new @book_title end end def text(text) if @in_book_title @book_title = text.strip @in_book_title = false elsif @in_verse @current_verse.text = text.strip end end - def print - puts "list of books..." - @books.each_value do |book| - puts "book: #{book.title}" - book.chapters.each do |chapter| - puts " chapter: #{chapter.id}" - chapter.verses.each do |verse| - puts " verse: #{verse.id}" - puts " text: #{verse.text}" - end - end - end - end - - - private + private def attribute_val(attributes, key) value = nil attributes.each do |attribute_pair| if attribute_pair[0] == key value = attribute_pair[1] break end end return value end end diff --git a/test/asv_parser_test.rb b/test/asv_parser_test.rb index 4d4552b..b20e947 100644 --- a/test/asv_parser_test.rb +++ b/test/asv_parser_test.rb @@ -1,32 +1,41 @@ require File.dirname(__FILE__) + "/test_helper" require "rexml/document" class AsvParserTest < Test::Unit::TestCase def test_parsing_test_file - parser = AsvParser.new - REXML::Document.parse_stream(File.open('test/test.xml'), parser) + parser = AsvParser.new File.open(File.dirname(__FILE__) + '/test.xml') - genesis = parser.books['GEN'] - matthew = parser.books['MAT'] + parser.all_books.each do |book| + if book.title == 'Genesis' + check_genesis book + elsif book.title == 'Matthew' + check_matthew book + else + flunk 'unrecognized book' + end + end + end + + def check_genesis(book) + assert_equal('Genesis', book.title) + assert_equal(2, book.chapters.size) + assert_equal(2, book.chapters[0].verses.size) + assert_equal(2, book.chapters[1].verses.size) + assert_equal('In the beginning God created the heavens and the earth.', book.chapters[0].verses[0].text) + assert_equal('And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters.', book.chapters[0].verses[1].text) + assert_equal('And the heavens and the earth were finished, and all the host of them.', book.chapters[1].verses[0].text) + assert_equal('And on the seventh day God finished his work which he had made; and he rested on the seventh day from all his work which he had made.', book.chapters[1].verses[1].text) + end - assert_equal('Genesis', genesis.title) - assert_equal(2, genesis.chapters.size) - assert_equal(2, genesis.chapters[0].verses.size) - assert_equal(2, genesis.chapters[1].verses.size) - assert_equal('In the beginning God created the heavens and the earth.', genesis.chapters[0].verses[0].text) - assert_equal('And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters.', genesis.chapters[0].verses[1].text) - assert_equal('And the heavens and the earth were finished, and all the host of them.', genesis.chapters[1].verses[0].text) - assert_equal('And on the seventh day God finished his work which he had made; and he rested on the seventh day from all his work which he had made.', genesis.chapters[1].verses[1].text) - - assert_equal('Matthew', matthew.title) - assert_equal(2, matthew.chapters.size) - assert_equal(2, matthew.chapters[0].verses.size) - assert_equal(2, matthew.chapters[1].verses.size) - assert_equal('The book of the generation of Jesus Christ, the son of David, the son of Abraham.', matthew.chapters[0].verses[0].text) - assert_equal('Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judah and his brethren;', matthew.chapters[0].verses[1].text) - assert_equal('Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, Wise-men from the east came to Jerusalem, saying,', matthew.chapters[1].verses[0].text) - - end + def check_matthew(book) + assert_equal('Matthew', book.title) + assert_equal(2, book.chapters.size) + assert_equal(2, book.chapters[0].verses.size) + assert_equal(2, book.chapters[1].verses.size) + assert_equal('The book of the generation of Jesus Christ, the son of David, the son of Abraham.', book.chapters[0].verses[0].text) + assert_equal('Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judah and his brethren;', book.chapters[0].verses[1].text) + assert_equal('Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, Wise-men from the east came to Jerusalem, saying,', book.chapters[1].verses[0].text) + end end
caspian311/xsem-parser
2f00ab154c3c3f773682bab58eff2e77c115f0f6
stupid require crap
diff --git a/test/test_helper.rb b/test/test_helper.rb index c6fd3ea..6050467 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,8 +1,5 @@ -#$:.unshift File.join(File.dirname(__FILE__),'..','lib') +$:.unshift File.join(File.dirname(__FILE__),'..','lib') -require "lib/book" -require "lib/chapter" -require "lib/verse" -require "lib/asv_parser" +require File.dirname(__FILE__) + "/../lib/asv_parser" require "test/unit" \ No newline at end of file
caspian311/xsem-parser
d6e4395871a88092829829ed3da3e27322be3228
renamed test helper
diff --git a/test/asv_parser_test.rb b/test/asv_parser_test.rb index 7b6b468..4d4552b 100644 --- a/test/asv_parser_test.rb +++ b/test/asv_parser_test.rb @@ -1,32 +1,32 @@ -require File.dirname(__FILE__) + "/testhelper" +require File.dirname(__FILE__) + "/test_helper" require "rexml/document" class AsvParserTest < Test::Unit::TestCase def test_parsing_test_file parser = AsvParser.new REXML::Document.parse_stream(File.open('test/test.xml'), parser) genesis = parser.books['GEN'] matthew = parser.books['MAT'] assert_equal('Genesis', genesis.title) assert_equal(2, genesis.chapters.size) assert_equal(2, genesis.chapters[0].verses.size) assert_equal(2, genesis.chapters[1].verses.size) assert_equal('In the beginning God created the heavens and the earth.', genesis.chapters[0].verses[0].text) assert_equal('And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters.', genesis.chapters[0].verses[1].text) assert_equal('And the heavens and the earth were finished, and all the host of them.', genesis.chapters[1].verses[0].text) assert_equal('And on the seventh day God finished his work which he had made; and he rested on the seventh day from all his work which he had made.', genesis.chapters[1].verses[1].text) assert_equal('Matthew', matthew.title) assert_equal(2, matthew.chapters.size) assert_equal(2, matthew.chapters[0].verses.size) assert_equal(2, matthew.chapters[1].verses.size) assert_equal('The book of the generation of Jesus Christ, the son of David, the son of Abraham.', matthew.chapters[0].verses[0].text) assert_equal('Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judah and his brethren;', matthew.chapters[0].verses[1].text) assert_equal('Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, Wise-men from the east came to Jerusalem, saying,', matthew.chapters[1].verses[0].text) end end diff --git a/test/book_test.rb b/test/book_test.rb index 68c0ccb..1c292d4 100644 --- a/test/book_test.rb +++ b/test/book_test.rb @@ -1,24 +1,24 @@ -require File.dirname(__FILE__) + "/testhelper" +require File.dirname(__FILE__) + "/test_helper" class BookTest < Test::Unit::TestCase def test_book_title_is_set b = Book.new "sometext" assert_equal(b.title, "sometext") end def test_add_chapter c1 = Chapter.new 1 c2 = Chapter.new 2 c3 = Chapter.new 3 b = Book.new "sometext" b.add_chapter c1 b.add_chapter c2 b.add_chapter c3 assert_equal(3, b.chapters.size) assert_equal(1, b.chapters[0].id) assert_equal(2, b.chapters[1].id) assert_equal(3, b.chapters[2].id) end end \ No newline at end of file diff --git a/test/chapter_test.rb b/test/chapter_test.rb index a5659ad..38969a6 100644 --- a/test/chapter_test.rb +++ b/test/chapter_test.rb @@ -1,30 +1,30 @@ -require File.dirname(__FILE__) + "/testhelper" +require File.dirname(__FILE__) + "/test_helper" class ChapterTest < Test::Unit::TestCase def test_chapter_is_set c1 = Chapter.new 1 c2 = Chapter.new 2 c3 = Chapter.new 999 assert_equal(1, c1.id) assert_equal(2, c2.id) assert_equal(999, c3.id) end def test_add_verse v1 = Verse.new 1 v2 = Verse.new 2 v3 = Verse.new 999 c1 = Chapter.new 1 c1.add_verse v1 c1.add_verse v2 c1.add_verse v3 assert_equal(3, c1.verses.size) assert_equal(1, c1.verses[0].id) assert_equal(2, c1.verses[1].id) assert_equal(999, c1.verses[2].id) end end \ No newline at end of file diff --git a/test/testhelper.rb b/test/test_helper.rb similarity index 100% rename from test/testhelper.rb rename to test/test_helper.rb diff --git a/test/verse_test.rb b/test/verse_test.rb index a167d69..f117fa2 100644 --- a/test/verse_test.rb +++ b/test/verse_test.rb @@ -1,20 +1,20 @@ -require File.dirname(__FILE__) + "/testhelper" +require File.dirname(__FILE__) + "/test_helper" class VerseTest < Test::Unit::TestCase def test_initialize_with_id v1 = Verse.new 1 v2 = Verse.new 2 v3 = Verse.new 999 assert_equal(1, v1.id) assert_equal(2, v2.id) assert_equal(999, v3.id) end def test_set_text v1 = Verse.new 1 v1.text = "blah blah blah" assert_equal("blah blah blah", v1.text) end end \ No newline at end of file
caspian311/xsem-parser
0bb75a759c8b81c4ec88361a1b870d8374340fbb
still messing with the stupid require
diff --git a/test/asv_parser_test.rb b/test/asv_parser_test.rb index 6e0d548..7b6b468 100644 --- a/test/asv_parser_test.rb +++ b/test/asv_parser_test.rb @@ -1,35 +1,32 @@ -$:.unshift File.join(File.dirname(__FILE__),'..','lib') +require File.dirname(__FILE__) + "/testhelper" require "rexml/document" -require "test/unit" - -require "lib/asv_parser" class AsvParserTest < Test::Unit::TestCase - def test_parsing_test_file + def test_parsing_test_file parser = AsvParser.new REXML::Document.parse_stream(File.open('test/test.xml'), parser) genesis = parser.books['GEN'] matthew = parser.books['MAT'] assert_equal('Genesis', genesis.title) assert_equal(2, genesis.chapters.size) assert_equal(2, genesis.chapters[0].verses.size) assert_equal(2, genesis.chapters[1].verses.size) assert_equal('In the beginning God created the heavens and the earth.', genesis.chapters[0].verses[0].text) assert_equal('And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters.', genesis.chapters[0].verses[1].text) assert_equal('And the heavens and the earth were finished, and all the host of them.', genesis.chapters[1].verses[0].text) assert_equal('And on the seventh day God finished his work which he had made; and he rested on the seventh day from all his work which he had made.', genesis.chapters[1].verses[1].text) assert_equal('Matthew', matthew.title) assert_equal(2, matthew.chapters.size) assert_equal(2, matthew.chapters[0].verses.size) assert_equal(2, matthew.chapters[1].verses.size) assert_equal('The book of the generation of Jesus Christ, the son of David, the son of Abraham.', matthew.chapters[0].verses[0].text) assert_equal('Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judah and his brethren;', matthew.chapters[0].verses[1].text) assert_equal('Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, Wise-men from the east came to Jerusalem, saying,', matthew.chapters[1].verses[0].text) end end diff --git a/test/book_test.rb b/test/book_test.rb index 17ca3d7..68c0ccb 100644 --- a/test/book_test.rb +++ b/test/book_test.rb @@ -1,26 +1,24 @@ -$:.unshift File.join(File.dirname(__FILE__),'..','lib') - -require "test/unit" +require File.dirname(__FILE__) + "/testhelper" class BookTest < Test::Unit::TestCase def test_book_title_is_set b = Book.new "sometext" assert_equal(b.title, "sometext") end def test_add_chapter c1 = Chapter.new 1 c2 = Chapter.new 2 c3 = Chapter.new 3 b = Book.new "sometext" b.add_chapter c1 b.add_chapter c2 b.add_chapter c3 assert_equal(3, b.chapters.size) assert_equal(1, b.chapters[0].id) assert_equal(2, b.chapters[1].id) assert_equal(3, b.chapters[2].id) end end \ No newline at end of file diff --git a/test/chapter_test.rb b/test/chapter_test.rb index 851f036..a5659ad 100644 --- a/test/chapter_test.rb +++ b/test/chapter_test.rb @@ -1,32 +1,30 @@ -$:.unshift File.join(File.dirname(__FILE__),'..','lib') - -require "test/unit" +require File.dirname(__FILE__) + "/testhelper" class ChapterTest < Test::Unit::TestCase def test_chapter_is_set c1 = Chapter.new 1 c2 = Chapter.new 2 c3 = Chapter.new 999 assert_equal(1, c1.id) assert_equal(2, c2.id) assert_equal(999, c3.id) end def test_add_verse v1 = Verse.new 1 v2 = Verse.new 2 v3 = Verse.new 999 c1 = Chapter.new 1 c1.add_verse v1 c1.add_verse v2 c1.add_verse v3 assert_equal(3, c1.verses.size) assert_equal(1, c1.verses[0].id) assert_equal(2, c1.verses[1].id) assert_equal(999, c1.verses[2].id) end end \ No newline at end of file diff --git a/test/testhelper.rb b/test/testhelper.rb new file mode 100644 index 0000000..c6fd3ea --- /dev/null +++ b/test/testhelper.rb @@ -0,0 +1,8 @@ +#$:.unshift File.join(File.dirname(__FILE__),'..','lib') + +require "lib/book" +require "lib/chapter" +require "lib/verse" +require "lib/asv_parser" + +require "test/unit" \ No newline at end of file diff --git a/test/verse_test.rb b/test/verse_test.rb index a8fcf2f..a167d69 100644 --- a/test/verse_test.rb +++ b/test/verse_test.rb @@ -1,22 +1,20 @@ -$:.unshift File.join(File.dirname(__FILE__),'..','lib') - -require "test/unit" +require File.dirname(__FILE__) + "/testhelper" class VerseTest < Test::Unit::TestCase def test_initialize_with_id v1 = Verse.new 1 v2 = Verse.new 2 v3 = Verse.new 999 assert_equal(1, v1.id) assert_equal(2, v2.id) assert_equal(999, v3.id) end def test_set_text v1 = Verse.new 1 v1.text = "blah blah blah" assert_equal("blah blah blah", v1.text) end end \ No newline at end of file
caspian311/xsem-parser
c8346f25b590eba1ffd21c08bc441747ff83a0b4
still trying to fix this stupid require hack crap
diff --git a/lib/stream_parser.rb b/lib/asv_parser.rb similarity index 94% rename from lib/stream_parser.rb rename to lib/asv_parser.rb index 246d108..512f466 100644 --- a/lib/stream_parser.rb +++ b/lib/asv_parser.rb @@ -1,80 +1,80 @@ require 'rexml/document' require 'rexml/streamlistener' require "lib/book" require "lib/chapter" require "lib/verse" include REXML -class StreamParser +class AsvParser include StreamListener attr_reader :books def initialize @books = {} end def tag_start(name, attributes) if name == 'bookDecl' @book_id = attribute_val(attributes, 'id') elsif name == 'shortName' @in_book_title = true elsif name == 'book' @current_book = books[attribute_val(attributes, 'value')] elsif name == 'chapter' @current_chapter = Chapter.new attribute_val(attributes, 'value') @current_book.add_chapter @current_chapter elsif name == 'verse' @current_verse = Verse.new attribute_val(attributes, 'value') @current_chapter.add_verse @current_verse @in_verse = true elsif name == 'verseEnd' @in_verse = false end end def tag_end(name) if name == 'bookDecl' @books[@book_id] = Book.new @book_title end end def text(text) if @in_book_title @book_title = text.strip @in_book_title = false elsif @in_verse @current_verse.text = text.strip end end def print puts "list of books..." @books.each_value do |book| puts "book: #{book.title}" book.chapters.each do |chapter| puts " chapter: #{chapter.id}" chapter.verses.each do |verse| puts " verse: #{verse.id}" puts " text: #{verse.text}" end end end end private def attribute_val(attributes, key) value = nil attributes.each do |attribute_pair| if attribute_pair[0] == key value = attribute_pair[1] break end end return value end end diff --git a/test/stream_parser_test.rb b/test/asv_parser_test.rb similarity index 88% rename from test/stream_parser_test.rb rename to test/asv_parser_test.rb index 2d60672..6e0d548 100644 --- a/test/stream_parser_test.rb +++ b/test/asv_parser_test.rb @@ -1,36 +1,35 @@ -require 'test/unit' -require 'rexml/document' +$:.unshift File.join(File.dirname(__FILE__),'..','lib') -require "lib/stream_parser" -require "lib/book" -require "lib/chapter" -require "lib/verse" +require "rexml/document" +require "test/unit" -class StreamParserTest < Test::Unit::TestCase +require "lib/asv_parser" + +class AsvParserTest < Test::Unit::TestCase def test_parsing_test_file - parser = StreamParser.new + parser = AsvParser.new REXML::Document.parse_stream(File.open('test/test.xml'), parser) genesis = parser.books['GEN'] matthew = parser.books['MAT'] assert_equal('Genesis', genesis.title) assert_equal(2, genesis.chapters.size) assert_equal(2, genesis.chapters[0].verses.size) assert_equal(2, genesis.chapters[1].verses.size) assert_equal('In the beginning God created the heavens and the earth.', genesis.chapters[0].verses[0].text) assert_equal('And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters.', genesis.chapters[0].verses[1].text) assert_equal('And the heavens and the earth were finished, and all the host of them.', genesis.chapters[1].verses[0].text) assert_equal('And on the seventh day God finished his work which he had made; and he rested on the seventh day from all his work which he had made.', genesis.chapters[1].verses[1].text) assert_equal('Matthew', matthew.title) assert_equal(2, matthew.chapters.size) assert_equal(2, matthew.chapters[0].verses.size) assert_equal(2, matthew.chapters[1].verses.size) assert_equal('The book of the generation of Jesus Christ, the son of David, the son of Abraham.', matthew.chapters[0].verses[0].text) assert_equal('Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judah and his brethren;', matthew.chapters[0].verses[1].text) assert_equal('Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, Wise-men from the east came to Jerusalem, saying,', matthew.chapters[1].verses[0].text) end end diff --git a/test/book_test.rb b/test/book_test.rb index 9e45535..17ca3d7 100644 --- a/test/book_test.rb +++ b/test/book_test.rb @@ -1,27 +1,26 @@ -require "test/unit" +$:.unshift File.join(File.dirname(__FILE__),'..','lib') -require "lib/book" -require "lib/chapter" +require "test/unit" class BookTest < Test::Unit::TestCase def test_book_title_is_set b = Book.new "sometext" assert_equal(b.title, "sometext") end def test_add_chapter c1 = Chapter.new 1 c2 = Chapter.new 2 c3 = Chapter.new 3 b = Book.new "sometext" b.add_chapter c1 b.add_chapter c2 b.add_chapter c3 assert_equal(3, b.chapters.size) assert_equal(1, b.chapters[0].id) assert_equal(2, b.chapters[1].id) assert_equal(3, b.chapters[2].id) end end \ No newline at end of file diff --git a/test/chapter_test.rb b/test/chapter_test.rb index 847ba26..851f036 100644 --- a/test/chapter_test.rb +++ b/test/chapter_test.rb @@ -1,32 +1,32 @@ -require "test/unit" +$:.unshift File.join(File.dirname(__FILE__),'..','lib') -require "lib/chapter" +require "test/unit" class ChapterTest < Test::Unit::TestCase def test_chapter_is_set c1 = Chapter.new 1 c2 = Chapter.new 2 c3 = Chapter.new 999 assert_equal(1, c1.id) assert_equal(2, c2.id) assert_equal(999, c3.id) end def test_add_verse v1 = Verse.new 1 v2 = Verse.new 2 v3 = Verse.new 999 c1 = Chapter.new 1 c1.add_verse v1 c1.add_verse v2 c1.add_verse v3 assert_equal(3, c1.verses.size) assert_equal(1, c1.verses[0].id) assert_equal(2, c1.verses[1].id) assert_equal(999, c1.verses[2].id) end end \ No newline at end of file diff --git a/test/verse_test.rb b/test/verse_test.rb index 8e7a7b9..a8fcf2f 100644 --- a/test/verse_test.rb +++ b/test/verse_test.rb @@ -1,22 +1,22 @@ -require "test/unit" +$:.unshift File.join(File.dirname(__FILE__),'..','lib') -require "lib/verse" +require "test/unit" class VerseTest < Test::Unit::TestCase def test_initialize_with_id v1 = Verse.new 1 v2 = Verse.new 2 v3 = Verse.new 999 assert_equal(1, v1.id) assert_equal(2, v2.id) assert_equal(999, v3.id) end def test_set_text v1 = Verse.new 1 v1.text = "blah blah blah" assert_equal("blah blah blah", v1.text) end end \ No newline at end of file
caspian311/xsem-parser
9f60345705e7d8ddd50829d68cde0504809e2df3
removed the original dom parser
diff --git a/lib/parser.rb b/lib/parser.rb deleted file mode 100644 index 1651681..0000000 --- a/lib/parser.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'rexml/document' -require 'book' -require 'chapter' -require 'verse' - -class Parser - attr_reader :books - - def initialize - @books = [] - end - - def parse_file(filename) - xml_file = File.new(filename); - doc = REXML::Document.new xml_file - - doc.elements.each('*/book') do |book_element| - book = Book.new(book_element.attributes['value']) - book_element.elements.each('*/c') do |chapter_element| - chapter = Chapter.new(chapter_element.attributes['id']) - book.add_chapter chapter - - book_element.elements.each('*/v') do |verse_element| - verse_id = verse_element.attributes['id'] - verse_text =verse_element.text - verse = Verse.new(verse_id, verse_text) - - chapter.add_verse verse - end - end - - books << book - end - end - - - def print_all - books.each do |book| - print "#{book.title}:\n" - book.chapters.each do |chapter| - print " chapter #{chapter.id}:\n" - chapter.verses.each do |verse| - print " #{verse.id} - #{verse.text}" - end - end - end - end -end diff --git a/lib/stream_parser.rb b/lib/stream_parser.rb index e2acfc8..246d108 100644 --- a/lib/stream_parser.rb +++ b/lib/stream_parser.rb @@ -1,79 +1,80 @@ require 'rexml/document' require 'rexml/streamlistener' -require 'app/book.rb' -require 'app/chapter' -require 'app/verse' + +require "lib/book" +require "lib/chapter" +require "lib/verse" include REXML class StreamParser include StreamListener attr_reader :books def initialize @books = {} end def tag_start(name, attributes) if name == 'bookDecl' @book_id = attribute_val(attributes, 'id') elsif name == 'shortName' @in_book_title = true elsif name == 'book' @current_book = books[attribute_val(attributes, 'value')] elsif name == 'chapter' @current_chapter = Chapter.new attribute_val(attributes, 'value') @current_book.add_chapter @current_chapter elsif name == 'verse' @current_verse = Verse.new attribute_val(attributes, 'value') @current_chapter.add_verse @current_verse @in_verse = true elsif name == 'verseEnd' @in_verse = false end end def tag_end(name) if name == 'bookDecl' @books[@book_id] = Book.new @book_title end end def text(text) if @in_book_title @book_title = text.strip @in_book_title = false elsif @in_verse @current_verse.text = text.strip end end def print puts "list of books..." @books.each_value do |book| puts "book: #{book.title}" book.chapters.each do |chapter| puts " chapter: #{chapter.id}" chapter.verses.each do |verse| puts " verse: #{verse.id}" puts " text: #{verse.text}" end end end end private def attribute_val(attributes, key) value = nil attributes.each do |attribute_pair| if attribute_pair[0] == key value = attribute_pair[1] break end end return value end end diff --git a/test/book_test.rb b/test/book_test.rb index e7829d7..9e45535 100644 --- a/test/book_test.rb +++ b/test/book_test.rb @@ -1,25 +1,27 @@ require "test/unit" -$:.unshift File.join(File.dirname(__FILE__),'..','lib') + +require "lib/book" +require "lib/chapter" class BookTest < Test::Unit::TestCase def test_book_title_is_set b = Book.new "sometext" assert_equal(b.title, "sometext") end def test_add_chapter c1 = Chapter.new 1 c2 = Chapter.new 2 c3 = Chapter.new 3 b = Book.new "sometext" b.add_chapter c1 b.add_chapter c2 b.add_chapter c3 assert_equal(3, b.chapters.size) assert_equal(1, b.chapters[0].id) assert_equal(2, b.chapters[1].id) assert_equal(3, b.chapters[2].id) end end \ No newline at end of file diff --git a/test/chapter_test.rb b/test/chapter_test.rb index ef9b9d9..847ba26 100644 --- a/test/chapter_test.rb +++ b/test/chapter_test.rb @@ -1,31 +1,32 @@ require "test/unit" -$:.unshift File.join(File.dirname(__FILE__),'..','lib') + +require "lib/chapter" class ChapterTest < Test::Unit::TestCase def test_chapter_is_set c1 = Chapter.new 1 c2 = Chapter.new 2 c3 = Chapter.new 999 assert_equal(1, c1.id) assert_equal(2, c2.id) assert_equal(999, c3.id) end def test_add_verse v1 = Verse.new 1 v2 = Verse.new 2 v3 = Verse.new 999 c1 = Chapter.new 1 c1.add_verse v1 c1.add_verse v2 c1.add_verse v3 assert_equal(3, c1.verses.size) assert_equal(1, c1.verses[0].id) assert_equal(2, c1.verses[1].id) assert_equal(999, c1.verses[2].id) end end \ No newline at end of file diff --git a/test/stream_parser_test.rb b/test/stream_parser_test.rb index 0d77ae4..2d60672 100644 --- a/test/stream_parser_test.rb +++ b/test/stream_parser_test.rb @@ -1,33 +1,36 @@ require 'test/unit' require 'rexml/document' -$:.unshift File.join(File.dirname(__FILE__),'..','lib') +require "lib/stream_parser" +require "lib/book" +require "lib/chapter" +require "lib/verse" class StreamParserTest < Test::Unit::TestCase def test_parsing_test_file parser = StreamParser.new - REXML::Document.parse_stream(File.open('test/unit/test.xml'), parser) + REXML::Document.parse_stream(File.open('test/test.xml'), parser) genesis = parser.books['GEN'] matthew = parser.books['MAT'] assert_equal('Genesis', genesis.title) assert_equal(2, genesis.chapters.size) assert_equal(2, genesis.chapters[0].verses.size) assert_equal(2, genesis.chapters[1].verses.size) assert_equal('In the beginning God created the heavens and the earth.', genesis.chapters[0].verses[0].text) assert_equal('And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters.', genesis.chapters[0].verses[1].text) assert_equal('And the heavens and the earth were finished, and all the host of them.', genesis.chapters[1].verses[0].text) assert_equal('And on the seventh day God finished his work which he had made; and he rested on the seventh day from all his work which he had made.', genesis.chapters[1].verses[1].text) assert_equal('Matthew', matthew.title) assert_equal(2, matthew.chapters.size) assert_equal(2, matthew.chapters[0].verses.size) assert_equal(2, matthew.chapters[1].verses.size) assert_equal('The book of the generation of Jesus Christ, the son of David, the son of Abraham.', matthew.chapters[0].verses[0].text) assert_equal('Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judah and his brethren;', matthew.chapters[0].verses[1].text) assert_equal('Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, Wise-men from the east came to Jerusalem, saying,', matthew.chapters[1].verses[0].text) end end diff --git a/test/verse_test.rb b/test/verse_test.rb index cab77b6..8e7a7b9 100644 --- a/test/verse_test.rb +++ b/test/verse_test.rb @@ -1,22 +1,22 @@ require "test/unit" -$:.unshift File.join(File.dirname(__FILE__),'..','lib') +require "lib/verse" class VerseTest < Test::Unit::TestCase def test_initialize_with_id v1 = Verse.new 1 v2 = Verse.new 2 v3 = Verse.new 999 assert_equal(1, v1.id) assert_equal(2, v2.id) assert_equal(999, v3.id) end def test_set_text v1 = Verse.new 1 v1.text = "blah blah blah" assert_equal("blah blah blah", v1.text) end end \ No newline at end of file
caspian311/xsem-parser
bd4a502cd40032a0e3b20d236e25947f54f333a9
retro-fitted the app with some tests now that i know how to use test/unit
diff --git a/test/unit/book_test.rb b/test/unit/book_test.rb new file mode 100644 index 0000000..96604d2 --- /dev/null +++ b/test/unit/book_test.rb @@ -0,0 +1,26 @@ +require "test/unit" +require "app/book" +require "app/chapter" + +class BookTest < Test::Unit::TestCase + def test_book_title_is_set + b = Book.new "sometext" + assert_equal(b.title, "sometext") + end + + def test_add_chapter + c1 = Chapter.new 1 + c2 = Chapter.new 2 + c3 = Chapter.new 3 + + b = Book.new "sometext" + b.add_chapter c1 + b.add_chapter c2 + b.add_chapter c3 + + assert_equal(3, b.chapters.size) + assert_equal(1, b.chapters[0].id) + assert_equal(2, b.chapters[1].id) + assert_equal(3, b.chapters[2].id) + end +end \ No newline at end of file diff --git a/test/unit/chapter_test.rb b/test/unit/chapter_test.rb new file mode 100644 index 0000000..c37084c --- /dev/null +++ b/test/unit/chapter_test.rb @@ -0,0 +1,32 @@ +require "test/unit" +require "app/chapter" +require "app/verse" + +class ChapterTest < Test::Unit::TestCase + def test_chapter_is_set + c1 = Chapter.new 1 + c2 = Chapter.new 2 + c3 = Chapter.new 999 + + assert_equal(1, c1.id) + assert_equal(2, c2.id) + assert_equal(999, c3.id) + end + + def test_add_verse + v1 = Verse.new 1 + v2 = Verse.new 2 + v3 = Verse.new 999 + c1 = Chapter.new 1 + + c1.add_verse v1 + c1.add_verse v2 + c1.add_verse v3 + + assert_equal(3, c1.verses.size) + + assert_equal(1, c1.verses[0].id) + assert_equal(2, c1.verses[1].id) + assert_equal(999, c1.verses[2].id) + end +end \ No newline at end of file diff --git a/test/unit/verse_test.rb b/test/unit/verse_test.rb new file mode 100644 index 0000000..c67b0b2 --- /dev/null +++ b/test/unit/verse_test.rb @@ -0,0 +1,21 @@ +require "test/unit" +require "app/verse" + +class VerseTest < Test::Unit::TestCase + def test_initialize_with_id + v1 = Verse.new 1 + v2 = Verse.new 2 + v3 = Verse.new 999 + + assert_equal(1, v1.id) + assert_equal(2, v2.id) + assert_equal(999, v3.id) + end + + def test_set_text + v1 = Verse.new 1 + v1.text = "blah blah blah" + + assert_equal("blah blah blah", v1.text) + end +end \ No newline at end of file
caspian311/xsem-parser
6993b504dd1944b674186a86d9bed12f0d0e4d9e
added .project and .loadpath to the gitignore
diff --git a/.gitignore b/.gitignore index 1377554..ff2a237 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ *.swp +.loadpath +.project
caspian311/xsem-parser
28942dfc7c8a48b2a793ae58046e179745fded9e
added print to the run
diff --git a/run.rb b/run.rb index 97835df..b703062 100644 --- a/run.rb +++ b/run.rb @@ -1,7 +1,8 @@ require 'REXML/document' require 'app/stream_parser' include REXML parser = StreamParser.new Document.parse_stream(File.open('data/asv-xsem.xml'), parser) +parser.print \ No newline at end of file
caspian311/xsem-parser
25dc103e67895c082e5df87de3b893ef4f0db412
fixed the run guy to use the right parser and data file
diff --git a/run.rb b/run.rb index e8878ae..97835df 100644 --- a/run.rb +++ b/run.rb @@ -1,5 +1,7 @@ -require './app/parser' +require 'REXML/document' +require 'app/stream_parser' -parser = Parser.new -parser.parse_file("data/asv-xsem.xml") -parser.print_all +include REXML + +parser = StreamParser.new +Document.parse_stream(File.open('data/asv-xsem.xml'), parser)
caspian311/xsem-parser
dd0c6c4fc8aaba3dda9499472a807723bb754e6a
moved the files into different directories and added a rake file
diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..a43b455 --- /dev/null +++ b/Rakefile @@ -0,0 +1,14 @@ +require 'rake' +require 'rake/testtask' +require 'rake/packagetask' +require 'find' + +desc 'Default: run unit tests.' +task :default => :test + +desc 'Test ASV Parser' +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.pattern = 'test/**/*_test.rb' + t.verbose = true +end diff --git a/book.rb b/app/book.rb similarity index 90% rename from book.rb rename to app/book.rb index 559a26c..e15aee6 100644 --- a/book.rb +++ b/app/book.rb @@ -1,16 +1,14 @@ - - class Book attr_reader :title attr_reader :chapters def initialize(title) @title = title @chapters = [] end def add_chapter(chapter) @chapters += [chapter] end end diff --git a/chapter.rb b/app/chapter.rb similarity index 91% rename from chapter.rb rename to app/chapter.rb index 3d59e64..5be264f 100644 --- a/chapter.rb +++ b/app/chapter.rb @@ -1,14 +1,13 @@ - class Chapter attr_reader :id attr_reader :verses def initialize(id) @id = id @verses = [] end def add_verse(verse) @verses += [verse] end end diff --git a/parser.rb b/app/parser.rb similarity index 100% rename from parser.rb rename to app/parser.rb diff --git a/stream_parser.rb b/app/stream_parser.rb similarity index 86% rename from stream_parser.rb rename to app/stream_parser.rb index b07c890..e2acfc8 100644 --- a/stream_parser.rb +++ b/app/stream_parser.rb @@ -1,84 +1,79 @@ require 'rexml/document' require 'rexml/streamlistener' -require 'book' -require 'chapter' -require 'verse' +require 'app/book.rb' +require 'app/chapter' +require 'app/verse' include REXML class StreamParser include StreamListener attr_reader :books def initialize @books = {} end def tag_start(name, attributes) if name == 'bookDecl' @book_id = attribute_val(attributes, 'id') elsif name == 'shortName' @in_book_title = true elsif name == 'book' @current_book = books[attribute_val(attributes, 'value')] elsif name == 'chapter' @current_chapter = Chapter.new attribute_val(attributes, 'value') @current_book.add_chapter @current_chapter elsif name == 'verse' @current_verse = Verse.new attribute_val(attributes, 'value') @current_chapter.add_verse @current_verse @in_verse = true elsif name == 'verseEnd' @in_verse = false end end def tag_end(name) if name == 'bookDecl' @books[@book_id] = Book.new @book_title end end def text(text) if @in_book_title @book_title = text.strip @in_book_title = false elsif @in_verse @current_verse.text = text.strip end end def print puts "list of books..." @books.each_value do |book| puts "book: #{book.title}" book.chapters.each do |chapter| puts " chapter: #{chapter.id}" chapter.verses.each do |verse| puts " verse: #{verse.id}" puts " text: #{verse.text}" end end end end private def attribute_val(attributes, key) value = nil attributes.each do |attribute_pair| if attribute_pair[0] == key value = attribute_pair[1] break end end return value end end - -myParser = StreamParser.new -Document.parse_stream( File.open('test.xml'), myParser) - -myParser.print diff --git a/verse.rb b/app/verse.rb similarity index 89% rename from verse.rb rename to app/verse.rb index 63c7b40..283b6fd 100644 --- a/verse.rb +++ b/app/verse.rb @@ -1,10 +1,9 @@ - class Verse attr_reader :id attr_accessor :text def initialize(id) @id = id end end diff --git a/run.rb b/run.rb index eef7706..e8878ae 100644 --- a/run.rb +++ b/run.rb @@ -1,5 +1,5 @@ -require 'parser' +require './app/parser' parser = Parser.new parser.parse_file("data/asv-xsem.xml") parser.print_all diff --git a/test/unit/stream_parser_test.rb b/test/unit/stream_parser_test.rb new file mode 100644 index 0000000..75b3f10 --- /dev/null +++ b/test/unit/stream_parser_test.rb @@ -0,0 +1,35 @@ +require 'test/unit' +require 'rexml/document' +require 'app/stream_parser' +require 'app/book' +require 'app/chapter' +require 'app/verse' + +class StreamParserTest < Test::Unit::TestCase + def test_parsing_test_file + parser = StreamParser.new + REXML::Document.parse_stream(File.open('test/unit/test.xml'), parser) + + genesis = parser.books['GEN'] + matthew = parser.books['MAT'] + + assert_equal('Genesis', genesis.title) + assert_equal(2, genesis.chapters.size) + assert_equal(2, genesis.chapters[0].verses.size) + assert_equal(2, genesis.chapters[1].verses.size) + assert_equal('In the beginning God created the heavens and the earth.', genesis.chapters[0].verses[0].text) + assert_equal('And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters.', genesis.chapters[0].verses[1].text) + assert_equal('And the heavens and the earth were finished, and all the host of them.', genesis.chapters[1].verses[0].text) + assert_equal('And on the seventh day God finished his work which he had made; and he rested on the seventh day from all his work which he had made.', genesis.chapters[1].verses[1].text) + + assert_equal('Matthew', matthew.title) + assert_equal(2, matthew.chapters.size) + assert_equal(2, matthew.chapters[0].verses.size) + assert_equal(2, matthew.chapters[1].verses.size) + assert_equal('The book of the generation of Jesus Christ, the son of David, the son of Abraham.', matthew.chapters[0].verses[0].text) + assert_equal('Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judah and his brethren;', matthew.chapters[0].verses[1].text) + assert_equal('Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, Wise-men from the east came to Jerusalem, saying,', matthew.chapters[1].verses[0].text) + + end +end + diff --git a/test.xml b/test/unit/test.xml similarity index 100% rename from test.xml rename to test/unit/test.xml
caspian311/xsem-parser
4f8827e55dbde4545d1cf5a8cd735f239d42331a
using a stream parser instead of a dom parser because of the nastiness of the available formats
diff --git a/stream_parser.rb b/stream_parser.rb new file mode 100644 index 0000000..b07c890 --- /dev/null +++ b/stream_parser.rb @@ -0,0 +1,84 @@ +require 'rexml/document' +require 'rexml/streamlistener' +require 'book' +require 'chapter' +require 'verse' + +include REXML + +class StreamParser + include StreamListener + + attr_reader :books + + def initialize + @books = {} + end + + def tag_start(name, attributes) + if name == 'bookDecl' + @book_id = attribute_val(attributes, 'id') + elsif name == 'shortName' + @in_book_title = true + elsif name == 'book' + @current_book = books[attribute_val(attributes, 'value')] + elsif name == 'chapter' + @current_chapter = Chapter.new attribute_val(attributes, 'value') + @current_book.add_chapter @current_chapter + elsif name == 'verse' + @current_verse = Verse.new attribute_val(attributes, 'value') + @current_chapter.add_verse @current_verse + @in_verse = true + elsif name == 'verseEnd' + @in_verse = false + end + end + + def tag_end(name) + if name == 'bookDecl' + @books[@book_id] = Book.new @book_title + end + end + + def text(text) + if @in_book_title + @book_title = text.strip + @in_book_title = false + elsif @in_verse + @current_verse.text = text.strip + end + end + + def print + puts "list of books..." + @books.each_value do |book| + puts "book: #{book.title}" + book.chapters.each do |chapter| + puts " chapter: #{chapter.id}" + chapter.verses.each do |verse| + puts " verse: #{verse.id}" + puts " text: #{verse.text}" + end + end + end + end + + + private + + def attribute_val(attributes, key) + value = nil + attributes.each do |attribute_pair| + if attribute_pair[0] == key + value = attribute_pair[1] + break + end + end + return value + end +end + +myParser = StreamParser.new +Document.parse_stream( File.open('test.xml'), myParser) + +myParser.print diff --git a/test.xml b/test.xml new file mode 100644 index 0000000..186a909 --- /dev/null +++ b/test.xml @@ -0,0 +1,56 @@ +<scripture> + <scriptureHeader> + <bookDecl id="GEN"> + <shortName>Genesis</shortName> + <longName>blah blah</longName> + </bookDecl> + <bookDecl id="MAT"> + <shortName>Matthew</shortName> + <longName>blah blah blah</longName> + </bookDecl> + </scriptureHeader> + <canon id="OT" value="OT"> + <book value="GEN"> + <text> + <chapter value="1" /> + <verse value="1" /> + In the beginning God created the heavens and the earth. + <verseEnd /> + <verse value="2" /> + And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters. + <verseEnd /> + <chapterEnd /> + <chapter value="2" /> + <verse value="1" /> + And the heavens and the earth were finished, and all the host of them. + <verseEnd /> + <verse value="2" /> + And on the seventh day God finished his work which he had made; and he rested on the seventh day from all his work which he had made. + <verseEnd /> + <chapterEnd /> + </text> + </book> + </canon> + <canon id="NT" value="NT"> + <book value="MAT"> + <text> + <chapter value="1" /> + <verse value="1" /> + The book of the generation of Jesus Christ, the son of David, the son of Abraham. + <verseEnd /> + <verse value="2" /> + Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judah and his brethren; + <verseEnd /> + <chapterEnd /> + <chapter value="2" /> + <verse value="1" /> + Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, Wise-men from the east came to Jerusalem, saying, + <verseEnd /> + <verse value="2" /> + Where is he that is born King of the Jews? for we saw his star in the east, and are come to worship him. + <verseEnd /> + <chapterEnd /> + </text> + </book> + </canon> +</scripture> \ No newline at end of file diff --git a/verse.rb b/verse.rb index 19f622b..63c7b40 100644 --- a/verse.rb +++ b/verse.rb @@ -1,11 +1,10 @@ class Verse attr_reader :id - attr_reader :text + attr_accessor :text - def initialize(id,text) + def initialize(id) @id = id - @text = text end end
caspian311/xsem-parser
b156bf38ae5ea531ac03707d94134cb2541e92ca
moved the data file to a data directory
diff --git a/asv-usfx.xml b/data/asv-usfx.xml similarity index 100% rename from asv-usfx.xml rename to data/asv-usfx.xml diff --git a/run.rb b/run.rb index 2cad029..63c3219 100644 --- a/run.rb +++ b/run.rb @@ -1,5 +1,5 @@ -require 'parse' +require 'parser' parser = Parser.new -parser.parse_file("asv-usfx.xml") +parser.parse_file("data/asv-usfx.xml") parser.print_all
caspian311/xsem-parser
db145e9f47277496c77b9926d365c6daf50bfbab
created book, chapter, verse classses to hold the data
diff --git a/book.rb b/book.rb new file mode 100644 index 0000000..559a26c --- /dev/null +++ b/book.rb @@ -0,0 +1,16 @@ + + +class Book + attr_reader :title + attr_reader :chapters + + def initialize(title) + @title = title + @chapters = [] + end + + def add_chapter(chapter) + @chapters += [chapter] + end +end + diff --git a/chapter.rb b/chapter.rb new file mode 100644 index 0000000..fef5a45 --- /dev/null +++ b/chapter.rb @@ -0,0 +1,13 @@ + +class Chapter + attr_reader :id + attr_reader :verses + + def initialize + @verses = [] + end + + def add_verse(verse) + @verses += [verse] + end +end diff --git a/parse.rb b/parse.rb index 8e89347..f970bd8 100644 --- a/parse.rb +++ b/parse.rb @@ -1,18 +1,35 @@ require 'rexml/document' +require 'book' +require 'chapter' +require 'verse' -# get the XML data as a string -xml_file = File.new("asv-usfx.xml"); +class Parser + attr_reader :books -# extract event information -doc = REXML::Document.new xml_file + def initialize + @books = [] + end + + def parse_file(filename) + xml_file = File.new(filename); + doc = REXML::Document.new xml_file + + doc.elements.each('usfx/book') do |book| + books << Book.new(book.elements["h"].text) + end + end -books = [] -doc.elements.each('usfx/book') do |book| - books << book.elements["h"].text -end -# print all events -puts "all titles..." -books.each do |book| - print "#{book}\n" + def print_all + puts "all titles..." + books.each do |book| + print "#{book.title}:\n" + book.chapters.each do |chapter| + print " chapter #{chapter.id}:\n" + chapter.verses.each do |verse| + print " #{verse.id} - #{verse.text}" + end + end + end + end end diff --git a/run.rb b/run.rb new file mode 100644 index 0000000..2cad029 --- /dev/null +++ b/run.rb @@ -0,0 +1,5 @@ +require 'parse' + +parser = Parser.new +parser.parse_file("asv-usfx.xml") +parser.print_all diff --git a/verse.rb b/verse.rb new file mode 100644 index 0000000..19f622b --- /dev/null +++ b/verse.rb @@ -0,0 +1,11 @@ + +class Verse + attr_reader :id + attr_reader :text + + def initialize(id,text) + @id = id + @text = text + end +end +
caspian311/xsem-parser
bf60e7d3001fc88d3051456a228bb24bab718f2e
added .gitignore file to ignore swap files left over from vi sessions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp
caspian311/xsem-parser
fac32f5d2d6bf8a000d8c9513469a486e9046a7b
initial import - added readme describing the project
diff --git a/README b/README new file mode 100644 index 0000000..39ffd9c --- /dev/null +++ b/README @@ -0,0 +1 @@ +this is a parser for the asb bible text available at http://ebible.org/asv
wintersa/Powershell-Exchange-CC
84a8e512bfd6efd6f8ea4df9b32933d1c7c39628
Empty directory
diff --git a/tmp/.gitignore b/tmp/.gitignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/tmp/.gitignore @@ -0,0 +1 @@ +*
wintersa/Powershell-Exchange-CC
44fcccb966015797af79f7204968faa97531c6e4
Changelog
diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..e69de29
candersonmiller/spatial-media-itp
6ed0e75062705cd0e574875ee204630710bd2ebb
adding pixel color assignment
diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/main.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/main.o new file mode 100644 index 0000000..81f01de Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/main.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofAppRunner.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofAppRunner.o new file mode 100644 index 0000000..5a4390d Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofAppRunner.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofGraphics.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofGraphics.o new file mode 100644 index 0000000..8043d7e Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofGraphics.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofImage.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofImage.o new file mode 100644 index 0000000..118dcf2 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofImage.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofMath.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofMath.o new file mode 100644 index 0000000..bffb3a7 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofMath.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofQtUtils.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofQtUtils.o new file mode 100644 index 0000000..93a115d Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofQtUtils.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSerial.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSerial.o new file mode 100644 index 0000000..8695269 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSerial.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSoundPlayer.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSoundPlayer.o new file mode 100644 index 0000000..d413fa5 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSoundPlayer.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSoundStream.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSoundStream.o new file mode 100644 index 0000000..e8a39b9 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSoundStream.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofTexture.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofTexture.o new file mode 100644 index 0000000..2ee0c68 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofTexture.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofTrueTypeFont.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofTrueTypeFont.o new file mode 100644 index 0000000..42a8e1b Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofTrueTypeFont.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofUtils.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofUtils.o new file mode 100644 index 0000000..7073a83 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofUtils.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofVideoGrabber.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofVideoGrabber.o new file mode 100644 index 0000000..2b05d2e Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofVideoGrabber.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofVideoPlayer.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofVideoPlayer.o new file mode 100644 index 0000000..32fe20a Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofVideoPlayer.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvColorImage.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvColorImage.o new file mode 100644 index 0000000..7b79b28 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvColorImage.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvContourFinder.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvContourFinder.o new file mode 100644 index 0000000..e8a759f Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvContourFinder.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvFloatImage.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvFloatImage.o new file mode 100644 index 0000000..7d4fbe2 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvFloatImage.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvGrayscaleImage.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvGrayscaleImage.o new file mode 100644 index 0000000..2718f71 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvGrayscaleImage.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvImage.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvImage.o new file mode 100644 index 0000000..d550516 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvImage.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/openFrameworksDebug.LinkFileList b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/openFrameworksDebug.LinkFileList new file mode 100644 index 0000000..c119f3e --- /dev/null +++ b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/openFrameworksDebug.LinkFileList @@ -0,0 +1,20 @@ +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/main.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/testApp.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofAppRunner.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSerial.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofGraphics.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofImage.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofTexture.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofTrueTypeFont.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSoundPlayer.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSoundStream.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofMath.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofUtils.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofQtUtils.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofVideoGrabber.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofVideoPlayer.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvColorImage.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvContourFinder.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvFloatImage.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvGrayscaleImage.o +/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvImage.o diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/testApp.o b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/testApp.o new file mode 100644 index 0000000..7969ec3 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/testApp.o differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Script-E4B6FFFD0C3F9AB9008CF71C.sh b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Script-E4B6FFFD0C3F9AB9008CF71C.sh new file mode 100755 index 0000000..c11182d --- /dev/null +++ b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/Script-E4B6FFFD0C3F9AB9008CF71C.sh @@ -0,0 +1,3 @@ +#!/bin/sh +cp -f ../../../libs/fmodex/lib/libfmodex.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/libfmodex.dylib" +install_name_tool -change ./libfmodex.dylib @executable_path/libfmodex.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME" diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/openFrameworks.dep b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/openFrameworks.dep new file mode 100644 index 0000000..7ba527a --- /dev/null +++ b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/openFrameworks.dep @@ -0,0 +1,46 @@ +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 61172 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofVideoGrabber.o +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 23688 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofQtUtils.o +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 51660 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofUtils.o +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 18040 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofMath.o +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 86704 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSoundStream.o +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 51744 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSoundPlayer.o +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 58280 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofTrueTypeFont.o +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 27624 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofTexture.o +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 54544 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofImage.o +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 118256 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofGraphics.o +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 48988 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSerial.o +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 53880 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofAppRunner.o +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 75824 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/testApp.o +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 27904 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/main.o +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 0 /var/folders/w4/w46cMgbdE90kYnGsjevtZk+++TM/-Caches-/com.apple.Xcode.502/SharedPrecompiledHeaders/Carbon-egksvqdvnnjasqejosbhbeagjqiq/Carbon.h.gch +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 5069284 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/openFrameworksDebug.app/Contents/MacOS/openFrameworksDebug +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 631 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/openFrameworksDebug.app/Contents/Resources/openFrameworks-Info.plist +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 8 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/openFrameworksDebug.app/Contents/PkgInfo +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 623 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/openFrameworksDebug.app/Contents/Info.plist +ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffff 102 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/openFrameworksDebug.app +a58bf7d9cd58854599b35772c09917d1 7de84fe7928d6e77cf32cc09930a4258 ffffffffffffffffffffffffffffffff 102 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/openFrameworksDebug.app +391c1b50ad0119b36becbd27d2a7bb48 35395f19d922442294f233bebdf86c7e ffffffffffffffffffffffffffffffff 5069284 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/openFrameworksDebug.app/Contents/MacOS/openFrameworksDebug +0000000045e172de0000000000000277 a9aeb390fc9aaa0a66add9ebafc6c290 ffffffffffffffffffffffffffffffff 631 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/openFrameworksDebug.app/Contents/Resources/openFrameworks-Info.plist +00000000000000000000000000000000 62cec941ea31816601b76e8903da95a9 ffffffffffffffffffffffffffffffff 8 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/openFrameworksDebug.app/Contents/PkgInfo +00000000000000000000000000000000 62cec941ea31816601b76e8903da95a9 ffffffffffffffffffffffffffffffff 623 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/openFrameworksDebug.app/Contents/Info.plist +a53520db00b51bde154945eff9c0e3c9 2226afb942a4472524df48cf5ed4d4af ffffffffffffffffffffffffffffffff 47156 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvImage.o +a53520db43ae4542154945eff9ca4667 d84df44488e461938bacb1bdffabc826 ffffffffffffffffffffffffffffffff 60684 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvGrayscaleImage.o +a53520db43a063ac154945eff9ca4f09 e55561d30408ace986c447e12ec6a687 ffffffffffffffffffffffffffffffff 41168 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvFloatImage.o +a53520db43bccebe154945eff9ca77a7 203f16220ddcb0cf62ea451e240fd551 ffffffffffffffffffffffffffffffff 149676 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvContourFinder.o +a53520db4c5d2318154945eff9ca4e41 1a1f0c6a0982683d1fceba8ba8625884 ffffffffffffffffffffffffffffffff 39332 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvColorImage.o +a53520db4f4dff64154945eff9c0db8e 1087cdf123c059189cecf803342d17ac ffffffffffffffffffffffffffffffff 58852 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofVideoPlayer.o +a53520db4469e20b154945eff9cbc57d fff0b5903beae9ec108f83bd93035aa6 ffffffffffffffffffffffffffffffff 61172 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofVideoGrabber.o +a53520db4f4dff66154945eff9c09df6 6166d8c88d6f226ae693e73e3acab0bb ffffffffffffffffffffffffffffffff 23688 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofQtUtils.o +a53520db4896f64e154945eff9c16130 720b086f9537ed1ef16f41846deda5fa ffffffffffffffffffffffffffffffff 51660 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofUtils.o +a53520db4896f64e154945eff9c16b4b ee111cae1945b25abbd85e6a07a1bc0f ffffffffffffffffffffffffffffffff 18040 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofMath.o +a53520db4646821d154945eff9c314f7 5ba94395f25db6a9a2a8c0f136ee81f9 ffffffffffffffffffffffffffffffff 86704 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSoundStream.o +a53520db4d7b1314154945eff9ca6f5a dbe6f4341d05c8b646693ad6bd43b189 ffffffffffffffffffffffffffffffff 51744 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSoundPlayer.o +a53520db0bb1c89c154945eff9ca5ed8 613ee74d85d2c64fef363bd41fd1621e ffffffffffffffffffffffffffffffff 58280 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofTrueTypeFont.o +a53520db0bb1c89a154945eff9ca7b0b 79b0f6b27b8f4aebb0129fd6c68a3c23 ffffffffffffffffffffffffffffffff 27624 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofTexture.o +a53520db4b203f59154945eff9c1d990 f80df5160872da2af33c29238deaefb2 ffffffffffffffffffffffffffffffff 54544 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofImage.o +a53520db0db2cfae154945eff9c021fd e798d6b53f59641edac35a968a179706 ffffffffffffffffffffffffffffffff 118256 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofGraphics.o +a53520db485f6916154945eff9c123b9 2f03b2b58590147e3a83debbc78bb336 ffffffffffffffffffffffffffffffff 48988 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSerial.o +a53520db40f553ed154945eff9ca8993 2446cba2ae5e5c87e57aa0625fd66b8a ffffffffffffffffffffffffffffffff 53880 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofAppRunner.o +a53520db0c30d0db154945eff9c18f33 193ca3751b0129f4efef3a66229f2805 ffffffffffffffffffffffffffffffff 75824 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/testApp.o +a53520db0442d5d2154945eff9ca616e 9b24d0c12652c93abd341660c9113622 ffffffffffffffffffffffffffffffff 27904 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/main.o +000000000ed1003500000000000dc3e2 a53520db4d63eb0d154945eff9c7a4b1 ffffffffffffffffffffffffffffffff 33230028 /var/folders/w4/w46cMgbdE90kYnGsjevtZk+++TM/-Caches-/com.apple.Xcode.502/SharedPrecompiledHeaders/Carbon-fxyhzwgdaavssheqofajhlyevidh/Carbon.h.gch diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/openFrameworksDebug.hmap b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/openFrameworksDebug.hmap new file mode 100644 index 0000000..4ea2adc Binary files /dev/null and b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/openFrameworksDebug.hmap differ diff --git a/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/openFrameworks~.dep b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/openFrameworks~.dep new file mode 100644 index 0000000..d9d48be --- /dev/null +++ b/pixelColor/build/openFrameworks.build/Debug/openFrameworks.build/openFrameworks~.dep @@ -0,0 +1,26 @@ +a58bf7d9cd58854599b35772c09917d1 7de84fe7928d6e77cf32cc09930a4258 ffffffffffffffffffffffffffffffff 102 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/openFrameworksDebug.app +391c1b50ad0119b36becbd27d2a7bb48 35395f19d922442294f233bebdf86c7e ffffffffffffffffffffffffffffffff 5069284 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/openFrameworksDebug.app/Contents/MacOS/openFrameworksDebug +0000000045e172de0000000000000277 a9aeb390fc9aaa0a66add9ebafc6c290 ffffffffffffffffffffffffffffffff 631 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/openFrameworksDebug.app/Contents/Resources/openFrameworks-Info.plist +00000000000000000000000000000000 62cec941ea31816601b76e8903da95a9 ffffffffffffffffffffffffffffffff 8 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/openFrameworksDebug.app/Contents/PkgInfo +00000000000000000000000000000000 62cec941ea31816601b76e8903da95a9 ffffffffffffffffffffffffffffffff 623 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/openFrameworksDebug.app/Contents/Info.plist +a53520db00b51bde154945eff9c0e3c9 2226afb942a4472524df48cf5ed4d4af ffffffffffffffffffffffffffffffff 47156 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvImage.o +a53520db43ae4542154945eff9ca4667 d84df44488e461938bacb1bdffabc826 ffffffffffffffffffffffffffffffff 60684 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvGrayscaleImage.o +a53520db43a063ac154945eff9ca4f09 e55561d30408ace986c447e12ec6a687 ffffffffffffffffffffffffffffffff 41168 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvFloatImage.o +a53520db43bccebe154945eff9ca77a7 203f16220ddcb0cf62ea451e240fd551 ffffffffffffffffffffffffffffffff 149676 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvContourFinder.o +a53520db4c5d2318154945eff9ca4e41 1a1f0c6a0982683d1fceba8ba8625884 ffffffffffffffffffffffffffffffff 39332 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofxCvColorImage.o +a53520db4f4dff64154945eff9c0db8e 1087cdf123c059189cecf803342d17ac ffffffffffffffffffffffffffffffff 58852 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofVideoPlayer.o +a53520db4469e20b154945eff9cbc57d fff0b5903beae9ec108f83bd93035aa6 ffffffffffffffffffffffffffffffff 61172 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofVideoGrabber.o +a53520db4f4dff66154945eff9c09df6 6166d8c88d6f226ae693e73e3acab0bb ffffffffffffffffffffffffffffffff 23688 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofQtUtils.o +a53520db4896f64e154945eff9c16130 720b086f9537ed1ef16f41846deda5fa ffffffffffffffffffffffffffffffff 51660 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofUtils.o +a53520db4896f64e154945eff9c16b4b ee111cae1945b25abbd85e6a07a1bc0f ffffffffffffffffffffffffffffffff 18040 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofMath.o +a53520db4646821d154945eff9c314f7 5ba94395f25db6a9a2a8c0f136ee81f9 ffffffffffffffffffffffffffffffff 86704 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSoundStream.o +a53520db4d7b1314154945eff9ca6f5a dbe6f4341d05c8b646693ad6bd43b189 ffffffffffffffffffffffffffffffff 51744 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSoundPlayer.o +a53520db0bb1c89c154945eff9ca5ed8 613ee74d85d2c64fef363bd41fd1621e ffffffffffffffffffffffffffffffff 58280 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofTrueTypeFont.o +a53520db0bb1c89a154945eff9ca7b0b 79b0f6b27b8f4aebb0129fd6c68a3c23 ffffffffffffffffffffffffffffffff 27624 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofTexture.o +a53520db4b203f59154945eff9c1d990 f80df5160872da2af33c29238deaefb2 ffffffffffffffffffffffffffffffff 54544 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofImage.o +a53520db0db2cfae154945eff9c021fd e798d6b53f59641edac35a968a179706 ffffffffffffffffffffffffffffffff 118256 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofGraphics.o +a53520db485f6916154945eff9c123b9 2f03b2b58590147e3a83debbc78bb336 ffffffffffffffffffffffffffffffff 48988 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofSerial.o +a53520db40f553ed154945eff9ca8993 2446cba2ae5e5c87e57aa0625fd66b8a ffffffffffffffffffffffffffffffff 53880 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/ofAppRunner.o +a53520db0c30d0db154945eff9c18f33 193ca3751b0129f4efef3a66229f2805 ffffffffffffffffffffffffffffffff 75824 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/testApp.o +a53520db0442d5d2154945eff9ca616e 9b24d0c12652c93abd341660c9113622 ffffffffffffffffffffffffffffffff 27904 /Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/opencvExample/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/main.o +000000000ed1003500000000000dc3e2 a53520db4d63eb0d154945eff9c7a4b1 ffffffffffffffffffffffffffffffff 33230028 /var/folders/w4/w46cMgbdE90kYnGsjevtZk+++TM/-Caches-/com.apple.Xcode.502/SharedPrecompiledHeaders/Carbon-fxyhzwgdaavssheqofajhlyevidh/Carbon.h.gch diff --git a/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/categories.pbxbtree b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/categories.pbxbtree new file mode 100644 index 0000000..d3f6bb3 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/categories.pbxbtree differ diff --git a/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/cdecls.pbxbtree b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/cdecls.pbxbtree new file mode 100644 index 0000000..073ef16 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/cdecls.pbxbtree differ diff --git a/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/decls.pbxbtree b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/decls.pbxbtree new file mode 100644 index 0000000..3f7dca5 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/decls.pbxbtree differ diff --git a/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/files.pbxbtree b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/files.pbxbtree new file mode 100644 index 0000000..c4b5c67 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/files.pbxbtree differ diff --git a/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/imports.pbxbtree b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/imports.pbxbtree new file mode 100644 index 0000000..a1428e7 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/imports.pbxbtree differ diff --git a/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/pbxindex.header b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/pbxindex.header new file mode 100644 index 0000000..d4707ec Binary files /dev/null and b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/pbxindex.header differ diff --git a/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/protocols.pbxbtree b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/protocols.pbxbtree new file mode 100644 index 0000000..d3f6bb3 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/protocols.pbxbtree differ diff --git a/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/refs.pbxbtree b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/refs.pbxbtree new file mode 100644 index 0000000..2817f8f Binary files /dev/null and b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/refs.pbxbtree differ diff --git a/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/strings.pbxstrings/control b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/strings.pbxstrings/control new file mode 100644 index 0000000..c6b0272 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/strings.pbxstrings/control differ diff --git a/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/strings.pbxstrings/strings b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/strings.pbxstrings/strings new file mode 100644 index 0000000..fe5e0ac Binary files /dev/null and b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/strings.pbxstrings/strings differ diff --git a/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/subclasses.pbxbtree b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/subclasses.pbxbtree new file mode 100644 index 0000000..a58c966 Binary files /dev/null and b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/subclasses.pbxbtree differ diff --git a/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/symbols0.pbxsymbols b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/symbols0.pbxsymbols new file mode 100644 index 0000000..73a941b Binary files /dev/null and b/pixelColor/build/openFrameworks.build/openFrameworks.pbxindex/symbols0.pbxsymbols differ diff --git a/pixelColor/data/fingers.mov b/pixelColor/data/fingers.mov new file mode 100755 index 0000000..8c2b875 Binary files /dev/null and b/pixelColor/data/fingers.mov differ diff --git a/pixelColor/data/logo.gif b/pixelColor/data/logo.gif new file mode 100644 index 0000000..2204caa Binary files /dev/null and b/pixelColor/data/logo.gif differ diff --git a/pixelColor/data/logo.jpg b/pixelColor/data/logo.jpg new file mode 100644 index 0000000..ffb3261 Binary files /dev/null and b/pixelColor/data/logo.jpg differ diff --git a/pixelColor/data/logo1.gif b/pixelColor/data/logo1.gif new file mode 100644 index 0000000..4588049 Binary files /dev/null and b/pixelColor/data/logo1.gif differ diff --git a/pixelColor/data/logo2.gif b/pixelColor/data/logo2.gif new file mode 100644 index 0000000..80a4d5b Binary files /dev/null and b/pixelColor/data/logo2.gif differ diff --git a/pixelColor/data/logo3.gif b/pixelColor/data/logo3.gif new file mode 100644 index 0000000..ce52b1a Binary files /dev/null and b/pixelColor/data/logo3.gif differ diff --git a/pixelColor/openFrameworks-Info.plist b/pixelColor/openFrameworks-Info.plist new file mode 100644 index 0000000..e5db555 --- /dev/null +++ b/pixelColor/openFrameworks-Info.plist @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>CFBundleExecutable</key> + <string>${EXECUTABLE_NAME}</string> + <key>CFBundleIdentifier</key> + <string>com.yourcompany.openFrameworks</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleVersion</key> + <string>1.0</string> +</dict> +</plist> diff --git a/pixelColor/openFrameworks.xcodeproj/andersonmiller.mode1v3 b/pixelColor/openFrameworks.xcodeproj/andersonmiller.mode1v3 new file mode 100644 index 0000000..e07a8b3 --- /dev/null +++ b/pixelColor/openFrameworks.xcodeproj/andersonmiller.mode1v3 @@ -0,0 +1,1501 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>ActivePerspectiveName</key> + <string>Project</string> + <key>AllowedModules</key> + <array> + <dict> + <key>BundleLoadPath</key> + <string></string> + <key>MaxInstances</key> + <string>n</string> + <key>Module</key> + <string>PBXSmartGroupTreeModule</string> + <key>Name</key> + <string>Groups and Files Outline View</string> + </dict> + <dict> + <key>BundleLoadPath</key> + <string></string> + <key>MaxInstances</key> + <string>n</string> + <key>Module</key> + <string>PBXNavigatorGroup</string> + <key>Name</key> + <string>Editor</string> + </dict> + <dict> + <key>BundleLoadPath</key> + <string></string> + <key>MaxInstances</key> + <string>n</string> + <key>Module</key> + <string>XCTaskListModule</string> + <key>Name</key> + <string>Task List</string> + </dict> + <dict> + <key>BundleLoadPath</key> + <string></string> + <key>MaxInstances</key> + <string>n</string> + <key>Module</key> + <string>XCDetailModule</string> + <key>Name</key> + <string>File and Smart Group Detail Viewer</string> + </dict> + <dict> + <key>BundleLoadPath</key> + <string></string> + <key>MaxInstances</key> + <string>1</string> + <key>Module</key> + <string>PBXBuildResultsModule</string> + <key>Name</key> + <string>Detailed Build Results Viewer</string> + </dict> + <dict> + <key>BundleLoadPath</key> + <string></string> + <key>MaxInstances</key> + <string>1</string> + <key>Module</key> + <string>PBXProjectFindModule</string> + <key>Name</key> + <string>Project Batch Find Tool</string> + </dict> + <dict> + <key>BundleLoadPath</key> + <string></string> + <key>MaxInstances</key> + <string>n</string> + <key>Module</key> + <string>XCProjectFormatConflictsModule</string> + <key>Name</key> + <string>Project Format Conflicts List</string> + </dict> + <dict> + <key>BundleLoadPath</key> + <string></string> + <key>MaxInstances</key> + <string>n</string> + <key>Module</key> + <string>PBXBookmarksModule</string> + <key>Name</key> + <string>Bookmarks Tool</string> + </dict> + <dict> + <key>BundleLoadPath</key> + <string></string> + <key>MaxInstances</key> + <string>n</string> + <key>Module</key> + <string>PBXClassBrowserModule</string> + <key>Name</key> + <string>Class Browser</string> + </dict> + <dict> + <key>BundleLoadPath</key> + <string></string> + <key>MaxInstances</key> + <string>n</string> + <key>Module</key> + <string>PBXCVSModule</string> + <key>Name</key> + <string>Source Code Control Tool</string> + </dict> + <dict> + <key>BundleLoadPath</key> + <string></string> + <key>MaxInstances</key> + <string>n</string> + <key>Module</key> + <string>PBXDebugBreakpointsModule</string> + <key>Name</key> + <string>Debug Breakpoints Tool</string> + </dict> + <dict> + <key>BundleLoadPath</key> + <string></string> + <key>MaxInstances</key> + <string>n</string> + <key>Module</key> + <string>XCDockableInspector</string> + <key>Name</key> + <string>Inspector</string> + </dict> + <dict> + <key>BundleLoadPath</key> + <string></string> + <key>MaxInstances</key> + <string>n</string> + <key>Module</key> + <string>PBXOpenQuicklyModule</string> + <key>Name</key> + <string>Open Quickly Tool</string> + </dict> + <dict> + <key>BundleLoadPath</key> + <string></string> + <key>MaxInstances</key> + <string>1</string> + <key>Module</key> + <string>PBXDebugSessionModule</string> + <key>Name</key> + <string>Debugger</string> + </dict> + <dict> + <key>BundleLoadPath</key> + <string></string> + <key>MaxInstances</key> + <string>1</string> + <key>Module</key> + <string>PBXDebugCLIModule</string> + <key>Name</key> + <string>Debug Console</string> + </dict> + <dict> + <key>BundleLoadPath</key> + <string></string> + <key>MaxInstances</key> + <string>n</string> + <key>Module</key> + <string>XCSnapshotModule</string> + <key>Name</key> + <string>Snapshots Tool</string> + </dict> + </array> + <key>BundlePath</key> + <string>/Developer/Library/PrivateFrameworks/DevToolsInterface.framework/Resources</string> + <key>Description</key> + <string>DefaultDescriptionKey</string> + <key>DockingSystemVisible</key> + <false/> + <key>Extension</key> + <string>mode1v3</string> + <key>FavBarConfig</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>B7AC3DBB0F337B7F00B4EC0A</string> + <key>XCBarModuleItemNames</key> + <dict/> + <key>XCBarModuleItems</key> + <array/> + </dict> + <key>FirstTimeWindowDisplayed</key> + <false/> + <key>Identifier</key> + <string>com.apple.perspectives.project.mode1v3</string> + <key>MajorVersion</key> + <integer>33</integer> + <key>MinorVersion</key> + <integer>0</integer> + <key>Name</key> + <string>Default</string> + <key>Notifications</key> + <array/> + <key>OpenEditors</key> + <array> + <dict> + <key>Content</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>B7AC3E1F0F33838700B4EC0A</string> + <key>PBXProjectModuleLabel</key> + <string>testApp.cpp</string> + <key>PBXSplitModuleInNavigatorKey</key> + <dict> + <key>Split0</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>B7AC3E200F33838700B4EC0A</string> + <key>PBXProjectModuleLabel</key> + <string>testApp.cpp</string> + <key>_historyCapacity</key> + <integer>0</integer> + <key>bookmark</key> + <string>B7AC3E6E0F338AAD00B4EC0A</string> + <key>history</key> + <array> + <string>B7AC3E350F33885C00B4EC0A</string> + </array> + </dict> + <key>SplitCount</key> + <string>1</string> + </dict> + <key>StatusBarVisibility</key> + <true/> + </dict> + <key>Geometry</key> + <dict> + <key>Frame</key> + <string>{{0, 20}, {1143, 602}}</string> + <key>PBXModuleWindowStatusBarHidden2</key> + <false/> + <key>RubberWindowFrame</key> + <string>558 178 1143 643 0 0 1440 878 </string> + </dict> + </dict> + <dict> + <key>Content</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>B7AC3E370F33885C00B4EC0A</string> + <key>PBXProjectModuleLabel</key> + <string>testApp.h</string> + <key>PBXSplitModuleInNavigatorKey</key> + <dict> + <key>Split0</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>B7AC3E380F33885C00B4EC0A</string> + <key>PBXProjectModuleLabel</key> + <string>testApp.h</string> + <key>_historyCapacity</key> + <integer>0</integer> + <key>bookmark</key> + <string>B7AC3E6F0F338AAD00B4EC0A</string> + <key>history</key> + <array> + <string>B7AC3E2F0F33881D00B4EC0A</string> + </array> + </dict> + <key>SplitCount</key> + <string>1</string> + </dict> + <key>StatusBarVisibility</key> + <true/> + </dict> + <key>Geometry</key> + <dict> + <key>Frame</key> + <string>{{0, 20}, {1143, 602}}</string> + <key>PBXModuleWindowStatusBarHidden2</key> + <false/> + <key>RubberWindowFrame</key> + <string>539 129 1143 643 0 0 1440 878 </string> + </dict> + </dict> + </array> + <key>PerspectiveWidths</key> + <array> + <integer>-1</integer> + <integer>-1</integer> + </array> + <key>Perspectives</key> + <array> + <dict> + <key>ChosenToolbarItems</key> + <array> + <string>active-target-popup</string> + <string>active-buildstyle-popup</string> + <string>action</string> + <string>NSToolbarFlexibleSpaceItem</string> + <string>buildOrClean</string> + <string>build-and-goOrGo</string> + <string>com.apple.ide.PBXToolbarStopButton</string> + <string>get-info</string> + <string>toggle-editor</string> + <string>NSToolbarFlexibleSpaceItem</string> + <string>com.apple.pbx.toolbar.searchfield</string> + </array> + <key>ControllerClassBaseName</key> + <string></string> + <key>IconName</key> + <string>WindowOfProjectWithEditor</string> + <key>Identifier</key> + <string>perspective.project</string> + <key>IsVertical</key> + <false/> + <key>Layout</key> + <array> + <dict> + <key>BecomeActive</key> + <true/> + <key>ContentConfiguration</key> + <dict> + <key>PBXBottomSmartGroupGIDs</key> + <array> + <string>1C37FBAC04509CD000000102</string> + <string>1C37FAAC04509CD000000102</string> + <string>1C08E77C0454961000C914BD</string> + <string>1C37FABC05509CD000000102</string> + <string>1C37FABC05539CD112110102</string> + <string>E2644B35053B69B200211256</string> + <string>1C37FABC04509CD000100104</string> + <string>1CC0EA4004350EF90044410B</string> + <string>1CC0EA4004350EF90041110B</string> + </array> + <key>PBXProjectModuleGUID</key> + <string>1CE0B1FE06471DED0097A5F4</string> + <key>PBXProjectModuleLabel</key> + <string>Files</string> + <key>PBXProjectStructureProvided</key> + <string>yes</string> + <key>PBXSmartGroupTreeModuleColumnData</key> + <dict> + <key>PBXSmartGroupTreeModuleColumnWidthsKey</key> + <array> + <real>186</real> + </array> + <key>PBXSmartGroupTreeModuleColumnsKey_v4</key> + <array> + <string>MainColumn</string> + </array> + </dict> + <key>PBXSmartGroupTreeModuleOutlineStateKey_v7</key> + <dict> + <key>PBXSmartGroupTreeModuleOutlineStateExpansionKey</key> + <array> + <string>E4B69B4A0A3A1720003C02F2</string> + <string>E4B69E1C0A3A1BDC003C02F2</string> + <string>E4B69E160A3A1A8B003C02F2</string> + <string>E411BE010CFA279F007A1F4A</string> + <string>E489A5640DA165C800695191</string> + <string>E489A5890DA165C900695191</string> + <string>1C37FABC05509CD000000102</string> + </array> + <key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key> + <array> + <array> + <integer>3</integer> + <integer>1</integer> + <integer>0</integer> + </array> + </array> + <key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key> + <string>{{0, 0}, {186, 445}}</string> + </dict> + <key>PBXTopSmartGroupGIDs</key> + <array/> + <key>XCIncludePerspectivesSwitch</key> + <true/> + <key>XCSharingToken</key> + <string>com.apple.Xcode.GFSharingToken</string> + </dict> + <key>GeometryConfiguration</key> + <dict> + <key>Frame</key> + <string>{{0, 0}, {203, 463}}</string> + <key>GroupTreeTableConfiguration</key> + <array> + <string>MainColumn</string> + <real>186</real> + </array> + <key>RubberWindowFrame</key> + <string>373 131 788 504 0 0 1440 878 </string> + </dict> + <key>Module</key> + <string>PBXSmartGroupTreeModule</string> + <key>Proportion</key> + <string>203pt</string> + </dict> + <dict> + <key>Dock</key> + <array> + <dict> + <key>ContentConfiguration</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>1CE0B20306471E060097A5F4</string> + <key>PBXProjectModuleLabel</key> + <string>testApp.cpp</string> + <key>PBXSplitModuleInNavigatorKey</key> + <dict> + <key>Split0</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>1CE0B20406471E060097A5F4</string> + <key>PBXProjectModuleLabel</key> + <string>testApp.cpp</string> + <key>_historyCapacity</key> + <integer>0</integer> + <key>bookmark</key> + <string>B7AC3E6D0F338AAD00B4EC0A</string> + <key>history</key> + <array> + <string>B7AC3DF70F3382E900B4EC0A</string> + <string>B7AC3DF80F3382E900B4EC0A</string> + <string>B7AC3E0B0F33831E00B4EC0A</string> + <string>B7AC3E1B0F33838700B4EC0A</string> + <string>B7AC3E330F33885C00B4EC0A</string> + </array> + <key>prevStack</key> + <array> + <string>B7AC3DE70F337FF700B4EC0A</string> + <string>B7AC3DFA0F3382E900B4EC0A</string> + <string>B7AC3DFB0F3382E900B4EC0A</string> + <string>B7AC3DFC0F3382E900B4EC0A</string> + <string>B7AC3DFD0F3382E900B4EC0A</string> + <string>B7AC3DFE0F3382E900B4EC0A</string> + <string>B7AC3DFF0F3382E900B4EC0A</string> + <string>B7AC3E0D0F33831E00B4EC0A</string> + <string>B7AC3E140F33834E00B4EC0A</string> + <string>B7AC3E150F33834E00B4EC0A</string> + <string>B7AC3E160F33834E00B4EC0A</string> + <string>B7AC3E1D0F33838700B4EC0A</string> + </array> + </dict> + <key>SplitCount</key> + <string>1</string> + </dict> + <key>StatusBarVisibility</key> + <true/> + </dict> + <key>GeometryConfiguration</key> + <dict> + <key>Frame</key> + <string>{{0, 0}, {580, 285}}</string> + <key>RubberWindowFrame</key> + <string>373 131 788 504 0 0 1440 878 </string> + </dict> + <key>Module</key> + <string>PBXNavigatorGroup</string> + <key>Proportion</key> + <string>285pt</string> + </dict> + <dict> + <key>ContentConfiguration</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>1CE0B20506471E060097A5F4</string> + <key>PBXProjectModuleLabel</key> + <string>Detail</string> + </dict> + <key>GeometryConfiguration</key> + <dict> + <key>Frame</key> + <string>{{0, 290}, {580, 173}}</string> + <key>RubberWindowFrame</key> + <string>373 131 788 504 0 0 1440 878 </string> + </dict> + <key>Module</key> + <string>XCDetailModule</string> + <key>Proportion</key> + <string>173pt</string> + </dict> + </array> + <key>Proportion</key> + <string>580pt</string> + </dict> + </array> + <key>Name</key> + <string>Project</string> + <key>ServiceClasses</key> + <array> + <string>XCModuleDock</string> + <string>PBXSmartGroupTreeModule</string> + <string>XCModuleDock</string> + <string>PBXNavigatorGroup</string> + <string>XCDetailModule</string> + </array> + <key>TableOfContents</key> + <array> + <string>B7AC3DE90F337FF700B4EC0A</string> + <string>1CE0B1FE06471DED0097A5F4</string> + <string>B7AC3DEA0F337FF700B4EC0A</string> + <string>1CE0B20306471E060097A5F4</string> + <string>1CE0B20506471E060097A5F4</string> + </array> + <key>ToolbarConfiguration</key> + <string>xcode.toolbar.config.defaultV3</string> + </dict> + <dict> + <key>ControllerClassBaseName</key> + <string></string> + <key>IconName</key> + <string>WindowOfProject</string> + <key>Identifier</key> + <string>perspective.morph</string> + <key>IsVertical</key> + <integer>0</integer> + <key>Layout</key> + <array> + <dict> + <key>BecomeActive</key> + <integer>1</integer> + <key>ContentConfiguration</key> + <dict> + <key>PBXBottomSmartGroupGIDs</key> + <array> + <string>1C37FBAC04509CD000000102</string> + <string>1C37FAAC04509CD000000102</string> + <string>1C08E77C0454961000C914BD</string> + <string>1C37FABC05509CD000000102</string> + <string>1C37FABC05539CD112110102</string> + <string>E2644B35053B69B200211256</string> + <string>1C37FABC04509CD000100104</string> + <string>1CC0EA4004350EF90044410B</string> + <string>1CC0EA4004350EF90041110B</string> + </array> + <key>PBXProjectModuleGUID</key> + <string>11E0B1FE06471DED0097A5F4</string> + <key>PBXProjectModuleLabel</key> + <string>Files</string> + <key>PBXProjectStructureProvided</key> + <string>yes</string> + <key>PBXSmartGroupTreeModuleColumnData</key> + <dict> + <key>PBXSmartGroupTreeModuleColumnWidthsKey</key> + <array> + <real>186</real> + </array> + <key>PBXSmartGroupTreeModuleColumnsKey_v4</key> + <array> + <string>MainColumn</string> + </array> + </dict> + <key>PBXSmartGroupTreeModuleOutlineStateKey_v7</key> + <dict> + <key>PBXSmartGroupTreeModuleOutlineStateExpansionKey</key> + <array> + <string>29B97314FDCFA39411CA2CEA</string> + <string>1C37FABC05509CD000000102</string> + </array> + <key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key> + <array> + <array> + <integer>0</integer> + </array> + </array> + <key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key> + <string>{{0, 0}, {186, 337}}</string> + </dict> + <key>PBXTopSmartGroupGIDs</key> + <array/> + <key>XCIncludePerspectivesSwitch</key> + <integer>1</integer> + <key>XCSharingToken</key> + <string>com.apple.Xcode.GFSharingToken</string> + </dict> + <key>GeometryConfiguration</key> + <dict> + <key>Frame</key> + <string>{{0, 0}, {203, 355}}</string> + <key>GroupTreeTableConfiguration</key> + <array> + <string>MainColumn</string> + <real>186</real> + </array> + <key>RubberWindowFrame</key> + <string>373 269 690 397 0 0 1440 878 </string> + </dict> + <key>Module</key> + <string>PBXSmartGroupTreeModule</string> + <key>Proportion</key> + <string>100%</string> + </dict> + </array> + <key>Name</key> + <string>Morph</string> + <key>PreferredWidth</key> + <integer>300</integer> + <key>ServiceClasses</key> + <array> + <string>XCModuleDock</string> + <string>PBXSmartGroupTreeModule</string> + </array> + <key>TableOfContents</key> + <array> + <string>11E0B1FE06471DED0097A5F4</string> + </array> + <key>ToolbarConfiguration</key> + <string>xcode.toolbar.config.default.shortV3</string> + </dict> + </array> + <key>PerspectivesBarVisible</key> + <false/> + <key>ShelfIsVisible</key> + <false/> + <key>SourceDescription</key> + <string>file at '/Developer/Library/PrivateFrameworks/DevToolsInterface.framework/Resources/XCPerspectivesSpecificationMode1.xcperspec'</string> + <key>StatusbarIsVisible</key> + <true/> + <key>TimeStamp</key> + <real>0.0</real> + <key>ToolbarDisplayMode</key> + <integer>1</integer> + <key>ToolbarIsVisible</key> + <true/> + <key>ToolbarSizeMode</key> + <integer>1</integer> + <key>Type</key> + <string>Perspectives</string> + <key>UpdateMessage</key> + <string>The Default Workspace in this version of Xcode now includes support to hide and show the detail view (what has been referred to as the "Metro-Morph" feature). You must discard your current Default Workspace settings and update to the latest Default Workspace in order to gain this feature. Do you wish to update to the latest Workspace defaults for project '%@'?</string> + <key>WindowJustification</key> + <integer>5</integer> + <key>WindowOrderList</key> + <array> + <string>B7AC3E0F0F33831E00B4EC0A</string> + <string>B7AC3E100F33831E00B4EC0A</string> + <string>1CD10A99069EF8BA00B06720</string> + <string>B7AC3DC30F337C0300B4EC0A</string> + <string>1C78EAAD065D492600B07095</string> + <string>B7AC3E370F33885C00B4EC0A</string> + <string>/Users/andersonmiller/Downloads/of_preRelease_v0.05_xcode_FAT/apps/addonsExamples/spatialMediaPixelcolor/openFrameworks.xcodeproj</string> + <string>B7AC3E1F0F33838700B4EC0A</string> + </array> + <key>WindowString</key> + <string>373 131 788 504 0 0 1440 878 </string> + <key>WindowToolsV3</key> + <array> + <dict> + <key>FirstTimeWindowDisplayed</key> + <false/> + <key>Identifier</key> + <string>windowTool.build</string> + <key>IsVertical</key> + <true/> + <key>Layout</key> + <array> + <dict> + <key>Dock</key> + <array> + <dict> + <key>ContentConfiguration</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>1CD0528F0623707200166675</string> + <key>PBXProjectModuleLabel</key> + <string></string> + <key>StatusBarVisibility</key> + <true/> + </dict> + <key>GeometryConfiguration</key> + <dict> + <key>Frame</key> + <string>{{0, 0}, {500, 218}}</string> + <key>RubberWindowFrame</key> + <string>347 289 500 500 0 0 1440 878 </string> + </dict> + <key>Module</key> + <string>PBXNavigatorGroup</string> + <key>Proportion</key> + <string>218pt</string> + </dict> + <dict> + <key>ContentConfiguration</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>XCMainBuildResultsModuleGUID</string> + <key>PBXProjectModuleLabel</key> + <string>Build</string> + <key>XCBuildResultsTrigger_Collapse</key> + <integer>1021</integer> + <key>XCBuildResultsTrigger_Open</key> + <integer>1011</integer> + </dict> + <key>GeometryConfiguration</key> + <dict> + <key>Frame</key> + <string>{{0, 223}, {500, 236}}</string> + <key>RubberWindowFrame</key> + <string>347 289 500 500 0 0 1440 878 </string> + </dict> + <key>Module</key> + <string>PBXBuildResultsModule</string> + <key>Proportion</key> + <string>236pt</string> + </dict> + </array> + <key>Proportion</key> + <string>459pt</string> + </dict> + </array> + <key>Name</key> + <string>Build Results</string> + <key>ServiceClasses</key> + <array> + <string>PBXBuildResultsModule</string> + </array> + <key>StatusbarIsVisible</key> + <true/> + <key>TableOfContents</key> + <array> + <string>B7AC3DC30F337C0300B4EC0A</string> + <string>B7AC3E010F3382E900B4EC0A</string> + <string>1CD0528F0623707200166675</string> + <string>XCMainBuildResultsModuleGUID</string> + </array> + <key>ToolbarConfiguration</key> + <string>xcode.toolbar.config.buildV3</string> + <key>WindowString</key> + <string>347 289 500 500 0 0 1440 878 </string> + <key>WindowToolGUID</key> + <string>B7AC3DC30F337C0300B4EC0A</string> + <key>WindowToolIsVisible</key> + <false/> + </dict> + <dict> + <key>FirstTimeWindowDisplayed</key> + <false/> + <key>Identifier</key> + <string>windowTool.debugger</string> + <key>IsVertical</key> + <true/> + <key>Layout</key> + <array> + <dict> + <key>Dock</key> + <array> + <dict> + <key>ContentConfiguration</key> + <dict> + <key>Debugger</key> + <dict> + <key>HorizontalSplitView</key> + <dict> + <key>_collapsingFrameDimension</key> + <real>0.0</real> + <key>_indexOfCollapsedView</key> + <integer>0</integer> + <key>_percentageOfCollapsedView</key> + <real>0.0</real> + <key>isCollapsed</key> + <string>yes</string> + <key>sizes</key> + <array> + <string>{{0, 0}, {316, 194}}</string> + <string>{{316, 0}, {378, 194}}</string> + </array> + </dict> + <key>VerticalSplitView</key> + <dict> + <key>_collapsingFrameDimension</key> + <real>0.0</real> + <key>_indexOfCollapsedView</key> + <integer>0</integer> + <key>_percentageOfCollapsedView</key> + <real>0.0</real> + <key>isCollapsed</key> + <string>yes</string> + <key>sizes</key> + <array> + <string>{{0, 0}, {694, 194}}</string> + <string>{{0, 194}, {694, 187}}</string> + </array> + </dict> + </dict> + <key>LauncherConfigVersion</key> + <string>8</string> + <key>PBXProjectModuleGUID</key> + <string>1C162984064C10D400B95A72</string> + <key>PBXProjectModuleLabel</key> + <string>Debug - GLUTExamples (Underwater)</string> + </dict> + <key>GeometryConfiguration</key> + <dict> + <key>DebugConsoleVisible</key> + <string>None</string> + <key>DebugConsoleWindowFrame</key> + <string>{{200, 200}, {500, 300}}</string> + <key>DebugSTDIOWindowFrame</key> + <string>{{200, 200}, {500, 300}}</string> + <key>Frame</key> + <string>{{0, 0}, {694, 381}}</string> + <key>PBXDebugSessionStackFrameViewKey</key> + <dict> + <key>DebugVariablesTableConfiguration</key> + <array> + <string>Name</string> + <real>120</real> + <string>Value</string> + <real>85</real> + <string>Summary</string> + <real>148</real> + </array> + <key>Frame</key> + <string>{{316, 0}, {378, 194}}</string> + <key>RubberWindowFrame</key> + <string>347 367 694 422 0 0 1440 878 </string> + </dict> + <key>RubberWindowFrame</key> + <string>347 367 694 422 0 0 1440 878 </string> + </dict> + <key>Module</key> + <string>PBXDebugSessionModule</string> + <key>Proportion</key> + <string>381pt</string> + </dict> + </array> + <key>Proportion</key> + <string>381pt</string> + </dict> + </array> + <key>Name</key> + <string>Debugger</string> + <key>ServiceClasses</key> + <array> + <string>PBXDebugSessionModule</string> + </array> + <key>StatusbarIsVisible</key> + <true/> + <key>TableOfContents</key> + <array> + <string>1CD10A99069EF8BA00B06720</string> + <string>B7AC3E020F3382E900B4EC0A</string> + <string>1C162984064C10D400B95A72</string> + <string>B7AC3E030F3382E900B4EC0A</string> + <string>B7AC3E040F3382E900B4EC0A</string> + <string>B7AC3E050F3382E900B4EC0A</string> + <string>B7AC3E060F3382E900B4EC0A</string> + <string>B7AC3E070F3382E900B4EC0A</string> + </array> + <key>ToolbarConfiguration</key> + <string>xcode.toolbar.config.debugV3</string> + <key>WindowString</key> + <string>347 367 694 422 0 0 1440 878 </string> + <key>WindowToolGUID</key> + <string>1CD10A99069EF8BA00B06720</string> + <key>WindowToolIsVisible</key> + <false/> + </dict> + <dict> + <key>Identifier</key> + <string>windowTool.find</string> + <key>Layout</key> + <array> + <dict> + <key>Dock</key> + <array> + <dict> + <key>Dock</key> + <array> + <dict> + <key>ContentConfiguration</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>1CDD528C0622207200134675</string> + <key>PBXProjectModuleLabel</key> + <string>&lt;No Editor&gt;</string> + <key>PBXSplitModuleInNavigatorKey</key> + <dict> + <key>Split0</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>1CD0528D0623707200166675</string> + </dict> + <key>SplitCount</key> + <string>1</string> + </dict> + <key>StatusBarVisibility</key> + <integer>1</integer> + </dict> + <key>GeometryConfiguration</key> + <dict> + <key>Frame</key> + <string>{{0, 0}, {781, 167}}</string> + <key>RubberWindowFrame</key> + <string>62 385 781 470 0 0 1440 878 </string> + </dict> + <key>Module</key> + <string>PBXNavigatorGroup</string> + <key>Proportion</key> + <string>781pt</string> + </dict> + </array> + <key>Proportion</key> + <string>50%</string> + </dict> + <dict> + <key>BecomeActive</key> + <integer>1</integer> + <key>ContentConfiguration</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>1CD0528E0623707200166675</string> + <key>PBXProjectModuleLabel</key> + <string>Project Find</string> + </dict> + <key>GeometryConfiguration</key> + <dict> + <key>Frame</key> + <string>{{8, 0}, {773, 254}}</string> + <key>RubberWindowFrame</key> + <string>62 385 781 470 0 0 1440 878 </string> + </dict> + <key>Module</key> + <string>PBXProjectFindModule</string> + <key>Proportion</key> + <string>50%</string> + </dict> + </array> + <key>Proportion</key> + <string>428pt</string> + </dict> + </array> + <key>Name</key> + <string>Project Find</string> + <key>ServiceClasses</key> + <array> + <string>PBXProjectFindModule</string> + </array> + <key>StatusbarIsVisible</key> + <integer>1</integer> + <key>TableOfContents</key> + <array> + <string>1C530D57069F1CE1000CFCEE</string> + <string>1C530D58069F1CE1000CFCEE</string> + <string>1C530D59069F1CE1000CFCEE</string> + <string>1CDD528C0622207200134675</string> + <string>1C530D5A069F1CE1000CFCEE</string> + <string>1CE0B1FE06471DED0097A5F4</string> + <string>1CD0528E0623707200166675</string> + </array> + <key>WindowString</key> + <string>62 385 781 470 0 0 1440 878 </string> + <key>WindowToolGUID</key> + <string>1C530D57069F1CE1000CFCEE</string> + <key>WindowToolIsVisible</key> + <integer>0</integer> + </dict> + <dict> + <key>Identifier</key> + <string>MENUSEPARATOR</string> + </dict> + <dict> + <key>FirstTimeWindowDisplayed</key> + <false/> + <key>Identifier</key> + <string>windowTool.debuggerConsole</string> + <key>IsVertical</key> + <true/> + <key>Layout</key> + <array> + <dict> + <key>Dock</key> + <array> + <dict> + <key>BecomeActive</key> + <true/> + <key>ContentConfiguration</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>1C78EAAC065D492600B07095</string> + <key>PBXProjectModuleLabel</key> + <string>Debugger Console</string> + </dict> + <key>GeometryConfiguration</key> + <dict> + <key>Frame</key> + <string>{{0, 0}, {650, 209}}</string> + <key>RubberWindowFrame</key> + <string>915 233 650 250 0 0 1440 878 </string> + </dict> + <key>Module</key> + <string>PBXDebugCLIModule</string> + <key>Proportion</key> + <string>209pt</string> + </dict> + </array> + <key>Proportion</key> + <string>209pt</string> + </dict> + </array> + <key>Name</key> + <string>Debugger Console</string> + <key>ServiceClasses</key> + <array> + <string>PBXDebugCLIModule</string> + </array> + <key>StatusbarIsVisible</key> + <true/> + <key>TableOfContents</key> + <array> + <string>1C78EAAD065D492600B07095</string> + <string>B7AC3E080F3382E900B4EC0A</string> + <string>1C78EAAC065D492600B07095</string> + </array> + <key>ToolbarConfiguration</key> + <string>xcode.toolbar.config.consoleV3</string> + <key>WindowString</key> + <string>915 233 650 250 0 0 1440 878 </string> + <key>WindowToolGUID</key> + <string>1C78EAAD065D492600B07095</string> + <key>WindowToolIsVisible</key> + <true/> + </dict> + <dict> + <key>Identifier</key> + <string>windowTool.snapshots</string> + <key>Layout</key> + <array> + <dict> + <key>Dock</key> + <array> + <dict> + <key>Module</key> + <string>XCSnapshotModule</string> + <key>Proportion</key> + <string>100%</string> + </dict> + </array> + <key>Proportion</key> + <string>100%</string> + </dict> + </array> + <key>Name</key> + <string>Snapshots</string> + <key>ServiceClasses</key> + <array> + <string>XCSnapshotModule</string> + </array> + <key>StatusbarIsVisible</key> + <string>Yes</string> + <key>ToolbarConfiguration</key> + <string>xcode.toolbar.config.snapshots</string> + <key>WindowString</key> + <string>315 824 300 550 0 0 1440 878 </string> + <key>WindowToolIsVisible</key> + <string>Yes</string> + </dict> + <dict> + <key>Identifier</key> + <string>windowTool.scm</string> + <key>Layout</key> + <array> + <dict> + <key>Dock</key> + <array> + <dict> + <key>ContentConfiguration</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>1C78EAB2065D492600B07095</string> + <key>PBXProjectModuleLabel</key> + <string>&lt;No Editor&gt;</string> + <key>PBXSplitModuleInNavigatorKey</key> + <dict> + <key>Split0</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>1C78EAB3065D492600B07095</string> + </dict> + <key>SplitCount</key> + <string>1</string> + </dict> + <key>StatusBarVisibility</key> + <integer>1</integer> + </dict> + <key>GeometryConfiguration</key> + <dict> + <key>Frame</key> + <string>{{0, 0}, {452, 0}}</string> + <key>RubberWindowFrame</key> + <string>743 379 452 308 0 0 1280 1002 </string> + </dict> + <key>Module</key> + <string>PBXNavigatorGroup</string> + <key>Proportion</key> + <string>0pt</string> + </dict> + <dict> + <key>BecomeActive</key> + <integer>1</integer> + <key>ContentConfiguration</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>1CD052920623707200166675</string> + <key>PBXProjectModuleLabel</key> + <string>SCM</string> + </dict> + <key>GeometryConfiguration</key> + <dict> + <key>ConsoleFrame</key> + <string>{{0, 259}, {452, 0}}</string> + <key>Frame</key> + <string>{{0, 7}, {452, 259}}</string> + <key>RubberWindowFrame</key> + <string>743 379 452 308 0 0 1280 1002 </string> + <key>TableConfiguration</key> + <array> + <string>Status</string> + <real>30</real> + <string>FileName</string> + <real>199</real> + <string>Path</string> + <real>197.0950012207031</real> + </array> + <key>TableFrame</key> + <string>{{0, 0}, {452, 250}}</string> + </dict> + <key>Module</key> + <string>PBXCVSModule</string> + <key>Proportion</key> + <string>262pt</string> + </dict> + </array> + <key>Proportion</key> + <string>266pt</string> + </dict> + </array> + <key>Name</key> + <string>SCM</string> + <key>ServiceClasses</key> + <array> + <string>PBXCVSModule</string> + </array> + <key>StatusbarIsVisible</key> + <integer>1</integer> + <key>TableOfContents</key> + <array> + <string>1C78EAB4065D492600B07095</string> + <string>1C78EAB5065D492600B07095</string> + <string>1C78EAB2065D492600B07095</string> + <string>1CD052920623707200166675</string> + </array> + <key>ToolbarConfiguration</key> + <string>xcode.toolbar.config.scm</string> + <key>WindowString</key> + <string>743 379 452 308 0 0 1280 1002 </string> + </dict> + <dict> + <key>Identifier</key> + <string>windowTool.breakpoints</string> + <key>IsVertical</key> + <integer>0</integer> + <key>Layout</key> + <array> + <dict> + <key>Dock</key> + <array> + <dict> + <key>BecomeActive</key> + <integer>1</integer> + <key>ContentConfiguration</key> + <dict> + <key>PBXBottomSmartGroupGIDs</key> + <array> + <string>1C77FABC04509CD000000102</string> + </array> + <key>PBXProjectModuleGUID</key> + <string>1CE0B1FE06471DED0097A5F4</string> + <key>PBXProjectModuleLabel</key> + <string>Files</string> + <key>PBXProjectStructureProvided</key> + <string>no</string> + <key>PBXSmartGroupTreeModuleColumnData</key> + <dict> + <key>PBXSmartGroupTreeModuleColumnWidthsKey</key> + <array> + <real>168</real> + </array> + <key>PBXSmartGroupTreeModuleColumnsKey_v4</key> + <array> + <string>MainColumn</string> + </array> + </dict> + <key>PBXSmartGroupTreeModuleOutlineStateKey_v7</key> + <dict> + <key>PBXSmartGroupTreeModuleOutlineStateExpansionKey</key> + <array> + <string>1C77FABC04509CD000000102</string> + </array> + <key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key> + <array> + <array> + <integer>0</integer> + </array> + </array> + <key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key> + <string>{{0, 0}, {168, 350}}</string> + </dict> + <key>PBXTopSmartGroupGIDs</key> + <array/> + <key>XCIncludePerspectivesSwitch</key> + <integer>0</integer> + </dict> + <key>GeometryConfiguration</key> + <dict> + <key>Frame</key> + <string>{{0, 0}, {185, 368}}</string> + <key>GroupTreeTableConfiguration</key> + <array> + <string>MainColumn</string> + <real>168</real> + </array> + <key>RubberWindowFrame</key> + <string>315 424 744 409 0 0 1440 878 </string> + </dict> + <key>Module</key> + <string>PBXSmartGroupTreeModule</string> + <key>Proportion</key> + <string>185pt</string> + </dict> + <dict> + <key>ContentConfiguration</key> + <dict> + <key>PBXProjectModuleGUID</key> + <string>1CA1AED706398EBD00589147</string> + <key>PBXProjectModuleLabel</key> + <string>Detail</string> + </dict> + <key>GeometryConfiguration</key> + <dict> + <key>Frame</key> + <string>{{190, 0}, {554, 368}}</string> + <key>RubberWindowFrame</key> + <string>315 424 744 409 0 0 1440 878 </string> + </dict> + <key>Module</key> + <string>XCDetailModule</string> + <key>Proportion</key> + <string>554pt</string> + </dict> + </array> + <key>Proportion</key> + <string>368pt</string> + </dict> + </array> + <key>MajorVersion</key> + <integer>3</integer> + <key>MinorVersion</key> + <integer>0</integer> + <key>Name</key> + <string>Breakpoints</string> + <key>ServiceClasses</key> + <array> + <string>PBXSmartGroupTreeModule</string> + <string>XCDetailModule</string> + </array> + <key>StatusbarIsVisible</key> + <integer>1</integer> + <key>TableOfContents</key> + <array> + <string>1CDDB66807F98D9800BB5817</string> + <string>1CDDB66907F98D9800BB5817</string> + <string>1CE0B1FE06471DED0097A5F4</string> + <string>1CA1AED706398EBD00589147</string> + </array> + <key>ToolbarConfiguration</key> + <string>xcode.toolbar.config.breakpointsV3</string> + <key>WindowString</key> + <string>315 424 744 409 0 0 1440 878 </string> + <key>WindowToolGUID</key> + <string>1CDDB66807F98D9800BB5817</string> + <key>WindowToolIsVisible</key> + <integer>1</integer> + </dict> + <dict> + <key>Identifier</key> + <string>windowTool.debugAnimator</string> + <key>Layout</key> + <array> + <dict> + <key>Dock</key> + <array> + <dict> + <key>Module</key> + <string>PBXNavigatorGroup</string> + <key>Proportion</key> + <string>100%</string> + </dict> + </array> + <key>Proportion</key> + <string>100%</string> + </dict> + </array> + <key>Name</key> + <string>Debug Visualizer</string> + <key>ServiceClasses</key> + <array> + <string>PBXNavigatorGroup</string> + </array> + <key>StatusbarIsVisible</key> + <integer>1</integer> + <key>ToolbarConfiguration</key> + <string>xcode.toolbar.config.debugAnimatorV3</string> + <key>WindowString</key> + <string>100 100 700 500 0 0 1280 1002 </string> + </dict> + <dict> + <key>Identifier</key> + <string>windowTool.bookmarks</string> + <key>Layout</key> + <array> + <dict> + <key>Dock</key> + <array> + <dict> + <key>Module</key> + <string>PBXBookmarksModule</string> + <key>Proportion</key> + <string>100%</string> + </dict> + </array> + <key>Proportion</key> + <string>100%</string> + </dict> + </array> + <key>Name</key> + <string>Bookmarks</string> + <key>ServiceClasses</key> + <array> + <string>PBXBookmarksModule</string> + </array> + <key>StatusbarIsVisible</key> + <integer>0</integer> + <key>WindowString</key> + <string>538 42 401 187 0 0 1280 1002 </string> + </dict> + <dict> + <key>Identifier</key> + <string>windowTool.projectFormatConflicts</string> + <key>Layout</key> + <array> + <dict> + <key>Dock</key> + <array> + <dict> + <key>Module</key> + <string>XCProjectFormatConflictsModule</string> + <key>Proportion</key> + <string>100%</string> + </dict> + </array> + <key>Proportion</key> + <string>100%</string> + </dict> + </array> + <key>Name</key> + <string>Project Format Conflicts</string> + <key>ServiceClasses</key> + <array> + <string>XCProjectFormatConflictsModule</string> + </array> + <key>StatusbarIsVisible</key> + <integer>0</integer> + <key>WindowContentMinSize</key> + <string>450 300</string> + <key>WindowString</key> + <string>50 850 472 307 0 0 1440 877</string> + </dict> + <dict> + <key>Identifier</key> + <string>windowTool.classBrowser</string> + <key>Layout</key> + <array> + <dict> + <key>Dock</key> + <array> + <dict> + <key>BecomeActive</key> + <integer>1</integer> + <key>ContentConfiguration</key> + <dict> + <key>OptionsSetName</key> + <string>Hierarchy, all classes</string> + <key>PBXProjectModuleGUID</key> + <string>1CA6456E063B45B4001379D8</string> + <key>PBXProjectModuleLabel</key> + <string>Class Browser - NSObject</string> + </dict> + <key>GeometryConfiguration</key> + <dict> + <key>ClassesFrame</key> + <string>{{0, 0}, {374, 96}}</string> + <key>ClassesTreeTableConfiguration</key> + <array> + <string>PBXClassNameColumnIdentifier</string> + <real>208</real> + <string>PBXClassBookColumnIdentifier</string> + <real>22</real> + </array> + <key>Frame</key> + <string>{{0, 0}, {630, 331}}</string> + <key>MembersFrame</key> + <string>{{0, 105}, {374, 395}}</string> + <key>MembersTreeTableConfiguration</key> + <array> + <string>PBXMemberTypeIconColumnIdentifier</string> + <real>22</real> + <string>PBXMemberNameColumnIdentifier</string> + <real>216</real> + <string>PBXMemberTypeColumnIdentifier</string> + <real>97</real> + <string>PBXMemberBookColumnIdentifier</string> + <real>22</real> + </array> + <key>PBXModuleWindowStatusBarHidden2</key> + <integer>1</integer> + <key>RubberWindowFrame</key> + <string>385 179 630 352 0 0 1440 878 </string> + </dict> + <key>Module</key> + <string>PBXClassBrowserModule</string> + <key>Proportion</key> + <string>332pt</string> + </dict> + </array> + <key>Proportion</key> + <string>332pt</string> + </dict> + </array> + <key>Name</key> + <string>Class Browser</string> + <key>ServiceClasses</key> + <array> + <string>PBXClassBrowserModule</string> + </array> + <key>StatusbarIsVisible</key> + <integer>0</integer> + <key>TableOfContents</key> + <array> + <string>1C0AD2AF069F1E9B00FABCE6</string> + <string>1C0AD2B0069F1E9B00FABCE6</string> + <string>1CA6456E063B45B4001379D8</string> + </array> + <key>ToolbarConfiguration</key> + <string>xcode.toolbar.config.classbrowser</string> + <key>WindowString</key> + <string>385 179 630 352 0 0 1440 878 </string> + <key>WindowToolGUID</key> + <string>1C0AD2AF069F1E9B00FABCE6</string> + <key>WindowToolIsVisible</key> + <integer>0</integer> + </dict> + <dict> + <key>Identifier</key> + <string>windowTool.refactoring</string> + <key>IncludeInToolsMenu</key> + <integer>0</integer> + <key>Layout</key> + <array> + <dict> + <key>Dock</key> + <array> + <dict> + <key>BecomeActive</key> + <integer>1</integer> + <key>GeometryConfiguration</key> + <dict> + <key>Frame</key> + <string>{0, 0}, {500, 335}</string> + <key>RubberWindowFrame</key> + <string>{0, 0}, {500, 335}</string> + </dict> + <key>Module</key> + <string>XCRefactoringModule</string> + <key>Proportion</key> + <string>100%</string> + </dict> + </array> + <key>Proportion</key> + <string>100%</string> + </dict> + </array> + <key>Name</key> + <string>Refactoring</string> + <key>ServiceClasses</key> + <array> + <string>XCRefactoringModule</string> + </array> + <key>WindowString</key> + <string>200 200 500 356 0 0 1920 1200 </string> + </dict> + </array> +</dict> +</plist> diff --git a/pixelColor/openFrameworks.xcodeproj/andersonmiller.pbxuser b/pixelColor/openFrameworks.xcodeproj/andersonmiller.pbxuser new file mode 100644 index 0000000..e9f8d25 --- /dev/null +++ b/pixelColor/openFrameworks.xcodeproj/andersonmiller.pbxuser @@ -0,0 +1,1069 @@ +// !$*UTF8*$! +{ + B7AC3DB60F337B7C00B4EC0A /* openFrameworks */ = { + isa = PBXExecutable; + activeArgIndices = ( + ); + argumentStrings = ( + ); + autoAttachOnCrash = 1; + breakpointsEnabled = 0; + configStateDict = { + }; + customDataFormattersEnabled = 1; + debuggerPlugin = GDBDebugging; + disassemblyDisplayState = 0; + dylibVariantSuffix = ""; + enableDebugStr = 1; + environmentEntries = ( + ); + executableSystemSymbolLevel = 0; + executableUserSymbolLevel = 0; + libgmallocEnabled = 0; + name = openFrameworks; + savedGlobals = { + }; + sourceDirectories = ( + ); + }; + B7AC3DBC0F337B7F00B4EC0A /* Source Control */ = { + isa = PBXSourceControlManager; + fallbackIsa = XCSourceControlManager; + isSCMEnabled = 0; + scmConfiguration = { + }; + }; + B7AC3DBD0F337B7F00B4EC0A /* Code sense */ = { + isa = PBXCodeSenseManager; + indexTemplatePath = ""; + }; + B7AC3DD20F337FCD00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1D0A3A1BDC003C02F2 /* main.cpp */; + name = "main.cpp: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 355; + vrLoc = 0; + }; + B7AC3DDB0F337FE800B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1D0A3A1BDC003C02F2 /* main.cpp */; + name = "main.cpp: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 355; + vrLoc = 0; + }; + B7AC3DE40F337FEE00B4EC0A /* PBXBookmark */ = { + isa = PBXBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + }; + B7AC3DE50F337FF700B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1D0A3A1BDC003C02F2 /* main.cpp */; + name = "main.cpp: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 355; + vrLoc = 0; + }; + B7AC3DE60F337FF700B4EC0A /* PBXBookmark */ = { + isa = PBXBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + }; + B7AC3DE70F337FF700B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1D0A3A1BDC003C02F2 /* main.cpp */; + name = "main.cpp: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 355; + vrLoc = 0; + }; + B7AC3DE80F337FF700B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 327; + vrLoc = 0; + }; + B7AC3DED0F337FF700B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 837; + vrLoc = 99; + }; + B7AC3DF60F3382E900B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 31"; + rLen = 15; + rLoc = 588; + rType = 0; + vrLen = 324; + vrLoc = 376; + }; + B7AC3DF70F3382E900B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E489A58D0DA165C900695191 /* ofxCvColorImage.cpp */; + name = "ofxCvColorImage.cpp: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 517; + vrLoc = 0; + }; + B7AC3DF80F3382E900B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E489A58E0DA165C900695191 /* ofxCvColorImage.h */; + name = "ofxCvColorImage.h: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 332; + vrLoc = 0; + }; + B7AC3DF90F3382E900B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 396; + vrLoc = 0; + }; + B7AC3DFA0F3382E900B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 327; + vrLoc = 0; + }; + B7AC3DFB0F3382E900B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 396; + vrLoc = 0; + }; + B7AC3DFC0F3382E900B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 31"; + rLen = 15; + rLoc = 588; + rType = 0; + vrLen = 324; + vrLoc = 376; + }; + B7AC3DFD0F3382E900B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E489A58D0DA165C900695191 /* ofxCvColorImage.cpp */; + name = "ofxCvColorImage.cpp: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 517; + vrLoc = 0; + }; + B7AC3DFE0F3382E900B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E489A58E0DA165C900695191 /* ofxCvColorImage.h */; + name = "ofxCvColorImage.h: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 332; + vrLoc = 0; + }; + B7AC3DFF0F3382E900B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 396; + vrLoc = 0; + }; + B7AC3E000F3382E900B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1D0A3A1BDC003C02F2 /* main.cpp */; + name = "main.cpp: 7"; + rLen = 0; + rLoc = 165; + rType = 0; + vrLen = 351; + vrLoc = 0; + }; + B7AC3E0B0F33831E00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1D0A3A1BDC003C02F2 /* main.cpp */; + name = "main.cpp: 7"; + rLen = 0; + rLoc = 165; + rType = 0; + vrLen = 351; + vrLoc = 0; + }; + B7AC3E0C0F33831E00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 396; + vrLoc = 0; + }; + B7AC3E0D0F33831E00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1D0A3A1BDC003C02F2 /* main.cpp */; + name = "main.cpp: 7"; + rLen = 0; + rLoc = 165; + rType = 0; + vrLen = 351; + vrLoc = 0; + }; + B7AC3E0E0F33831E00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 49"; + rLen = 0; + rLoc = 1373; + rType = 0; + vrLen = 347; + vrLoc = 797; + }; + B7AC3E120F33834E00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 26"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 439; + vrLoc = 270; + }; + B7AC3E130F33834E00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 34"; + rLen = 0; + rLoc = 700; + rType = 0; + vrLen = 350; + vrLoc = 376; + }; + B7AC3E140F33834E00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 26"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 439; + vrLoc = 270; + }; + B7AC3E150F33834E00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 34"; + rLen = 0; + rLoc = 700; + rType = 0; + vrLen = 350; + vrLoc = 376; + }; + B7AC3E160F33834E00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 26"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 439; + vrLoc = 270; + }; + B7AC3E170F33834E00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 36"; + rLen = 0; + rLoc = 698; + rType = 0; + vrLen = 365; + vrLoc = 376; + }; + B7AC3E190F33835D00B4EC0A /* PBXBookmark */ = { + isa = PBXBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + }; + B7AC3E1B0F33838700B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 36"; + rLen = 0; + rLoc = 698; + rType = 0; + vrLen = 327; + vrLoc = 0; + }; + B7AC3E1C0F33838700B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 26"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 439; + vrLoc = 270; + }; + B7AC3E1D0F33838700B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 36"; + rLen = 0; + rLoc = 698; + rType = 0; + vrLen = 327; + vrLoc = 0; + }; + B7AC3E1E0F33838700B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 30"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 313; + vrLoc = 118; + }; + B7AC3E210F33838700B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 38"; + rLen = 0; + rLoc = 768; + rType = 0; + vrLen = 833; + vrLoc = 153; + }; + B7AC3E230F33841600B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 30"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 313; + vrLoc = 118; + }; + B7AC3E240F33841600B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 54"; + rLen = 0; + rLoc = 1228; + rType = 0; + vrLen = 953; + vrLoc = 597; + }; + B7AC3E260F33844300B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 30"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 313; + vrLoc = 118; + }; + B7AC3E270F33844300B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 40"; + rLen = 0; + rLoc = 883; + rType = 0; + vrLen = 846; + vrLoc = 371; + }; + B7AC3E290F33845600B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 30"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 313; + vrLoc = 118; + }; + B7AC3E2A0F33845600B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 40"; + rLen = 0; + rLoc = 796; + rType = 0; + vrLen = 852; + vrLoc = 371; + }; + B7AC3E2D0F33858500B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 30"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 313; + vrLoc = 118; + }; + B7AC3E2E0F33858500B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 55"; + rLen = 0; + rLoc = 1180; + rType = 0; + vrLen = 1017; + vrLoc = 594; + }; + B7AC3E2F0F33881D00B4EC0A /* PBXBookmark */ = { + isa = PBXBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + }; + B7AC3E330F33885C00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 30"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 305; + vrLoc = 0; + }; + B7AC3E340F33885C00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 31"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 299; + vrLoc = 0; + }; + B7AC3E350F33885C00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 55"; + rLen = 0; + rLoc = 1180; + rType = 0; + vrLen = 983; + vrLoc = 665; + }; + B7AC3E360F33885C00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 18"; + rLen = 0; + rLoc = 323; + rType = 0; + vrLen = 846; + vrLoc = 120; + }; + B7AC3E390F33885C00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 37"; + rLen = 0; + rLoc = 698; + rType = 0; + vrLen = 737; + vrLoc = 19; + }; + B7AC3E3B0F33887000B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 31"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 299; + vrLoc = 0; + }; + B7AC3E3C0F33887000B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 41"; + rLen = 0; + rLoc = 824; + rType = 0; + vrLen = 849; + vrLoc = 120; + }; + B7AC3E3D0F33887000B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 37"; + rLen = 0; + rLoc = 698; + rType = 0; + vrLen = 737; + vrLoc = 19; + }; + B7AC3E400F33888E00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 31"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 299; + vrLoc = 0; + }; + B7AC3E410F33888E00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 43"; + rLen = 0; + rLoc = 883; + rType = 0; + vrLen = 838; + vrLoc = 120; + }; + B7AC3E420F33888E00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 37"; + rLen = 0; + rLoc = 698; + rType = 0; + vrLen = 737; + vrLoc = 19; + }; + B7AC3E440F33889B00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 31"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 299; + vrLoc = 0; + }; + B7AC3E450F33889B00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 42"; + rLen = 0; + rLoc = 853; + rType = 0; + vrLen = 838; + vrLoc = 120; + }; + B7AC3E460F33889B00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 37"; + rLen = 0; + rLoc = 698; + rType = 0; + vrLen = 737; + vrLoc = 19; + }; + B7AC3E480F3388A500B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 31"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 299; + vrLoc = 0; + }; + B7AC3E490F3388A500B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 42"; + rLen = 0; + rLoc = 853; + rType = 0; + vrLen = 838; + vrLoc = 120; + }; + B7AC3E4A0F3388A500B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 37"; + rLen = 0; + rLoc = 698; + rType = 0; + vrLen = 737; + vrLoc = 19; + }; + B7AC3E4C0F3388AD00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 31"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 299; + vrLoc = 0; + }; + B7AC3E4D0F3388AD00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 42"; + rLen = 0; + rLoc = 849; + rType = 0; + vrLen = 838; + vrLoc = 120; + }; + B7AC3E4E0F3388AD00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 37"; + rLen = 0; + rLoc = 698; + rType = 0; + vrLen = 737; + vrLoc = 19; + }; + B7AC3E500F3388BC00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 31"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 299; + vrLoc = 0; + }; + B7AC3E510F3388BC00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 42"; + rLen = 0; + rLoc = 849; + rType = 0; + vrLen = 838; + vrLoc = 120; + }; + B7AC3E520F3388BC00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 37"; + rLen = 0; + rLoc = 698; + rType = 0; + vrLen = 737; + vrLoc = 19; + }; + B7AC3E540F3388F100B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 31"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 299; + vrLoc = 0; + }; + B7AC3E550F3388F100B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 18"; + rLen = 0; + rLoc = 316; + rType = 0; + vrLen = 839; + vrLoc = 120; + }; + B7AC3E560F3388F100B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 37"; + rLen = 0; + rLoc = 698; + rType = 0; + vrLen = 737; + vrLoc = 19; + }; + B7AC3E580F33890800B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 31"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 299; + vrLoc = 0; + }; + B7AC3E590F33890800B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 18"; + rLen = 0; + rLoc = 316; + rType = 0; + vrLen = 838; + vrLoc = 120; + }; + B7AC3E5A0F33890800B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 37"; + rLen = 0; + rLoc = 698; + rType = 0; + vrLen = 737; + vrLoc = 19; + }; + B7AC3E5C0F33896100B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 31"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 299; + vrLoc = 0; + }; + B7AC3E5D0F33896100B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 18"; + rLen = 0; + rLoc = 316; + rType = 0; + vrLen = 839; + vrLoc = 120; + }; + B7AC3E5E0F33896100B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 37"; + rLen = 0; + rLoc = 698; + rType = 0; + vrLen = 737; + vrLoc = 19; + }; + B7AC3E600F33897600B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 31"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 299; + vrLoc = 0; + }; + B7AC3E610F33897600B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 40"; + rLen = 0; + rLoc = 773; + rType = 0; + vrLen = 843; + vrLoc = 120; + }; + B7AC3E620F33897600B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 37"; + rLen = 0; + rLoc = 698; + rType = 0; + vrLen = 737; + vrLoc = 19; + }; + B7AC3E640F3389DF00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 31"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 299; + vrLoc = 0; + }; + B7AC3E650F3389DF00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 18"; + rLen = 0; + rLoc = 316; + rType = 0; + vrLen = 801; + vrLoc = 92; + }; + B7AC3E660F3389DF00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 37"; + rLen = 0; + rLoc = 698; + rType = 0; + vrLen = 737; + vrLoc = 19; + }; + B7AC3E680F338A2000B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 31"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 299; + vrLoc = 0; + }; + B7AC3E690F338A2000B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 18"; + rLen = 0; + rLoc = 316; + rType = 0; + vrLen = 800; + vrLoc = 0; + }; + B7AC3E6A0F338A2000B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 37"; + rLen = 0; + rLoc = 698; + rType = 0; + vrLen = 737; + vrLoc = 19; + }; + B7AC3E6D0F338AAD00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 29"; + rLen = 0; + rLoc = 614; + rType = 0; + vrLen = 328; + vrLoc = 0; + }; + B7AC3E6E0F338AAD00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 34"; + rLen = 7; + rLoc = 695; + rType = 0; + vrLen = 857; + vrLoc = 284; + }; + B7AC3E6F0F338AAD00B4EC0A /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 37"; + rLen = 0; + rLoc = 698; + rType = 0; + vrLen = 737; + vrLoc = 19; + }; + E489A58D0DA165C900695191 /* ofxCvColorImage.cpp */ = { + uiCtxt = { + sepNavIntBoundsRect = "{{0, 0}, {519, 3416}}"; + sepNavSelRange = "{0, 0}"; + sepNavVisRange = "{0, 517}"; + }; + }; + E489A58E0DA165C900695191 /* ofxCvColorImage.h */ = { + uiCtxt = { + sepNavIntBoundsRect = "{{0, 0}, {738, 686}}"; + sepNavSelRange = "{0, 0}"; + sepNavVisRange = "{0, 332}"; + sepNavWindowFrame = "{{84, 111}, {1143, 699}}"; + }; + }; + E4B69B4C0A3A1720003C02F2 /* Project object */ = { + activeBuildConfigurationName = Debug; + activeExecutable = B7AC3DB60F337B7C00B4EC0A /* openFrameworks */; + activeTarget = E4B69B5A0A3A1756003C02F2 /* openFrameworks */; + codeSenseManager = B7AC3DBD0F337B7F00B4EC0A /* Code sense */; + executables = ( + B7AC3DB60F337B7C00B4EC0A /* openFrameworks */, + ); + perUserDictionary = { + PBXConfiguration.PBXFileTableDataSource3.PBXFileTableDataSource = { + PBXFileTableDataSourceColumnSortingDirectionKey = "-1"; + PBXFileTableDataSourceColumnSortingKey = PBXFileDataSource_Filename_ColumnID; + PBXFileTableDataSourceColumnWidthsKey = ( + 20, + 341, + 20, + 48, + 43, + 43, + 20, + ); + PBXFileTableDataSourceColumnsKey = ( + PBXFileDataSource_FiletypeID, + PBXFileDataSource_Filename_ColumnID, + PBXFileDataSource_Built_ColumnID, + PBXFileDataSource_ObjectSize_ColumnID, + PBXFileDataSource_Errors_ColumnID, + PBXFileDataSource_Warnings_ColumnID, + PBXFileDataSource_Target_ColumnID, + ); + }; + PBXPerProjectTemplateStateSaveDate = 255033323; + PBXWorkspaceStateSaveDate = 255033323; + }; + perUserProjectItems = { + B7AC3DD20F337FCD00B4EC0A = B7AC3DD20F337FCD00B4EC0A /* PBXTextBookmark */; + B7AC3DDB0F337FE800B4EC0A = B7AC3DDB0F337FE800B4EC0A /* PBXTextBookmark */; + B7AC3DE40F337FEE00B4EC0A /* PBXBookmark */ = B7AC3DE40F337FEE00B4EC0A /* PBXBookmark */; + B7AC3DE50F337FF700B4EC0A /* PBXTextBookmark */ = B7AC3DE50F337FF700B4EC0A /* PBXTextBookmark */; + B7AC3DE60F337FF700B4EC0A /* PBXBookmark */ = B7AC3DE60F337FF700B4EC0A /* PBXBookmark */; + B7AC3DE70F337FF700B4EC0A /* PBXTextBookmark */ = B7AC3DE70F337FF700B4EC0A /* PBXTextBookmark */; + B7AC3DE80F337FF700B4EC0A /* PBXTextBookmark */ = B7AC3DE80F337FF700B4EC0A /* PBXTextBookmark */; + B7AC3DED0F337FF700B4EC0A /* PBXTextBookmark */ = B7AC3DED0F337FF700B4EC0A /* PBXTextBookmark */; + B7AC3DF60F3382E900B4EC0A /* PBXTextBookmark */ = B7AC3DF60F3382E900B4EC0A /* PBXTextBookmark */; + B7AC3DF70F3382E900B4EC0A /* PBXTextBookmark */ = B7AC3DF70F3382E900B4EC0A /* PBXTextBookmark */; + B7AC3DF80F3382E900B4EC0A /* PBXTextBookmark */ = B7AC3DF80F3382E900B4EC0A /* PBXTextBookmark */; + B7AC3DF90F3382E900B4EC0A /* PBXTextBookmark */ = B7AC3DF90F3382E900B4EC0A /* PBXTextBookmark */; + B7AC3DFA0F3382E900B4EC0A /* PBXTextBookmark */ = B7AC3DFA0F3382E900B4EC0A /* PBXTextBookmark */; + B7AC3DFB0F3382E900B4EC0A /* PBXTextBookmark */ = B7AC3DFB0F3382E900B4EC0A /* PBXTextBookmark */; + B7AC3DFC0F3382E900B4EC0A /* PBXTextBookmark */ = B7AC3DFC0F3382E900B4EC0A /* PBXTextBookmark */; + B7AC3DFD0F3382E900B4EC0A /* PBXTextBookmark */ = B7AC3DFD0F3382E900B4EC0A /* PBXTextBookmark */; + B7AC3DFE0F3382E900B4EC0A /* PBXTextBookmark */ = B7AC3DFE0F3382E900B4EC0A /* PBXTextBookmark */; + B7AC3DFF0F3382E900B4EC0A /* PBXTextBookmark */ = B7AC3DFF0F3382E900B4EC0A /* PBXTextBookmark */; + B7AC3E000F3382E900B4EC0A /* PBXTextBookmark */ = B7AC3E000F3382E900B4EC0A /* PBXTextBookmark */; + B7AC3E0B0F33831E00B4EC0A /* PBXTextBookmark */ = B7AC3E0B0F33831E00B4EC0A /* PBXTextBookmark */; + B7AC3E0C0F33831E00B4EC0A /* PBXTextBookmark */ = B7AC3E0C0F33831E00B4EC0A /* PBXTextBookmark */; + B7AC3E0D0F33831E00B4EC0A /* PBXTextBookmark */ = B7AC3E0D0F33831E00B4EC0A /* PBXTextBookmark */; + B7AC3E0E0F33831E00B4EC0A /* PBXTextBookmark */ = B7AC3E0E0F33831E00B4EC0A /* PBXTextBookmark */; + B7AC3E120F33834E00B4EC0A /* PBXTextBookmark */ = B7AC3E120F33834E00B4EC0A /* PBXTextBookmark */; + B7AC3E130F33834E00B4EC0A /* PBXTextBookmark */ = B7AC3E130F33834E00B4EC0A /* PBXTextBookmark */; + B7AC3E140F33834E00B4EC0A /* PBXTextBookmark */ = B7AC3E140F33834E00B4EC0A /* PBXTextBookmark */; + B7AC3E150F33834E00B4EC0A /* PBXTextBookmark */ = B7AC3E150F33834E00B4EC0A /* PBXTextBookmark */; + B7AC3E160F33834E00B4EC0A /* PBXTextBookmark */ = B7AC3E160F33834E00B4EC0A /* PBXTextBookmark */; + B7AC3E170F33834E00B4EC0A /* PBXTextBookmark */ = B7AC3E170F33834E00B4EC0A /* PBXTextBookmark */; + B7AC3E190F33835D00B4EC0A /* PBXBookmark */ = B7AC3E190F33835D00B4EC0A /* PBXBookmark */; + B7AC3E1B0F33838700B4EC0A /* PBXTextBookmark */ = B7AC3E1B0F33838700B4EC0A /* PBXTextBookmark */; + B7AC3E1C0F33838700B4EC0A /* PBXTextBookmark */ = B7AC3E1C0F33838700B4EC0A /* PBXTextBookmark */; + B7AC3E1D0F33838700B4EC0A /* PBXTextBookmark */ = B7AC3E1D0F33838700B4EC0A /* PBXTextBookmark */; + B7AC3E1E0F33838700B4EC0A /* PBXTextBookmark */ = B7AC3E1E0F33838700B4EC0A /* PBXTextBookmark */; + B7AC3E210F33838700B4EC0A /* PBXTextBookmark */ = B7AC3E210F33838700B4EC0A /* PBXTextBookmark */; + B7AC3E230F33841600B4EC0A /* PBXTextBookmark */ = B7AC3E230F33841600B4EC0A /* PBXTextBookmark */; + B7AC3E240F33841600B4EC0A /* PBXTextBookmark */ = B7AC3E240F33841600B4EC0A /* PBXTextBookmark */; + B7AC3E260F33844300B4EC0A /* PBXTextBookmark */ = B7AC3E260F33844300B4EC0A /* PBXTextBookmark */; + B7AC3E270F33844300B4EC0A /* PBXTextBookmark */ = B7AC3E270F33844300B4EC0A /* PBXTextBookmark */; + B7AC3E290F33845600B4EC0A /* PBXTextBookmark */ = B7AC3E290F33845600B4EC0A /* PBXTextBookmark */; + B7AC3E2A0F33845600B4EC0A /* PBXTextBookmark */ = B7AC3E2A0F33845600B4EC0A /* PBXTextBookmark */; + B7AC3E2D0F33858500B4EC0A /* PBXTextBookmark */ = B7AC3E2D0F33858500B4EC0A /* PBXTextBookmark */; + B7AC3E2E0F33858500B4EC0A /* PBXTextBookmark */ = B7AC3E2E0F33858500B4EC0A /* PBXTextBookmark */; + B7AC3E2F0F33881D00B4EC0A /* PBXBookmark */ = B7AC3E2F0F33881D00B4EC0A /* PBXBookmark */; + B7AC3E330F33885C00B4EC0A /* PBXTextBookmark */ = B7AC3E330F33885C00B4EC0A /* PBXTextBookmark */; + B7AC3E340F33885C00B4EC0A /* PBXTextBookmark */ = B7AC3E340F33885C00B4EC0A /* PBXTextBookmark */; + B7AC3E350F33885C00B4EC0A /* PBXTextBookmark */ = B7AC3E350F33885C00B4EC0A /* PBXTextBookmark */; + B7AC3E360F33885C00B4EC0A /* PBXTextBookmark */ = B7AC3E360F33885C00B4EC0A /* PBXTextBookmark */; + B7AC3E390F33885C00B4EC0A /* PBXTextBookmark */ = B7AC3E390F33885C00B4EC0A /* PBXTextBookmark */; + B7AC3E3B0F33887000B4EC0A /* PBXTextBookmark */ = B7AC3E3B0F33887000B4EC0A /* PBXTextBookmark */; + B7AC3E3C0F33887000B4EC0A /* PBXTextBookmark */ = B7AC3E3C0F33887000B4EC0A /* PBXTextBookmark */; + B7AC3E3D0F33887000B4EC0A /* PBXTextBookmark */ = B7AC3E3D0F33887000B4EC0A /* PBXTextBookmark */; + B7AC3E400F33888E00B4EC0A /* PBXTextBookmark */ = B7AC3E400F33888E00B4EC0A /* PBXTextBookmark */; + B7AC3E410F33888E00B4EC0A /* PBXTextBookmark */ = B7AC3E410F33888E00B4EC0A /* PBXTextBookmark */; + B7AC3E420F33888E00B4EC0A /* PBXTextBookmark */ = B7AC3E420F33888E00B4EC0A /* PBXTextBookmark */; + B7AC3E440F33889B00B4EC0A /* PBXTextBookmark */ = B7AC3E440F33889B00B4EC0A /* PBXTextBookmark */; + B7AC3E450F33889B00B4EC0A /* PBXTextBookmark */ = B7AC3E450F33889B00B4EC0A /* PBXTextBookmark */; + B7AC3E460F33889B00B4EC0A /* PBXTextBookmark */ = B7AC3E460F33889B00B4EC0A /* PBXTextBookmark */; + B7AC3E480F3388A500B4EC0A /* PBXTextBookmark */ = B7AC3E480F3388A500B4EC0A /* PBXTextBookmark */; + B7AC3E490F3388A500B4EC0A /* PBXTextBookmark */ = B7AC3E490F3388A500B4EC0A /* PBXTextBookmark */; + B7AC3E4A0F3388A500B4EC0A /* PBXTextBookmark */ = B7AC3E4A0F3388A500B4EC0A /* PBXTextBookmark */; + B7AC3E4C0F3388AD00B4EC0A /* PBXTextBookmark */ = B7AC3E4C0F3388AD00B4EC0A /* PBXTextBookmark */; + B7AC3E4D0F3388AD00B4EC0A /* PBXTextBookmark */ = B7AC3E4D0F3388AD00B4EC0A /* PBXTextBookmark */; + B7AC3E4E0F3388AD00B4EC0A /* PBXTextBookmark */ = B7AC3E4E0F3388AD00B4EC0A /* PBXTextBookmark */; + B7AC3E500F3388BC00B4EC0A /* PBXTextBookmark */ = B7AC3E500F3388BC00B4EC0A /* PBXTextBookmark */; + B7AC3E510F3388BC00B4EC0A /* PBXTextBookmark */ = B7AC3E510F3388BC00B4EC0A /* PBXTextBookmark */; + B7AC3E520F3388BC00B4EC0A /* PBXTextBookmark */ = B7AC3E520F3388BC00B4EC0A /* PBXTextBookmark */; + B7AC3E540F3388F100B4EC0A /* PBXTextBookmark */ = B7AC3E540F3388F100B4EC0A /* PBXTextBookmark */; + B7AC3E550F3388F100B4EC0A /* PBXTextBookmark */ = B7AC3E550F3388F100B4EC0A /* PBXTextBookmark */; + B7AC3E560F3388F100B4EC0A /* PBXTextBookmark */ = B7AC3E560F3388F100B4EC0A /* PBXTextBookmark */; + B7AC3E580F33890800B4EC0A /* PBXTextBookmark */ = B7AC3E580F33890800B4EC0A /* PBXTextBookmark */; + B7AC3E590F33890800B4EC0A /* PBXTextBookmark */ = B7AC3E590F33890800B4EC0A /* PBXTextBookmark */; + B7AC3E5A0F33890800B4EC0A /* PBXTextBookmark */ = B7AC3E5A0F33890800B4EC0A /* PBXTextBookmark */; + B7AC3E5C0F33896100B4EC0A /* PBXTextBookmark */ = B7AC3E5C0F33896100B4EC0A /* PBXTextBookmark */; + B7AC3E5D0F33896100B4EC0A /* PBXTextBookmark */ = B7AC3E5D0F33896100B4EC0A /* PBXTextBookmark */; + B7AC3E5E0F33896100B4EC0A /* PBXTextBookmark */ = B7AC3E5E0F33896100B4EC0A /* PBXTextBookmark */; + B7AC3E600F33897600B4EC0A /* PBXTextBookmark */ = B7AC3E600F33897600B4EC0A /* PBXTextBookmark */; + B7AC3E610F33897600B4EC0A /* PBXTextBookmark */ = B7AC3E610F33897600B4EC0A /* PBXTextBookmark */; + B7AC3E620F33897600B4EC0A /* PBXTextBookmark */ = B7AC3E620F33897600B4EC0A /* PBXTextBookmark */; + B7AC3E640F3389DF00B4EC0A /* PBXTextBookmark */ = B7AC3E640F3389DF00B4EC0A /* PBXTextBookmark */; + B7AC3E650F3389DF00B4EC0A /* PBXTextBookmark */ = B7AC3E650F3389DF00B4EC0A /* PBXTextBookmark */; + B7AC3E660F3389DF00B4EC0A /* PBXTextBookmark */ = B7AC3E660F3389DF00B4EC0A /* PBXTextBookmark */; + B7AC3E680F338A2000B4EC0A /* PBXTextBookmark */ = B7AC3E680F338A2000B4EC0A /* PBXTextBookmark */; + B7AC3E690F338A2000B4EC0A /* PBXTextBookmark */ = B7AC3E690F338A2000B4EC0A /* PBXTextBookmark */; + B7AC3E6A0F338A2000B4EC0A /* PBXTextBookmark */ = B7AC3E6A0F338A2000B4EC0A /* PBXTextBookmark */; + B7AC3E6D0F338AAD00B4EC0A /* PBXTextBookmark */ = B7AC3E6D0F338AAD00B4EC0A /* PBXTextBookmark */; + B7AC3E6E0F338AAD00B4EC0A /* PBXTextBookmark */ = B7AC3E6E0F338AAD00B4EC0A /* PBXTextBookmark */; + B7AC3E6F0F338AAD00B4EC0A /* PBXTextBookmark */ = B7AC3E6F0F338AAD00B4EC0A /* PBXTextBookmark */; + }; + sourceControlManager = B7AC3DBC0F337B7F00B4EC0A /* Source Control */; + userBuildSettings = { + }; + }; + E4B69B5A0A3A1756003C02F2 /* openFrameworks */ = { + activeExec = 0; + executables = ( + B7AC3DB60F337B7C00B4EC0A /* openFrameworks */, + ); + }; + E4B69E1D0A3A1BDC003C02F2 /* main.cpp */ = { + uiCtxt = { + sepNavIntBoundsRect = "{{0, 0}, {519, 253}}"; + sepNavSelRange = "{165, 0}"; + sepNavVisRange = "{0, 351}"; + sepNavWindowFrame = "{{15, 174}, {1143, 699}}"; + }; + }; + E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */ = { + uiCtxt = { + sepNavIntBoundsRect = "{{0, 0}, {1084, 1106}}"; + sepNavSelRange = "{695, 7}"; + sepNavVisRange = "{284, 857}"; + sepNavWindowFrame = "{{558, 122}, {1143, 699}}"; + }; + }; + E4B69E1F0A3A1BDC003C02F2 /* testApp.h */ = { + uiCtxt = { + sepNavIntBoundsRect = "{{0, 0}, {1084, 644}}"; + sepNavSelRange = "{698, 0}"; + sepNavVisRange = "{19, 737}"; + sepNavWindowFrame = "{{539, 73}, {1143, 699}}"; + }; + }; +} diff --git a/pixelColor/openFrameworks.xcodeproj/project.pbxproj b/pixelColor/openFrameworks.xcodeproj/project.pbxproj new file mode 100644 index 0000000..59a9a7a --- /dev/null +++ b/pixelColor/openFrameworks.xcodeproj/project.pbxproj @@ -0,0 +1,573 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 42; + objects = { + +/* Begin PBXBuildFile section */ + E43121A80C7DEC2700E7BC7C /* ofAppRunner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43121860C7DEC2700E7BC7C /* ofAppRunner.cpp */; }; + E43121A90C7DEC2700E7BC7C /* ofSerial.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E431218A0C7DEC2700E7BC7C /* ofSerial.cpp */; }; + E43121AA0C7DEC2700E7BC7C /* ofGraphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E431218D0C7DEC2700E7BC7C /* ofGraphics.cpp */; }; + E43121AB0C7DEC2700E7BC7C /* ofImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E431218F0C7DEC2700E7BC7C /* ofImage.cpp */; }; + E43121AC0C7DEC2700E7BC7C /* ofTexture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43121910C7DEC2700E7BC7C /* ofTexture.cpp */; }; + E43121AD0C7DEC2700E7BC7C /* ofTrueTypeFont.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43121930C7DEC2700E7BC7C /* ofTrueTypeFont.cpp */; }; + E43121AE0C7DEC2700E7BC7C /* ofSoundPlayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43121970C7DEC2700E7BC7C /* ofSoundPlayer.cpp */; }; + E43121AF0C7DEC2700E7BC7C /* ofSoundStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43121990C7DEC2700E7BC7C /* ofSoundStream.cpp */; }; + E43121B00C7DEC2700E7BC7C /* ofMath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E431219D0C7DEC2700E7BC7C /* ofMath.cpp */; }; + E43121B10C7DEC2700E7BC7C /* ofUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E431219F0C7DEC2700E7BC7C /* ofUtils.cpp */; }; + E43121B20C7DEC2700E7BC7C /* ofQtUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43121A20C7DEC2700E7BC7C /* ofQtUtils.cpp */; }; + E43121B30C7DEC2700E7BC7C /* ofVideoGrabber.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43121A40C7DEC2700E7BC7C /* ofVideoGrabber.cpp */; }; + E43121B40C7DEC2700E7BC7C /* ofVideoPlayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43121A60C7DEC2700E7BC7C /* ofVideoPlayer.cpp */; }; + E489A5A50DA165C900695191 /* ofxCvColorImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E489A58D0DA165C900695191 /* ofxCvColorImage.cpp */; }; + E489A5A60DA165C900695191 /* ofxCvContourFinder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E489A5900DA165C900695191 /* ofxCvContourFinder.cpp */; }; + E489A5A70DA165C900695191 /* ofxCvFloatImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E489A5920DA165C900695191 /* ofxCvFloatImage.cpp */; }; + E489A5A80DA165C900695191 /* ofxCvGrayscaleImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E489A5940DA165C900695191 /* ofxCvGrayscaleImage.cpp */; }; + E489A5A90DA165C900695191 /* ofxCvImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E489A5960DA165C900695191 /* ofxCvImage.cpp */; }; + E4B69E200A3A1BDC003C02F2 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B69E1D0A3A1BDC003C02F2 /* main.cpp */; }; + E4B69E210A3A1BDC003C02F2 /* testApp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; }; + E4B6FCAE0C3E899E008CF71C /* openFrameworks-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = E4B6FCAD0C3E899E008CF71C /* openFrameworks-Info.plist */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + E411BE020CFA279F007A1F4A /* ofAddons.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofAddons.h; path = ../../../addons/ofAddons.h; sourceTree = SOURCE_ROOT; }; + E43121850C7DEC2700E7BC7C /* ofAppGlutGlue.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofAppGlutGlue.h; path = ../../../libs/openFrameworks/app/ofAppGlutGlue.h; sourceTree = SOURCE_ROOT; }; + E43121860C7DEC2700E7BC7C /* ofAppRunner.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ofAppRunner.cpp; path = ../../../libs/openFrameworks/app/ofAppRunner.cpp; sourceTree = SOURCE_ROOT; }; + E43121870C7DEC2700E7BC7C /* ofAppRunner.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofAppRunner.h; path = ../../../libs/openFrameworks/app/ofAppRunner.h; sourceTree = SOURCE_ROOT; }; + E43121880C7DEC2700E7BC7C /* ofSimpleApp.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofSimpleApp.h; path = ../../../libs/openFrameworks/app/ofSimpleApp.h; sourceTree = SOURCE_ROOT; }; + E431218A0C7DEC2700E7BC7C /* ofSerial.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ofSerial.cpp; path = ../../../libs/openFrameworks/communication/ofSerial.cpp; sourceTree = SOURCE_ROOT; }; + E431218B0C7DEC2700E7BC7C /* ofSerial.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofSerial.h; path = ../../../libs/openFrameworks/communication/ofSerial.h; sourceTree = SOURCE_ROOT; }; + E431218D0C7DEC2700E7BC7C /* ofGraphics.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ofGraphics.cpp; path = ../../../libs/openFrameworks/graphics/ofGraphics.cpp; sourceTree = SOURCE_ROOT; }; + E431218E0C7DEC2700E7BC7C /* ofGraphics.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofGraphics.h; path = ../../../libs/openFrameworks/graphics/ofGraphics.h; sourceTree = SOURCE_ROOT; }; + E431218F0C7DEC2700E7BC7C /* ofImage.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ofImage.cpp; path = ../../../libs/openFrameworks/graphics/ofImage.cpp; sourceTree = SOURCE_ROOT; }; + E43121900C7DEC2700E7BC7C /* ofImage.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofImage.h; path = ../../../libs/openFrameworks/graphics/ofImage.h; sourceTree = SOURCE_ROOT; }; + E43121910C7DEC2700E7BC7C /* ofTexture.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ofTexture.cpp; path = ../../../libs/openFrameworks/graphics/ofTexture.cpp; sourceTree = SOURCE_ROOT; }; + E43121920C7DEC2700E7BC7C /* ofTexture.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofTexture.h; path = ../../../libs/openFrameworks/graphics/ofTexture.h; sourceTree = SOURCE_ROOT; }; + E43121930C7DEC2700E7BC7C /* ofTrueTypeFont.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ofTrueTypeFont.cpp; path = ../../../libs/openFrameworks/graphics/ofTrueTypeFont.cpp; sourceTree = SOURCE_ROOT; }; + E43121940C7DEC2700E7BC7C /* ofTrueTypefont.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofTrueTypefont.h; path = ../../../libs/openFrameworks/graphics/ofTrueTypefont.h; sourceTree = SOURCE_ROOT; }; + E43121950C7DEC2700E7BC7C /* ofMain.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofMain.h; path = ../../../libs/openFrameworks/ofMain.h; sourceTree = SOURCE_ROOT; }; + E43121970C7DEC2700E7BC7C /* ofSoundPlayer.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ofSoundPlayer.cpp; path = ../../../libs/openFrameworks/sound/ofSoundPlayer.cpp; sourceTree = SOURCE_ROOT; }; + E43121980C7DEC2700E7BC7C /* ofSoundPlayer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofSoundPlayer.h; path = ../../../libs/openFrameworks/sound/ofSoundPlayer.h; sourceTree = SOURCE_ROOT; }; + E43121990C7DEC2700E7BC7C /* ofSoundStream.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ofSoundStream.cpp; path = ../../../libs/openFrameworks/sound/ofSoundStream.cpp; sourceTree = SOURCE_ROOT; }; + E431219A0C7DEC2700E7BC7C /* ofSoundStream.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofSoundStream.h; path = ../../../libs/openFrameworks/sound/ofSoundStream.h; sourceTree = SOURCE_ROOT; }; + E431219C0C7DEC2700E7BC7C /* ofConstants.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofConstants.h; path = ../../../libs/openFrameworks/utils/ofConstants.h; sourceTree = SOURCE_ROOT; }; + E431219D0C7DEC2700E7BC7C /* ofMath.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ofMath.cpp; path = ../../../libs/openFrameworks/utils/ofMath.cpp; sourceTree = SOURCE_ROOT; }; + E431219E0C7DEC2700E7BC7C /* ofMath.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofMath.h; path = ../../../libs/openFrameworks/utils/ofMath.h; sourceTree = SOURCE_ROOT; }; + E431219F0C7DEC2700E7BC7C /* ofUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ofUtils.cpp; path = ../../../libs/openFrameworks/utils/ofUtils.cpp; sourceTree = SOURCE_ROOT; }; + E43121A00C7DEC2700E7BC7C /* ofUtils.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofUtils.h; path = ../../../libs/openFrameworks/utils/ofUtils.h; sourceTree = SOURCE_ROOT; }; + E43121A20C7DEC2700E7BC7C /* ofQtUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ofQtUtils.cpp; path = ../../../libs/openFrameworks/video/ofQtUtils.cpp; sourceTree = SOURCE_ROOT; }; + E43121A30C7DEC2700E7BC7C /* ofQtUtils.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofQtUtils.h; path = ../../../libs/openFrameworks/video/ofQtUtils.h; sourceTree = SOURCE_ROOT; }; + E43121A40C7DEC2700E7BC7C /* ofVideoGrabber.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ofVideoGrabber.cpp; path = ../../../libs/openFrameworks/video/ofVideoGrabber.cpp; sourceTree = SOURCE_ROOT; }; + E43121A50C7DEC2700E7BC7C /* ofVideoGrabber.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofVideoGrabber.h; path = ../../../libs/openFrameworks/video/ofVideoGrabber.h; sourceTree = SOURCE_ROOT; }; + E43121A60C7DEC2700E7BC7C /* ofVideoPlayer.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ofVideoPlayer.cpp; path = ../../../libs/openFrameworks/video/ofVideoPlayer.cpp; sourceTree = SOURCE_ROOT; }; + E43121A70C7DEC2700E7BC7C /* ofVideoPlayer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofVideoPlayer.h; path = ../../../libs/openFrameworks/video/ofVideoPlayer.h; sourceTree = SOURCE_ROOT; }; + E489A58D0DA165C900695191 /* ofxCvColorImage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ofxCvColorImage.cpp; path = ../../../addons/ofxOpenCv/src/ofxCvColorImage.cpp; sourceTree = SOURCE_ROOT; }; + E489A58E0DA165C900695191 /* ofxCvColorImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ofxCvColorImage.h; path = ../../../addons/ofxOpenCv/src/ofxCvColorImage.h; sourceTree = SOURCE_ROOT; }; + E489A58F0DA165C900695191 /* ofxCvConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ofxCvConstants.h; path = ../../../addons/ofxOpenCv/src/ofxCvConstants.h; sourceTree = SOURCE_ROOT; }; + E489A5900DA165C900695191 /* ofxCvContourFinder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ofxCvContourFinder.cpp; path = ../../../addons/ofxOpenCv/src/ofxCvContourFinder.cpp; sourceTree = SOURCE_ROOT; }; + E489A5910DA165C900695191 /* ofxCvContourFinder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ofxCvContourFinder.h; path = ../../../addons/ofxOpenCv/src/ofxCvContourFinder.h; sourceTree = SOURCE_ROOT; }; + E489A5920DA165C900695191 /* ofxCvFloatImage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ofxCvFloatImage.cpp; path = ../../../addons/ofxOpenCv/src/ofxCvFloatImage.cpp; sourceTree = SOURCE_ROOT; }; + E489A5930DA165C900695191 /* ofxCvFloatImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ofxCvFloatImage.h; path = ../../../addons/ofxOpenCv/src/ofxCvFloatImage.h; sourceTree = SOURCE_ROOT; }; + E489A5940DA165C900695191 /* ofxCvGrayscaleImage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ofxCvGrayscaleImage.cpp; path = ../../../addons/ofxOpenCv/src/ofxCvGrayscaleImage.cpp; sourceTree = SOURCE_ROOT; }; + E489A5950DA165C900695191 /* ofxCvGrayscaleImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ofxCvGrayscaleImage.h; path = ../../../addons/ofxOpenCv/src/ofxCvGrayscaleImage.h; sourceTree = SOURCE_ROOT; }; + E489A5960DA165C900695191 /* ofxCvImage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ofxCvImage.cpp; path = ../../../addons/ofxOpenCv/src/ofxCvImage.cpp; sourceTree = SOURCE_ROOT; }; + E489A5970DA165C900695191 /* ofxCvImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ofxCvImage.h; path = ../../../addons/ofxOpenCv/src/ofxCvImage.h; sourceTree = SOURCE_ROOT; }; + E489A5980DA165C900695191 /* ofxCvMain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ofxCvMain.h; path = ../../../addons/ofxOpenCv/src/ofxCvMain.h; sourceTree = SOURCE_ROOT; }; + E489A6370DA1691A00695191 /* ofxCvBlob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ofxCvBlob.h; path = ../../../addons/ofxOpenCv/src/ofxCvBlob.h; sourceTree = SOURCE_ROOT; }; + E4B69B5B0A3A1756003C02F2 /* openFrameworksDebug.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = openFrameworksDebug.app; sourceTree = BUILT_PRODUCTS_DIR; }; + E4B69E1D0A3A1BDC003C02F2 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = main.cpp; path = src/main.cpp; sourceTree = SOURCE_ROOT; }; + E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = testApp.cpp; path = src/testApp.cpp; sourceTree = SOURCE_ROOT; }; + E4B69E1F0A3A1BDC003C02F2 /* testApp.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = testApp.h; path = src/testApp.h; sourceTree = SOURCE_ROOT; }; + E4B6FCAD0C3E899E008CF71C /* openFrameworks-Info.plist */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.plist.xml; path = "openFrameworks-Info.plist"; sourceTree = SOURCE_ROOT; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + E4B69B590A3A1756003C02F2 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + E411BE010CFA279F007A1F4A /* addons */ = { + isa = PBXGroup; + children = ( + E411BE020CFA279F007A1F4A /* ofAddons.h */, + E489A5640DA165C800695191 /* ofxOpenCv */, + ); + name = addons; + path = ../../../addons; + sourceTree = SOURCE_ROOT; + }; + E43121830C7DEC2700E7BC7C /* openFrameworks */ = { + isa = PBXGroup; + children = ( + E43121950C7DEC2700E7BC7C /* ofMain.h */, + E43121840C7DEC2700E7BC7C /* app */, + E43121890C7DEC2700E7BC7C /* communication */, + E431218C0C7DEC2700E7BC7C /* graphics */, + E43121960C7DEC2700E7BC7C /* sound */, + E431219B0C7DEC2700E7BC7C /* utils */, + E43121A10C7DEC2700E7BC7C /* video */, + ); + name = openFrameworks; + path = ../../../libs/openFrameworks; + sourceTree = SOURCE_ROOT; + }; + E43121840C7DEC2700E7BC7C /* app */ = { + isa = PBXGroup; + children = ( + E43121850C7DEC2700E7BC7C /* ofAppGlutGlue.h */, + E43121860C7DEC2700E7BC7C /* ofAppRunner.cpp */, + E43121870C7DEC2700E7BC7C /* ofAppRunner.h */, + E43121880C7DEC2700E7BC7C /* ofSimpleApp.h */, + ); + name = app; + path = ../../../libs/openFrameworks/app; + sourceTree = SOURCE_ROOT; + }; + E43121890C7DEC2700E7BC7C /* communication */ = { + isa = PBXGroup; + children = ( + E431218A0C7DEC2700E7BC7C /* ofSerial.cpp */, + E431218B0C7DEC2700E7BC7C /* ofSerial.h */, + ); + name = communication; + path = ../../../libs/openFrameworks/communication; + sourceTree = SOURCE_ROOT; + }; + E431218C0C7DEC2700E7BC7C /* graphics */ = { + isa = PBXGroup; + children = ( + E431218D0C7DEC2700E7BC7C /* ofGraphics.cpp */, + E431218E0C7DEC2700E7BC7C /* ofGraphics.h */, + E431218F0C7DEC2700E7BC7C /* ofImage.cpp */, + E43121900C7DEC2700E7BC7C /* ofImage.h */, + E43121910C7DEC2700E7BC7C /* ofTexture.cpp */, + E43121920C7DEC2700E7BC7C /* ofTexture.h */, + E43121930C7DEC2700E7BC7C /* ofTrueTypeFont.cpp */, + E43121940C7DEC2700E7BC7C /* ofTrueTypefont.h */, + ); + name = graphics; + path = ../../../libs/openFrameworks/graphics; + sourceTree = SOURCE_ROOT; + }; + E43121960C7DEC2700E7BC7C /* sound */ = { + isa = PBXGroup; + children = ( + E43121970C7DEC2700E7BC7C /* ofSoundPlayer.cpp */, + E43121980C7DEC2700E7BC7C /* ofSoundPlayer.h */, + E43121990C7DEC2700E7BC7C /* ofSoundStream.cpp */, + E431219A0C7DEC2700E7BC7C /* ofSoundStream.h */, + ); + name = sound; + path = ../../../libs/openFrameworks/sound; + sourceTree = SOURCE_ROOT; + }; + E431219B0C7DEC2700E7BC7C /* utils */ = { + isa = PBXGroup; + children = ( + E431219C0C7DEC2700E7BC7C /* ofConstants.h */, + E431219D0C7DEC2700E7BC7C /* ofMath.cpp */, + E431219E0C7DEC2700E7BC7C /* ofMath.h */, + E431219F0C7DEC2700E7BC7C /* ofUtils.cpp */, + E43121A00C7DEC2700E7BC7C /* ofUtils.h */, + ); + name = utils; + path = ../../../libs/openFrameworks/utils; + sourceTree = SOURCE_ROOT; + }; + E43121A10C7DEC2700E7BC7C /* video */ = { + isa = PBXGroup; + children = ( + E43121A20C7DEC2700E7BC7C /* ofQtUtils.cpp */, + E43121A30C7DEC2700E7BC7C /* ofQtUtils.h */, + E43121A40C7DEC2700E7BC7C /* ofVideoGrabber.cpp */, + E43121A50C7DEC2700E7BC7C /* ofVideoGrabber.h */, + E43121A60C7DEC2700E7BC7C /* ofVideoPlayer.cpp */, + E43121A70C7DEC2700E7BC7C /* ofVideoPlayer.h */, + ); + name = video; + path = ../../../libs/openFrameworks/video; + sourceTree = SOURCE_ROOT; + }; + E489A5640DA165C800695191 /* ofxOpenCv */ = { + isa = PBXGroup; + children = ( + E489A5890DA165C900695191 /* src */, + ); + path = ofxOpenCv; + sourceTree = "<group>"; + }; + E489A5890DA165C900695191 /* src */ = { + isa = PBXGroup; + children = ( + E489A6370DA1691A00695191 /* ofxCvBlob.h */, + E489A58D0DA165C900695191 /* ofxCvColorImage.cpp */, + E489A58E0DA165C900695191 /* ofxCvColorImage.h */, + E489A58F0DA165C900695191 /* ofxCvConstants.h */, + E489A5900DA165C900695191 /* ofxCvContourFinder.cpp */, + E489A5910DA165C900695191 /* ofxCvContourFinder.h */, + E489A5920DA165C900695191 /* ofxCvFloatImage.cpp */, + E489A5930DA165C900695191 /* ofxCvFloatImage.h */, + E489A5940DA165C900695191 /* ofxCvGrayscaleImage.cpp */, + E489A5950DA165C900695191 /* ofxCvGrayscaleImage.h */, + E489A5960DA165C900695191 /* ofxCvImage.cpp */, + E489A5970DA165C900695191 /* ofxCvImage.h */, + E489A5980DA165C900695191 /* ofxCvMain.h */, + ); + name = src; + path = ../../../addons/ofxOpenCv/src; + sourceTree = SOURCE_ROOT; + }; + E4B69B4A0A3A1720003C02F2 = { + isa = PBXGroup; + children = ( + E4B69E1C0A3A1BDC003C02F2 /* src */, + E4B69E160A3A1A8B003C02F2 /* libs */, + F5C26FB40D9AF9EC00D485F4 /* plist */, + E4B69B5C0A3A1756003C02F2 /* Products */, + ); + sourceTree = "<group>"; + }; + E4B69B5C0A3A1756003C02F2 /* Products */ = { + isa = PBXGroup; + children = ( + E4B69B5B0A3A1756003C02F2 /* openFrameworksDebug.app */, + ); + name = Products; + sourceTree = "<group>"; + }; + E4B69E160A3A1A8B003C02F2 /* libs */ = { + isa = PBXGroup; + children = ( + E43121830C7DEC2700E7BC7C /* openFrameworks */, + E411BE010CFA279F007A1F4A /* addons */, + ); + name = libs; + sourceTree = "<group>"; + }; + E4B69E1C0A3A1BDC003C02F2 /* src */ = { + isa = PBXGroup; + children = ( + E4B69E1D0A3A1BDC003C02F2 /* main.cpp */, + E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */, + E4B69E1F0A3A1BDC003C02F2 /* testApp.h */, + ); + path = src; + sourceTree = SOURCE_ROOT; + }; + F5C26FB40D9AF9EC00D485F4 /* plist */ = { + isa = PBXGroup; + children = ( + E4B6FCAD0C3E899E008CF71C /* openFrameworks-Info.plist */, + ); + name = plist; + path = src; + sourceTree = "<group>"; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + E4B69B5A0A3A1756003C02F2 /* openFrameworks */ = { + isa = PBXNativeTarget; + buildConfigurationList = E4B69B5F0A3A1757003C02F2 /* Build configuration list for PBXNativeTarget "openFrameworks" */; + buildPhases = ( + E4B69B570A3A1756003C02F2 /* Resources */, + E4B69B580A3A1756003C02F2 /* Sources */, + E4B69B590A3A1756003C02F2 /* Frameworks */, + E4B6FFFD0C3F9AB9008CF71C /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = openFrameworks; + productName = myOFApp; + productReference = E4B69B5B0A3A1756003C02F2 /* openFrameworksDebug.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + E4B69B4C0A3A1720003C02F2 /* Project object */ = { + isa = PBXProject; + buildConfigurationList = E4B69B4D0A3A1720003C02F2 /* Build configuration list for PBXProject "openFrameworks" */; + compatibilityVersion = "Xcode 2.4"; + hasScannedForEncodings = 0; + mainGroup = E4B69B4A0A3A1720003C02F2; + productRefGroup = E4B69B5C0A3A1756003C02F2 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + E4B69B5A0A3A1756003C02F2 /* openFrameworks */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + E4B69B570A3A1756003C02F2 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E4B6FCAE0C3E899E008CF71C /* openFrameworks-Info.plist in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + E4B6FFFD0C3F9AB9008CF71C /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "cp -f ../../../libs/fmodex/lib/libfmodex.dylib \"$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/libfmodex.dylib\"\ninstall_name_tool -change ./libfmodex.dylib @executable_path/libfmodex.dylib \"$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME\" "; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + E4B69B580A3A1756003C02F2 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E4B69E200A3A1BDC003C02F2 /* main.cpp in Sources */, + E4B69E210A3A1BDC003C02F2 /* testApp.cpp in Sources */, + E43121A80C7DEC2700E7BC7C /* ofAppRunner.cpp in Sources */, + E43121A90C7DEC2700E7BC7C /* ofSerial.cpp in Sources */, + E43121AA0C7DEC2700E7BC7C /* ofGraphics.cpp in Sources */, + E43121AB0C7DEC2700E7BC7C /* ofImage.cpp in Sources */, + E43121AC0C7DEC2700E7BC7C /* ofTexture.cpp in Sources */, + E43121AD0C7DEC2700E7BC7C /* ofTrueTypeFont.cpp in Sources */, + E43121AE0C7DEC2700E7BC7C /* ofSoundPlayer.cpp in Sources */, + E43121AF0C7DEC2700E7BC7C /* ofSoundStream.cpp in Sources */, + E43121B00C7DEC2700E7BC7C /* ofMath.cpp in Sources */, + E43121B10C7DEC2700E7BC7C /* ofUtils.cpp in Sources */, + E43121B20C7DEC2700E7BC7C /* ofQtUtils.cpp in Sources */, + E43121B30C7DEC2700E7BC7C /* ofVideoGrabber.cpp in Sources */, + E43121B40C7DEC2700E7BC7C /* ofVideoPlayer.cpp in Sources */, + E489A5A50DA165C900695191 /* ofxCvColorImage.cpp in Sources */, + E489A5A60DA165C900695191 /* ofxCvContourFinder.cpp in Sources */, + E489A5A70DA165C900695191 /* ofxCvFloatImage.cpp in Sources */, + E489A5A80DA165C900695191 /* ofxCvGrayscaleImage.cpp in Sources */, + E489A5A90DA165C900695191 /* ofxCvImage.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + E4B69B4E0A3A1720003C02F2 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(NATIVE_ARCH)"; + CONFIGURATION_BUILD_DIR = "$(SRCROOT)"; + COPY_PHASE_STRIP = NO; + GCC_INLINES_ARE_PRIVATE_EXTERN = NO; + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO; + GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = NO; + GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = NO; + HEADER_SEARCH_PATHS = ( + ../../../libs/fmodex/inc, + "../../../libs/openFrameworks/**", + "../../../libs/freeimage/include/**", + "../../../libs/freetype/include/**", + ../../../libs/GLee/include, + ../../../libs/rtAudio/include, + "../../../addons/ofxOsc/libs/oscpack/include//**", + ../../../addons/ofxOpenCv/libs/opencv/include, + ); + OTHER_CPLUSPLUSFLAGS = ( + "-D__MACOSX_CORE__", + "-lpthread", + ); + OTHER_LDFLAGS = ( + ../../../libs/freetype/lib/freetype.a, + ../../../libs/freeimage/lib/freeimage.a, + ../../../libs/fmodex/lib/libfmodex.dylib, + ../../../libs/GLee/lib/GLee.a, + ../../../libs/rtAudio/lib/rtAudio.a, + "-framework", + Carbon, + "-framework", + GLUT, + "-framework", + CoreFoundation, + "-framework", + OpenGL, + "-framework", + QuickTime, + "-framework", + ApplicationServices, + "-framework", + AudioToolbox, + "-framework", + CoreAudio, + "-framework", + CoreServices, + "-framework", + AGL, + ../../../addons/ofxOpenCv/libs/opencv/lib/osx/libOpenCV.a, + ../../../addons/ofxOsc/libs/oscpack/lib/osx/libOsc.a, + ); + SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk; + }; + name = Debug; + }; + E4B69B4F0A3A1720003C02F2 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = ( + ppc, + i386, + ); + CONFIGURATION_BUILD_DIR = "$(SRCROOT)"; + COPY_PHASE_STRIP = YES; + GCC_INLINES_ARE_PRIVATE_EXTERN = NO; + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO; + GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = NO; + GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = NO; + HEADER_SEARCH_PATHS = ( + ../../../libs/fmodex/inc, + "../../../libs/openFrameworks/**", + "../../../libs/freeimage/include/**", + "../../../libs/freetype/include/**", + ../../../libs/GLee/include, + ../../../libs/rtAudio/include, + "../../../addons/ofxOsc/libs/oscpack/include//**", + ../../../addons/ofxOpenCv/libs/opencv/include, + ); + OTHER_CPLUSPLUSFLAGS = ( + "-D__MACOSX_CORE__", + "-lpthread", + ); + OTHER_LDFLAGS = ( + ../../../libs/freetype/lib/freetype.a, + ../../../libs/freeimage/lib/freeimage.a, + ../../../libs/fmodex/lib/libfmodex.dylib, + ../../../libs/GLee/lib/GLee.a, + ../../../libs/rtAudio/lib/rtAudio.a, + "-framework", + Carbon, + "-framework", + GLUT, + "-framework", + CoreFoundation, + "-framework", + OpenGL, + "-framework", + QuickTime, + "-framework", + ApplicationServices, + "-framework", + AudioToolbox, + "-framework", + CoreAudio, + "-framework", + CoreServices, + "-framework", + AGL, + ../../../addons/ofxOpenCv/libs/opencv/lib/osx/libOpenCV.a, + ../../../addons/ofxOsc/libs/oscpack/lib/osx/libOsc.a, + ); + SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk; + }; + name = Release; + }; + E4B69B600A3A1757003C02F2 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COPY_PHASE_STRIP = NO; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_FIX_AND_CONTINUE = YES; + GCC_GENERATE_DEBUGGING_SYMBOLS = YES; + GCC_MODEL_TUNING = G4; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/Carbon.framework/Headers/Carbon.h"; + INFOPLIST_FILE = "openFrameworks-Info.plist"; + INSTALL_PATH = "$(HOME)/Applications"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_1)", + "$(LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_2)", + "$(LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_3)", + "$(LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_4)", + ); + LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(SRCROOT)/../../../addons/ofxOpenCv/libs/opencv/lib/osx\""; + LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_2 = "\"$(SRCROOT)/../../../addons/ofxOpenCv/libs/opencv/lib/win32\""; + LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_3 = "\"$(SRCROOT)/../../../addons/ofxOsc/libs/oscpack/lib/osx\""; + LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_4 = "\"$(SRCROOT)/../../../addons/ofxOsc/libs/oscpack/lib/win32\""; + PREBINDING = NO; + PRODUCT_NAME = openFrameworksDebug; + WRAPPER_EXTENSION = app; + ZERO_LINK = NO; + }; + name = Debug; + }; + E4B69B610A3A1757003C02F2 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + COPY_PHASE_STRIP = YES; + GCC_ENABLE_FIX_AND_CONTINUE = NO; + GCC_GENERATE_DEBUGGING_SYMBOLS = NO; + GCC_MODEL_TUNING = G4; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/Carbon.framework/Headers/Carbon.h"; + INFOPLIST_FILE = "openFrameworks-Info.plist"; + INSTALL_PATH = "$(HOME)/Applications"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_1)", + "$(LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_2)", + "$(LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_3)", + "$(LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_4)", + ); + LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(SRCROOT)/../../../addons/ofxOpenCv/libs/opencv/lib/osx\""; + LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_2 = "\"$(SRCROOT)/../../../addons/ofxOpenCv/libs/opencv/lib/win32\""; + LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_3 = "\"$(SRCROOT)/../../../addons/ofxOsc/libs/oscpack/lib/osx\""; + LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_4 = "\"$(SRCROOT)/../../../addons/ofxOsc/libs/oscpack/lib/win32\""; + PREBINDING = NO; + PRODUCT_NAME = openFrameworks; + WRAPPER_EXTENSION = app; + ZERO_LINK = NO; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + E4B69B4D0A3A1720003C02F2 /* Build configuration list for PBXProject "openFrameworks" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E4B69B4E0A3A1720003C02F2 /* Debug */, + E4B69B4F0A3A1720003C02F2 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + E4B69B5F0A3A1757003C02F2 /* Build configuration list for PBXNativeTarget "openFrameworks" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E4B69B600A3A1757003C02F2 /* Debug */, + E4B69B610A3A1757003C02F2 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = E4B69B4C0A3A1720003C02F2 /* Project object */; +} diff --git a/pixelColor/src/main.cpp b/pixelColor/src/main.cpp new file mode 100755 index 0000000..68a3d43 --- /dev/null +++ b/pixelColor/src/main.cpp @@ -0,0 +1,15 @@ +#include "ofMain.h" +#include "testApp.h" + +//======================================================================== +int main( ){ + + ofSetupOpenGL(1024,768, OF_WINDOW); // <-------- setup the GL context + + // this kicks off the running of my app + // can be OF_WINDOW or OF_FULLSCREEN + // pass in width and height too: + + ofRunApp(new testApp()); + +} diff --git a/pixelColor/src/testApp.cpp b/pixelColor/src/testApp.cpp new file mode 100755 index 0000000..9ea1d0b --- /dev/null +++ b/pixelColor/src/testApp.cpp @@ -0,0 +1,75 @@ +#include "testApp.h" + + +//-------------------------------------------------------------- +void testApp::setup(){ + + vidGrabber.setVerbose(true); + vidGrabber.initGrabber(320,240); + colorImg.allocate(320,240); + bLearnBakground = true; + threshold = 80; + + red = 0; + green = 0; + blue = 0; + logo.loadImage("logo.gif"); +} + +//-------------------------------------------------------------- +void testApp::update(){ + ofBackground(100,100,100); + + bool bNewFrame = false; + + + vidGrabber.grabFrame(); + bNewFrame = vidGrabber.isFrameNew(); + colorImg.setFromPixels(vidGrabber.getPixels(), 320,240); + + +} + +//-------------------------------------------------------------- +void testApp::draw(){ + colorImg.draw(0,0); + + //ofSetColor(red, green, blue); + //ofRect(400,300,30,30); + ofSetColor(red, green, blue); + logo.draw(300,300,325,300); + ofSetColor(255, 255, 255); +} + + +//-------------------------------------------------------------- +void testApp::keyPressed (int key){ + + +} + +//-------------------------------------------------------------- +void testApp::mouseMoved(int x, int y ){ + + if(x < 320 && y < 240){ + pixels = colorImg.getPixels(); + int pixelImConcernedWith = (320 * y * 3) + (x * 3); + red = (int)pixels[pixelImConcernedWith]; + green = (int) pixels[pixelImConcernedWith + 1]; + blue = (int) pixels[pixelImConcernedWith + 2]; + } +} + +//-------------------------------------------------------------- +void testApp::mouseDragged(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void testApp::mousePressed(int x, int y, int button){ +} + +//-------------------------------------------------------------- +void testApp::mouseReleased(){ + +} diff --git a/pixelColor/src/testApp.h b/pixelColor/src/testApp.h new file mode 100755 index 0000000..f77b89b --- /dev/null +++ b/pixelColor/src/testApp.h @@ -0,0 +1,45 @@ +#ifndef _TEST_APP +#define _TEST_APP + +#include "ofMain.h" + +#define OF_ADDON_USING_OFXOPENCV + +#include "ofAddons.h" + +//#define _USE_LIVE_VIDEO // uncomment this to use a live camera + // otherwise, we'll use a movie file + + +class testApp : public ofSimpleApp{ + + public: + + void setup(); + void update(); + void draw(); + + void keyPressed (int key); + void mouseMoved(int x, int y ); + void mouseDragged(int x, int y, int button); + void mousePressed(int x, int y, int button); + void mouseReleased(); + + + ofVideoGrabber vidGrabber; + + ofxCvColorImage colorImg; + + unsigned char* pixels; + int red; + int green; + int blue; + ofImage logo; + + int threshold; + bool bLearnBakground; + + +}; + +#endif
davedash/International-Dialing-Codes
68174a2e09117752aa7791315f79767241f22ed3
Removed +39 for Vatican city as they either use +379 or fall under Italy's +39
diff --git a/codes.txt b/codes.txt index 50f884e..8bdef15 100644 --- a/codes.txt +++ b/codes.txt @@ -1,230 +1,229 @@ 93 Afghanistan 355 Albania 213 Algeria 1 American Samoa 376 Andorra 244 Angola 1 Anguilla 1 Antigua and Barbuda 54 Argentine Republic 374 Armenia 297 Aruba 247 Ascension 61 Australia 672 Australian External Territories 43 Austria 994 Azerbaijani Republic 1 Bahamas 973 Bahrain 880 Bangladesh 1 Barbados 375 Belarus 32 Belgium 501 Belize 229 Benin 1 Bermuda 975 Bhutan 591 Bolivia 387 Bosnia and Herzegovina 267 Botswana 55 Brazil 1 British Virgin Islands 673 Brunei Darussalam 359 Bulgaria 226 Burkina Faso 257 Burundi 855 Cambodia 237 Cameroon 1 Canada 238 Cape Verde 1 Cayman Islands 236 Central African Republic 235 Chad 56 Chile 86 China 57 Colombia 269 Comoros 242 Congo 682 Cook Islands 506 Costa Rica 225 Côte d'Ivoire 385 Croatia 53 Cuba 357 Cyprus 420 Czech Republic 850 Democratic People's Republic of Korea 243 Democratic Republic of the Congo 670 Democratic Republic of Timor-Leste 45 Denmark 246 Diego Garcia 253 Djibouti 1 Dominica 1 Dominican Republic 593 Ecuador 20 Egypt 503 El Salvador 240 Equatorial Guinea 291 Eritrea 372 Estonia 251 Ethiopia 500 Falkland Islands 298 Faroe Islands 679 Fiji 358 Finland 33 France 594 French Guiana 689 French Polynesia 241 Gabonese Republic 220 Gambia 995 Georgia 49 Germany 233 Ghana 350 Gibraltar 30 Greece 299 Greenland 1 Grenada 590 Guadeloupe 1 Guam 502 Guatemala 224 Guinea 245 Guinea-Bissau 592 Guyana 509 Haiti 504 Honduras 852 Hong Kong, China 36 Hungary 354 Iceland 91 India 62 Indonesia 98 Iran 964 Iraq 353 Ireland 972 Israel 39 Italy 1 Jamaica 81 Japan 962 Jordan 7 Kazakhstan 254 Kenya 686 Kiribati 82 Korea 965 Kuwait 996 Kyrgyz Republic 856 Lao People's Democratic Republic 371 Latvia 961 Lebanon 266 Lesotho 231 Liberia 218 Libya 423 Liechtenstein 370 Lithuania 352 Luxembourg 853 Macao, China 261 Madagascar 265 Malawi 60 Malaysia 960 Maldives 223 Mali 356 Malta 692 Marshall Islands 596 Martinique 222 Mauritania 230 Mauritius 269 Mayotte 52 Mexico 691 Micronesia 373 Moldova 377 Monaco 976 Mongolia 382 Montenegro 1 Montserrat 212 Morocco 258 Mozambique 95 Myanmar 264 Namibia 674 Nauru 977 Nepal 31 Netherlands 599 Netherlands Antilles 687 New Caledonia 64 New Zealand 505 Nicaragua 227 Niger 234 Nigeria 683 Niue 1 Northern Mariana Islands 47 Norway 968 Oman 92 Pakistan 680 Palau 507 Panama 675 Papua New Guinea 595 Paraguay 51 Peru 63 Philippines 48 Poland 351 Portugal 1 Puerto Rico 974 Qatar 40 Romania 7 Russian Federation 250 Rwanda 290 Saint Helena 1 Saint Kitts and Nevis 1 Saint Lucia 508 Saint Pierre and Miquelon 1 Saint Vincent and the Grenadines 685 Samoa 378 San Marino 239 Sao Tome and Principe 966 Saudi Arabia 221 Senegal 381 Serbia 248 Seychelles 232 Sierra Leone 65 Singapore 421 Slovak Republic 386 Slovenia 677 Solomon Islands 252 Somali Democratic Republic 27 South Africa 34 Spain 94 Sri Lanka 249 Sudan 597 Suriname 268 Swaziland 46 Sweden 41 Switzerland 963 Syrian Arab Republic 886 Taiwan, China 992 Tajikistan 255 Tanzania 66 Thailand 389 Macedonia 228 Togolese Republic 690 Tokelau 676 Tonga 1 Trinidad and Tobago 290 Tristan da Cunha 216 Tunisia 90 Turkey 993 Turkmenistan 1 Turks and Caicos Islands 688 Tuvalu 256 Uganda 380 Ukraine 971 United Arab Emirates 44 United Kingdom 1 United States of America 1 United States Virgin Islands 598 Uruguay 998 Uzbekistan 678 Vanuatu 379 Vatican City State -39 Vatican City State 58 Venezuela 84 Viet Nam 681 Wallis and Futuna 967 Yemen 260 Zambia 263 Zimbabwe \ No newline at end of file
auduny/statpipe
b7181f9d09460782eedc8134f1c7c8febf1fda0c
Fixed some error messages
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff1a9a --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.vscode +.perlcriticrc +.vstags +*.tdy diff --git a/statpipe b/statpipe index 43d374f..9579752 100755 --- a/statpipe +++ b/statpipe @@ -1,472 +1,474 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. my $version='1.0'; use Getopt::Long; #use gnu version of options Getopt::Long::Configure('gnu_getopt'); #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; use Scalar::Util qw(looks_like_number); # Unbuffered output $| = 1; # Catch Ctrl-C and friend $SIG{INT} = \&end_pipe; my $opt_linefreq = 0; # Default none my $opt_timefreq = 1; # Default every 1 second my $opt_maxtime = 0; # Default forever my $opt_maxlines = 0; # Default forever my $opt_maxkeys = 50000; # Default 50000 unique keys before we stop my $opt_case = 0; # Default case insensetive my $opt_limit = 0; # Default output all keys my $opt_not = 0; # Default no not's my $opt_multi = 0; # Default only read once per line my $opt_field = 0; # Don't split fields by default my $opt_delimiter = '\s+'; # Default delimiter is one or more spaces my $opt_keysize = 30; # Default length of printed key my $opt_help = 0; my $opt_version = 0; my $opt_hits = 1; # Show hits per second my $opt_title = 0; # What title to use my $opt_clear = 0; # Don't clean screen between updates -my $opt_relative = 0; +my $opt_relative = 0; # Relative percentage +my $opt_group = 0; # Grouping my @groups; my $groupmin=0; my $groupmax=0; +my $grouplength=0; my $result = GetOptions( 't|timefreq=i' => \$opt_timefreq, # how often do we update in time 'linefreq=i' => \$opt_linefreq, # how often do we update in lines 'maxtime=i' => \$opt_maxtime, # when to stop 'maxlines=i' => \$opt_maxlines, # when to stop 'maxkeys=i' => \$opt_maxkeys, # maxkeys (default 5000) 'l|limit=i' => \$opt_limit, # how many do we print 'n|not=s' => \$opt_not, # Not these 'm|multi' => \$opt_multi, # Multimatch for each line 'i|case' => \$opt_case, # key sensetive? 'g|group=s' => \$opt_group, # Group keys 'c|clear' => \$opt_clear, # clear and updatescreen? 'f|field=s' => \$opt_field, # what field to use? 'd|delimiter=s' => \$opt_delimiter, # What delimiter to use 'r|relative!' => \$opt_relative, # show relative percentages for hits 'k|keysize=i' => \$opt_keysize, # What delimiter to use 'hits!' => \$opt_hits, # show hits/s 'h|help' => \$opt_help, # Print help 'title=s' => \$opt_title, # What title to use 'v|version' => \$opt_version # Print version ); if (!$result) { $opt_help=1; } if ($opt_help) { close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit; } if ($opt_group) { @groups = split(",",$opt_group); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = scalar (keys %$objects); if ($keys >= $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { if ($opt_group) { # We want to group the actual numeral values in groups - $grouplenght = length(@groups); + $grouplength = scalar @groups; if (looks_like_number($line)) { if ($line > $groupmax) { $groupmax=$line; } my $match=0; for my $group (@groups) { if ($line < $group) { my $groupname = "< $group"; $objects->{$groupname}++; $match=1; last; } } if (!$match) { my $groupname = "> $groups[$grouplength-1]"; $objects->{$groupname}++; } } else { $objects->{"not numeric"}++ } } else { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=1; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } if ($opt_title) { # if set, print a header row print "$opt_title\n"; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total keys: " . scalar (keys(%$objects)) . ">", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total keys: " . scalar (keys(%$objects)) . '>', ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( '%-'.$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", - "<rest>", ( $rest / $divider ) * 100, - $rest, $lines + "<rest>", ( $restcount / $divider ) * 100, + $restcount, $lines ); } } if ($opt_group) { print "Highest numeric value: $groupmax\n" } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, grep for stuff and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut | sort | unique -c |sort -g | whatever. =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --title Optional title --help Show help --version Show version =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list TODO: Threads (use threads) for output TODO: Freqreset. REset numbers every X secons TODO: Scriptfilter on output (geoip etc) TODO: Fields in the form of -f-1 or -f2, =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
b4f2c780dee4da003b3b33770ca0ba5a98d8b5be
Added highest numberic value
diff --git a/statpipe b/statpipe index dd31811..43d374f 100755 --- a/statpipe +++ b/statpipe @@ -1,465 +1,472 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. my $version='1.0'; use Getopt::Long; #use gnu version of options Getopt::Long::Configure('gnu_getopt'); #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; use Scalar::Util qw(looks_like_number); # Unbuffered output $| = 1; # Catch Ctrl-C and friend $SIG{INT} = \&end_pipe; my $opt_linefreq = 0; # Default none my $opt_timefreq = 1; # Default every 1 second my $opt_maxtime = 0; # Default forever my $opt_maxlines = 0; # Default forever my $opt_maxkeys = 50000; # Default 50000 unique keys before we stop my $opt_case = 0; # Default case insensetive my $opt_limit = 0; # Default output all keys my $opt_not = 0; # Default no not's my $opt_multi = 0; # Default only read once per line my $opt_field = 0; # Don't split fields by default my $opt_delimiter = '\s+'; # Default delimiter is one or more spaces my $opt_keysize = 30; # Default length of printed key my $opt_help = 0; my $opt_version = 0; my $opt_hits = 1; # Show hits per second my $opt_title = 0; # What title to use my $opt_clear = 0; # Don't clean screen between updates my $opt_relative = 0; my @groups; my $groupmin=0; my $groupmax=0; my $result = GetOptions( 't|timefreq=i' => \$opt_timefreq, # how often do we update in time 'linefreq=i' => \$opt_linefreq, # how often do we update in lines 'maxtime=i' => \$opt_maxtime, # when to stop 'maxlines=i' => \$opt_maxlines, # when to stop 'maxkeys=i' => \$opt_maxkeys, # maxkeys (default 5000) 'l|limit=i' => \$opt_limit, # how many do we print 'n|not=s' => \$opt_not, # Not these 'm|multi' => \$opt_multi, # Multimatch for each line 'i|case' => \$opt_case, # key sensetive? 'g|group=s' => \$opt_group, # Group keys 'c|clear' => \$opt_clear, # clear and updatescreen? 'f|field=s' => \$opt_field, # what field to use? 'd|delimiter=s' => \$opt_delimiter, # What delimiter to use 'r|relative!' => \$opt_relative, # show relative percentages for hits 'k|keysize=i' => \$opt_keysize, # What delimiter to use 'hits!' => \$opt_hits, # show hits/s 'h|help' => \$opt_help, # Print help 'title=s' => \$opt_title, # What title to use 'v|version' => \$opt_version # Print version ); if (!$result) { $opt_help=1; } if ($opt_help) { close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit; } if ($opt_group) { @groups = split(",",$opt_group); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = scalar (keys %$objects); if ($keys >= $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { if ($opt_group) { # We want to group the actual numeral values in groups $grouplenght = length(@groups); if (looks_like_number($line)) { + if ($line > $groupmax) { + $groupmax=$line; + } my $match=0; for my $group (@groups) { if ($line < $group) { my $groupname = "< $group"; $objects->{$groupname}++; $match=1; last; } } if (!$match) { my $groupname = "> $groups[$grouplength-1]"; $objects->{$groupname}++; } } else { $objects->{"not numeric"}++ } } else { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=1; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } if ($opt_title) { # if set, print a header row print "$opt_title\n"; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total keys: " . scalar (keys(%$objects)) . ">", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total keys: " . scalar (keys(%$objects)) . '>', ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( '%-'.$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } + if ($opt_group) { + print "Highest numeric value: $groupmax\n" + } + print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, grep for stuff and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut | sort | unique -c |sort -g | whatever. =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --title Optional title --help Show help --version Show version =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list TODO: Threads (use threads) for output TODO: Freqreset. REset numbers every X secons TODO: Scriptfilter on output (geoip etc) TODO: Fields in the form of -f-1 or -f2, =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
33edb097d84a9245228aa09df351706e394ffb3e
Added support for groups
diff --git a/statpipe b/statpipe index 2f8aa4c..dd31811 100755 --- a/statpipe +++ b/statpipe @@ -1,428 +1,465 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. -=head1 NAME - -statpipe - swiss knife statistics - -=head1 DESCRIPTION - -statpipe is a excellent little tool to analyse logfiles, or any file -for that matter, grep for stuff and produce percentage of hits, -hits per second and other cool stuff. -It's supposed to be a better way of doing something similar to -tail -f | awk | cut | sort | unique -c |sort -g | whatever. - -=cut -my $version="1.0"; +my $version='1.0'; use Getopt::Long; #use gnu version of options -Getopt::Long::Configure("gnu_getopt"); +Getopt::Long::Configure('gnu_getopt'); #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; +use Scalar::Util qw(looks_like_number); # Unbuffered output $| = 1; -# Catch Ctrl-C and friends + +# Catch Ctrl-C and friend $SIG{INT} = \&end_pipe; my $opt_linefreq = 0; # Default none my $opt_timefreq = 1; # Default every 1 second my $opt_maxtime = 0; # Default forever my $opt_maxlines = 0; # Default forever my $opt_maxkeys = 50000; # Default 50000 unique keys before we stop my $opt_case = 0; # Default case insensetive my $opt_limit = 0; # Default output all keys my $opt_not = 0; # Default no not's my $opt_multi = 0; # Default only read once per line my $opt_field = 0; # Don't split fields by default my $opt_delimiter = '\s+'; # Default delimiter is one or more spaces my $opt_keysize = 30; # Default length of printed key my $opt_help = 0; my $opt_version = 0; my $opt_hits = 1; # Show hits per second my $opt_title = 0; # What title to use my $opt_clear = 0; # Don't clean screen between updates -my $opt_relative=0; +my $opt_relative = 0; +my @groups; +my $groupmin=0; +my $groupmax=0; + my $result = GetOptions( - "t|timefreq=i" => \$opt_timefreq, # how often do we update in time - "linefreq=i" => \$opt_linefreq, # how often do we update in lines - "maxtime=i" => \$opt_maxtime, # when to stop - "maxlines=i" => \$opt_maxlines, # when to stop - "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) - "l|limit=i" => \$opt_limit, # how many do we print - "n|not=s" => \$opt_not, # Not these - "m|multi" => \$opt_multi, # Multimatch for each line - "s|case" => \$opt_case, # key sensetive? - "c|clear" => \$opt_clear, # clear and updatescreen? - "f|field=s" => \$opt_field, # what field to use? - "d|delimiter=s" => \$opt_delimiter, # What delimiter to use - "r|relative!" => \$opt_relative, # show relative percentages for hits - "k|keysize=i" => \$opt_keysize, # What delimiter to use - "hits!" => \$opt_hits, # show hits/s - "h|help" => \$opt_help, # Print help - "title=s" => \$opt_title, # What title to use - "v|version" => \$opt_version # Print version + 't|timefreq=i' => \$opt_timefreq, # how often do we update in time + 'linefreq=i' => \$opt_linefreq, # how often do we update in lines + 'maxtime=i' => \$opt_maxtime, # when to stop + 'maxlines=i' => \$opt_maxlines, # when to stop + 'maxkeys=i' => \$opt_maxkeys, # maxkeys (default 5000) + 'l|limit=i' => \$opt_limit, # how many do we print + 'n|not=s' => \$opt_not, # Not these + 'm|multi' => \$opt_multi, # Multimatch for each line + 'i|case' => \$opt_case, # key sensetive? + 'g|group=s' => \$opt_group, # Group keys + 'c|clear' => \$opt_clear, # clear and updatescreen? + 'f|field=s' => \$opt_field, # what field to use? + 'd|delimiter=s' => \$opt_delimiter, # What delimiter to use + 'r|relative!' => \$opt_relative, # show relative percentages for hits + 'k|keysize=i' => \$opt_keysize, # What delimiter to use + 'hits!' => \$opt_hits, # show hits/s + 'h|help' => \$opt_help, # Print help + 'title=s' => \$opt_title, # What title to use + 'v|version' => \$opt_version # Print version ); if (!$result) { $opt_help=1; } -=head1 SYNOPSIS -tail -f some.log | statpipe [options] [regex] ... [regex] - -Regex is a perl regex, if the regex has a group 'something\.(.*)' the -match will be used as a key instead of the regexp itself. - -If no regex and no --field argument is given. It will be as '^(.*)$' was given. -Meaning that it will count all unique lines in the file/pipe. - - Options: - --field|f What field top use as key (default all fields) - --delimiter|d What delimiter to use for fields (spaces) - --timefreq|-t Frequency of output in seconds (1 second) - --linefreq Frequency of output in lines (none) - --maxtime Time before closing the pipe in seconds (unlimited) - --maxlines Maximum numbers of lines to parse (unlimited) - --multi|m Match multiple times per line (no) - --limit Limit output of keys (0) - --maxkeys Max number of unique keys (50000) - --not|n Exclude lines with regex - --case|s Be casesensetive - --clear Clear screen between updates - --relative|r Show relative percentages (no) - --keysize|k Length of keys (output) - --(no)hits Show hits per second (yes) - --title Optional title - --help Show help - --version Show version - -=cut if ($opt_help) { close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit; } + + +if ($opt_group) { + @groups = split(",",$opt_group); +} + if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = scalar (keys %$objects); if ($keys >= $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } - if ( !@ARGV ) { # we didn't send regexp, count every line - $hitcount++; - $objects->{$line}++; - $hitflag=1; + + if ( !@ARGV ) { + if ($opt_group) { + # We want to group the actual numeral values in groups + $grouplenght = length(@groups); + if (looks_like_number($line)) { + my $match=0; + for my $group (@groups) { + if ($line < $group) { + my $groupname = "< $group"; + $objects->{$groupname}++; + $match=1; + last; + } + } + if (!$match) { + my $groupname = "> $groups[$grouplength-1]"; + $objects->{$groupname}++; + } + } else { + $objects->{"not numeric"}++ + } + } else { + # we didn't send regexp, count every line + $hitcount++; + $objects->{$line}++; + $hitflag=1; + } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=1; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } if ($opt_title) { # if set, print a header row print "$opt_title\n"; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total keys: " . scalar (keys(%$objects)) . ">", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", - "<total keys: " . scalar (keys(%$objects)) . ">", + "<total keys: " . scalar (keys(%$objects)) . '>', ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( - "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", + '%-'.$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } +=head1 NAME + +statpipe - swiss knife statistics + +=head1 DESCRIPTION + +statpipe is a excellent little tool to analyse logfiles, or any file +for that matter, grep for stuff and produce percentage of hits, +hits per second and other cool stuff. +It's supposed to be a better way of doing something similar to +tail -f | awk | cut | sort | unique -c |sort -g | whatever. + +=head1 SYNOPSIS + +tail -f some.log | statpipe [options] [regex] ... [regex] + +Regex is a perl regex, if the regex has a group 'something\.(.*)' the +match will be used as a key instead of the regexp itself. + +If no regex and no --field argument is given. It will be as '^(.*)$' was given. +Meaning that it will count all unique lines in the file/pipe. + + Options: + --field|f What field top use as key (default all fields) + --delimiter|d What delimiter to use for fields (spaces) + --timefreq|-t Frequency of output in seconds (1 second) + --linefreq Frequency of output in lines (none) + --maxtime Time before closing the pipe in seconds (unlimited) + --maxlines Maximum numbers of lines to parse (unlimited) + --multi|m Match multiple times per line (no) + --limit Limit output of keys (0) + --maxkeys Max number of unique keys (50000) + --not|n Exclude lines with regex + --case|s Be casesensetive + --clear Clear screen between updates + --relative|r Show relative percentages (no) + --keysize|k Length of keys (output) + --(no)hits Show hits per second (yes) + --title Optional title + --help Show help + --version Show version + + =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list TODO: Threads (use threads) for output TODO: Freqreset. REset numbers every X secons TODO: Scriptfilter on output (geoip etc) TODO: Fields in the form of -f-1 or -f2, =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
7e442bcef9060317030a3f44ed3ffca7876142f4
Get counting of keys correct
diff --git a/examples.md b/examples.md index 63a49cd..e7d8a25 100644 --- a/examples.md +++ b/examples.md @@ -1,22 +1,22 @@ # EXAMPLES - #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) + # Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ cat testfiles/access.log | statpipe -f 7 # Most active ip's that are not 10.84.X.X $ varnishncsa |statpipe -f 7 --limit 15 --not 10.84 '^([^\?]+)\??' # Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 # Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif # Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift # Count all words in a file $ cat file | statpipe --multi '(\w)' # List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 diff --git a/statpipe b/statpipe index 3dd1553..2f8aa4c 100755 --- a/statpipe +++ b/statpipe @@ -1,427 +1,428 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, grep for stuff and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut | sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use gnu version of options Getopt::Long::Configure("gnu_getopt"); #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq = 0; # Default none my $opt_timefreq = 1; # Default every 1 second my $opt_maxtime = 0; # Default forever my $opt_maxlines = 0; # Default forever my $opt_maxkeys = 50000; # Default 50000 unique keys before we stop my $opt_case = 0; # Default case insensetive my $opt_limit = 0; # Default output all keys my $opt_not = 0; # Default no not's my $opt_multi = 0; # Default only read once per line my $opt_field = 0; # Don't split fields by default my $opt_delimiter = '\s+'; # Default delimiter is one or more spaces my $opt_keysize = 30; # Default length of printed key my $opt_help = 0; my $opt_version = 0; my $opt_hits = 1; # Show hits per second my $opt_title = 0; # What title to use my $opt_clear = 0; # Don't clean screen between updates my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "title=s" => \$opt_title, # What title to use "v|version" => \$opt_version # Print version ); if (!$result) { $opt_help=1; } =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --title Optional title --help Show help --version Show version =cut if ($opt_help) { close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit; } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { - $keys = keys %$objects; - if ($keys > $opt_maxkeys) { + $keys = scalar (keys %$objects); + + if ($keys >= $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=1; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } if ($opt_title) { # if set, print a header row print "$opt_title\n"; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", - "<total keys: " . keys(%$objects) . ">", + "<total keys: " . scalar (keys(%$objects)) . ">", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", - "<total keys: " . keys(%$objects) . ">", + "<total keys: " . scalar (keys(%$objects)) . ">", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list TODO: Threads (use threads) for output TODO: Freqreset. REset numbers every X secons TODO: Scriptfilter on output (geoip etc) TODO: Fields in the form of -f-1 or -f2, =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
84124edaa76fbf7dec00586385362b115e8eac39
Adding helpfile for title
diff --git a/statpipe b/statpipe index bbd1bdc..3dd1553 100755 --- a/statpipe +++ b/statpipe @@ -1,422 +1,427 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, grep for stuff and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut | sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use gnu version of options Getopt::Long::Configure("gnu_getopt"); #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; + my $opt_linefreq = 0; # Default none my $opt_timefreq = 1; # Default every 1 second my $opt_maxtime = 0; # Default forever my $opt_maxlines = 0; # Default forever my $opt_maxkeys = 50000; # Default 50000 unique keys before we stop my $opt_case = 0; # Default case insensetive -my $opt_limit = 0; # Default output all keys +my $opt_limit = 0; # Default output all keys +my $opt_not = 0; # Default no not's +my $opt_multi = 0; # Default only read once per line my $opt_field = 0; # Don't split fields by default my $opt_delimiter = '\s+'; # Default delimiter is one or more spaces my $opt_keysize = 30; # Default length of printed key my $opt_help = 0; my $opt_version = 0; my $opt_hits = 1; # Show hits per second +my $opt_title = 0; # What title to use my $opt_clear = 0; # Don't clean screen between updates my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "title=s" => \$opt_title, # What title to use "v|version" => \$opt_version # Print version ); if (!$result) { $opt_help=1; } =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) + --title Optional title --help Show help --version Show version =cut if ($opt_help) { close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit; } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=1; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } if ($opt_title) { # if set, print a header row print "$opt_title\n"; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list TODO: Threads (use threads) for output TODO: Freqreset. REset numbers every X secons TODO: Scriptfilter on output (geoip etc) TODO: Fields in the form of -f-1 or -f2, =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
6cacb6f6a4028556c2ffbf778651637ff4e89f77
Add another TODO for ranges
diff --git a/statpipe b/statpipe index 53d8133..bbd1bdc 100755 --- a/statpipe +++ b/statpipe @@ -1,421 +1,422 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, grep for stuff and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut | sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use gnu version of options Getopt::Long::Configure("gnu_getopt"); #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq = 0; # Default none my $opt_timefreq = 1; # Default every 1 second my $opt_maxtime = 0; # Default forever my $opt_maxlines = 0; # Default forever my $opt_maxkeys = 50000; # Default 50000 unique keys before we stop my $opt_case = 0; # Default case insensetive my $opt_limit = 0; # Default output all keys my $opt_field = 0; # Don't split fields by default my $opt_delimiter = '\s+'; # Default delimiter is one or more spaces my $opt_keysize = 30; # Default length of printed key my $opt_help = 0; my $opt_version = 0; my $opt_hits = 1; # Show hits per second my $opt_clear = 0; # Don't clean screen between updates my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "title=s" => \$opt_title, # What title to use "v|version" => \$opt_version # Print version ); if (!$result) { $opt_help=1; } =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit; } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=1; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } if ($opt_title) { # if set, print a header row print "$opt_title\n"; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list TODO: Threads (use threads) for output TODO: Freqreset. REset numbers every X secons TODO: Scriptfilter on output (geoip etc) +TODO: Fields in the form of -f-1 or -f2, =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
1b59a481a83b4106084b96b6f252ede85a031e9e
Added some info to TODO
diff --git a/statpipe b/statpipe index bf2ec2f..53d8133 100755 --- a/statpipe +++ b/statpipe @@ -1,421 +1,421 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, grep for stuff and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut | sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use gnu version of options Getopt::Long::Configure("gnu_getopt"); #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq = 0; # Default none my $opt_timefreq = 1; # Default every 1 second my $opt_maxtime = 0; # Default forever my $opt_maxlines = 0; # Default forever my $opt_maxkeys = 50000; # Default 50000 unique keys before we stop my $opt_case = 0; # Default case insensetive my $opt_limit = 0; # Default output all keys my $opt_field = 0; # Don't split fields by default my $opt_delimiter = '\s+'; # Default delimiter is one or more spaces my $opt_keysize = 30; # Default length of printed key my $opt_help = 0; my $opt_version = 0; my $opt_hits = 1; # Show hits per second my $opt_clear = 0; # Don't clean screen between updates my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "title=s" => \$opt_title, # What title to use "v|version" => \$opt_version # Print version ); if (!$result) { $opt_help=1; } =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit; } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=1; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } if ($opt_title) { # if set, print a header row print "$opt_title\n"; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list TODO: Threads (use threads) for output TODO: Freqreset. REset numbers every X secons -TODO: Scriptfilter on output +TODO: Scriptfilter on output (geoip etc) =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
b2fb31726462629a7526ced85a45329d1bf871ce
Clean up examples and logfaker
diff --git a/README.md b/README.md index f54f8f1..b3d9fb8 100644 --- a/README.md +++ b/README.md @@ -1,79 +1,79 @@ # Statpipe # NAME statpipe - swiss knife statistics # DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and -other cool stuff. +other cool stuff in the terminal It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. # SYNOPSIS tail -f some.log | statpipe \[options\] \[regex\] ... \[regex\] Regex is a perl regex, if the regex has a group 'something\\.(.\*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.\*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version # EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 # BUGS Probably plenty. # TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? # COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ diff --git a/examples.md b/examples.md index 9683a86..63a49cd 100644 --- a/examples.md +++ b/examples.md @@ -1,22 +1,22 @@ # EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ cat testfiles/access.log | statpipe -f 7 # Most active ip's that are not 10.84.X.X - $varnishncsa |statpipe -f 7 --limit 15 --not 10.84 '^([^\?]+)\??' + $ varnishncsa |statpipe -f 7 --limit 15 --not 10.84 '^([^\?]+)\??' - #Seperate fields by " and show field two + # Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 - #Group jpeg and jpg differently + # Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif - #Group jpeg and jpg into one key + # Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift - #Count all words in a file + # Count all words in a file $ cat file | statpipe --multi '(\w)' - #List top 20 articles the last 10 seconds + # List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 diff --git a/logfaker.pl b/logfaker.pl index e841ff1..9e49570 100755 --- a/logfaker.pl +++ b/logfaker.pl @@ -1,29 +1,39 @@ #!/usr/bin/perl use strict; use Getopt::Long; use Time::HiRes qw( time usleep); my $opt_bulk=1; my $opt_wait=0.0006; my $opt_unbuffered=1; +my $opt_loop=1; # Unbuffered output $| = 1; my $result = GetOptions( "b|buld=i" => \$opt_bulk, # how often do we update in time "s|sleep=f" => \$opt_wait, # how often do we update in lines -"u|unbuffered=i" => \$opt_unbuffered); +"u|unbuffered=i" => \$opt_unbuffered, +"l|loop=i" => \$opt_loop); + +if ($opt_loop == 0) { + $opt_loop = -1; +} my $wait = $opt_wait * 1000000; -open(my $fh, '<', $ARGV[0]) or die $!; +while ($opt_loop != 0) { + open(my $fh, '<', $ARGV[0]) or die $!; + + my $linecounter = 0; + my @lines; + my $time = time(); -my $linecounter = 0; -my @lines; -my $time = time(); -while (my $line = <$fh>) { - print $line; - usleep($wait); + while (my $line = <$fh>) { + print $line; + usleep($wait); + } + $opt_loop--; }
auduny/statpipe
ac0542d90fc5dde4b3f5b37f9ea4efb5a2a1fbbd
Added some todos
diff --git a/statpipe b/statpipe index 2511511..5272ec9 100755 --- a/statpipe +++ b/statpipe @@ -1,418 +1,420 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, grep for stuff and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut | sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use gnu version of options Getopt::Long::Configure("gnu_getopt"); #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq = 0; # Default none my $opt_timefreq = 1; # Default every 1 second my $opt_maxtime = 0; # Default forever my $opt_maxlines = 0; # Default forever my $opt_maxkeys = 50000; # Default 50000 unique keys before we stop my $opt_case = 0; # Default case insensetive my $opt_limit = 0; # Default output all keys my $opt_field = 0; # Don't split fields by default my $opt_delimiter = '\s+'; # Default delimiter is one or more spaces my $opt_keysize = 30; # Default length of printed key my $opt_help = 0; my $opt_version = 0; my $opt_hits = 1; # Show hits per second my $opt_clear = 0; # Don't clean screen between updates my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "title=s" => \$opt_title, # What title to use "v|version" => \$opt_version # Print version ); if (!$result) { $opt_help=1; } =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit; } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=1; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } if ($opt_title) { # if set, print a header row print "$opt_title\n"; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list +TODO: Threads (use threads) for output +TODO: Freqreset. REset numbers every X secons =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
a6d4ef626632e24ba3ae21f53db22cba9f7fdaea
removed seeming stray semicolon, which caused an error (on osx)
diff --git a/statpipe b/statpipe index 39892e1..2511511 100755 --- a/statpipe +++ b/statpipe @@ -1,418 +1,418 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, grep for stuff and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut | sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use gnu version of options Getopt::Long::Configure("gnu_getopt"); #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq = 0; # Default none my $opt_timefreq = 1; # Default every 1 second my $opt_maxtime = 0; # Default forever my $opt_maxlines = 0; # Default forever my $opt_maxkeys = 50000; # Default 50000 unique keys before we stop my $opt_case = 0; # Default case insensetive my $opt_limit = 0; # Default output all keys -my $opt_field; = 0; # Don't split fields by default +my $opt_field = 0; # Don't split fields by default my $opt_delimiter = '\s+'; # Default delimiter is one or more spaces my $opt_keysize = 30; # Default length of printed key my $opt_help = 0; my $opt_version = 0; my $opt_hits = 1; # Show hits per second my $opt_clear = 0; # Don't clean screen between updates my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "title=s" => \$opt_title, # What title to use "v|version" => \$opt_version # Print version ); if (!$result) { $opt_help=1; } =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit; } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=1; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } if ($opt_title) { # if set, print a header row print "$opt_title\n"; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
0b8c2dc244b1310c4ad76f0da946a511c84a4fc4
Comment clean up
diff --git a/statpipe b/statpipe index 6fe6121..39892e1 100755 --- a/statpipe +++ b/statpipe @@ -1,418 +1,418 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, grep for stuff and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut | sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; +#use gnu version of options Getopt::Long::Configure("gnu_getopt"); #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; -my $opt_linefreq; # Default none -my $opt_timefreq=1; # Default every 1 second -my $opt_maxtime=0; # Default forever -my $opt_maxlines=0; # Default forever -my $opt_maxkeys=50000; # Default 50000 unique keys before we stop -my $opt_regex = 0; -my $opt_case = 0; -my $opt_limit = 0; -my $opt_field; -my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces -my $opt_keysize = 30; # Default length of printed key -my $opt_help = 0; -my $opt_version = 0; -my $opt_hits=1; # Show hits per second -my $opt_clear=0; # Don't clean screen between updates +my $opt_linefreq = 0; # Default none +my $opt_timefreq = 1; # Default every 1 second +my $opt_maxtime = 0; # Default forever +my $opt_maxlines = 0; # Default forever +my $opt_maxkeys = 50000; # Default 50000 unique keys before we stop +my $opt_case = 0; # Default case insensetive +my $opt_limit = 0; # Default output all keys +my $opt_field; = 0; # Don't split fields by default +my $opt_delimiter = '\s+'; # Default delimiter is one or more spaces +my $opt_keysize = 30; # Default length of printed key +my $opt_help = 0; +my $opt_version = 0; +my $opt_hits = 1; # Show hits per second +my $opt_clear = 0; # Don't clean screen between updates my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "title=s" => \$opt_title, # What title to use "v|version" => \$opt_version # Print version ); if (!$result) { $opt_help=1; } =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit; } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=1; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } if ($opt_title) { # if set, print a header row print "$opt_title\n"; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
0c1edaf644b27dc0baadf85121f61d56066d9161
Adding examplefile
diff --git a/examples.md b/examples.md new file mode 100644 index 0000000..9683a86 --- /dev/null +++ b/examples.md @@ -0,0 +1,22 @@ +# EXAMPLES + + #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) + $ cat testfiles/access.log | statpipe -f 7 + + # Most active ip's that are not 10.84.X.X + $varnishncsa |statpipe -f 7 --limit 15 --not 10.84 '^([^\?]+)\??' + + #Seperate fields by " and show field two + $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 + + #Group jpeg and jpg differently + $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif + + #Group jpeg and jpg into one key + $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift + + #Count all words in a file + $ cat file | statpipe --multi '(\w)' + + #List top 20 articles the last 10 seconds + $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0
auduny/statpipe
0aaa767e04ddbb1f23c37dfef9356056d5c547aa
Fixed divide by zero and some indenting
diff --git a/statpipe b/statpipe index 4861958..6fe6121 100755 --- a/statpipe +++ b/statpipe @@ -1,418 +1,418 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, grep for stuff and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut | sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; Getopt::Long::Configure("gnu_getopt"); #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=1; # Default every 1 second my $opt_maxtime=0; # Default forever my $opt_maxlines=0; # Default forever my $opt_maxkeys=50000; # Default 50000 unique keys before we stop my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 0; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; # Default length of printed key my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; # Don't clean screen between updates my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time -"linefreq=i" => \$opt_linefreq, # how often do we update in lines -"maxtime=i" => \$opt_maxtime, # when to stop -"maxlines=i" => \$opt_maxlines, # when to stop -"maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) -"l|limit=i" => \$opt_limit, # how many do we print -"n|not=s" => \$opt_not, # Not these -"m|multi" => \$opt_multi, # Multimatch for each line -"s|case" => \$opt_case, # key sensetive? -"c|clear" => \$opt_clear, # clear and updatescreen? -"f|field=s" => \$opt_field, # what field to use? -"d|delimiter=s" => \$opt_delimiter, # What delimiter to use -"r|relative!" => \$opt_relative, # show relative percentages for hits -"k|keysize=i" => \$opt_keysize, # What delimiter to use -"hits!" => \$opt_hits, # show hits/s -"h|help" => \$opt_help, # Print help -"title=s" => \$opt_title, # What title to use -"v|version" => \$opt_version # Print version + "linefreq=i" => \$opt_linefreq, # how often do we update in lines + "maxtime=i" => \$opt_maxtime, # when to stop + "maxlines=i" => \$opt_maxlines, # when to stop + "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) + "l|limit=i" => \$opt_limit, # how many do we print + "n|not=s" => \$opt_not, # Not these + "m|multi" => \$opt_multi, # Multimatch for each line + "s|case" => \$opt_case, # key sensetive? + "c|clear" => \$opt_clear, # clear and updatescreen? + "f|field=s" => \$opt_field, # what field to use? + "d|delimiter=s" => \$opt_delimiter, # What delimiter to use + "r|relative!" => \$opt_relative, # show relative percentages for hits + "k|keysize=i" => \$opt_keysize, # What delimiter to use + "hits!" => \$opt_hits, # show hits/s + "h|help" => \$opt_help, # Print help + "title=s" => \$opt_title, # What title to use + "v|version" => \$opt_version # Print version ); if (!$result) { $opt_help=1; } =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit; } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } - # Default is not using multi match + # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; - my $divider=0; + my $divider=1; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } if ($opt_title) { # if set, print a header row print "$opt_title\n"; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
e7a917e1f6189e2d71d028a430b94e305182d5bf
Die on wrong options
diff --git a/statpipe b/statpipe index 5e9009d..4861958 100755 --- a/statpipe +++ b/statpipe @@ -1,416 +1,418 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, grep for stuff and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut | sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; Getopt::Long::Configure("gnu_getopt"); #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=1; # Default every 1 second my $opt_maxtime=0; # Default forever my $opt_maxlines=0; # Default forever my $opt_maxkeys=50000; # Default 50000 unique keys before we stop my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 0; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; # Default length of printed key my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; # Don't clean screen between updates my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "title=s" => \$opt_title, # What title to use "v|version" => \$opt_version # Print version ); +if (!$result) { + $opt_help=1; +} =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut - if ($opt_help) { close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit; } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } if ($opt_title) { # if set, print a header row print "$opt_title\n"; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
7afea3a113a6b24e38c830f87a12355d2ffe455e
Fixed some Docs
diff --git a/statpipe b/statpipe index be3f52b..5e9009d 100755 --- a/statpipe +++ b/statpipe @@ -1,416 +1,416 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file -for that matter, and produce percentage of hits, hits per second and -other cool stuff. +for that matter, grep for stuff and produce percentage of hits, +hits per second and other cool stuff. It's supposed to be a better way of doing something similar to -tail -f | awk | cut| sort | unique -c |sort -g | whatever. +tail -f | awk | cut | sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; Getopt::Long::Configure("gnu_getopt"); #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=1; # Default every 1 second -my $opt_maxtime=0; # Default 60 seconds -my $opt_maxlines=0; # Stop at five million lines -my $opt_maxkeys=50000; +my $opt_maxtime=0; # Default forever +my $opt_maxlines=0; # Default forever +my $opt_maxkeys=50000; # Default 50000 unique keys before we stop my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 0; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces -my $opt_keysize = 30; +my $opt_keysize = 30; # Default length of printed key my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second -my $opt_clear=0; #Don't clean screen +my $opt_clear=0; # Don't clean screen between updates my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "title=s" => \$opt_title, # What title to use "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit; } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } if ($opt_title) { # if set, print a header row print "$opt_title\n"; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
7faeecda87f0ce4eefe25168749f60ba1cbd8a8d
Added gnu_compat which enable -d\" and -f2
diff --git a/statpipe b/statpipe index 9b67c42..be3f52b 100755 --- a/statpipe +++ b/statpipe @@ -1,415 +1,416 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; +Getopt::Long::Configure("gnu_getopt"); #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=1; # Default every 1 second my $opt_maxtime=0; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 0; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "title=s" => \$opt_title, # What title to use "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit; } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } if ($opt_title) { # if set, print a header row print "$opt_title\n"; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
0540cfa290ff2ff187736f2860a617d6e0e331d7
Added optional title
diff --git a/statpipe b/statpipe index 75bf102..58d1cc2 100755 --- a/statpipe +++ b/statpipe @@ -1,410 +1,414 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=1; # Default every 1 second my $opt_maxtime=0; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 0; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help +"title=s" => \$opt_title, # What title to use "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } + if ($opt_title) { # if set, print a header row + print "$opt_title\n"; + } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
ee98283c6c81a0f99132aeb12853b23c20ddae68
syntatic sugar
diff --git a/statpipe b/statpipe index 3515530..1e26e15 100755 --- a/statpipe +++ b/statpipe @@ -1,411 +1,411 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=1; # Default every 1 second my $opt_maxtime=0; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 0; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit; } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", - "<unique keys: " . keys(%$objects) . ">", + "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", - "<unique keys: " . keys(%$objects) . ">", + "<total keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
dfa9632f561b3aa3a6b17c2e70be8ba493a63a22
Wrong hash
diff --git a/statpipe b/statpipe index ce848ce..3515530 100755 --- a/statpipe +++ b/statpipe @@ -1,411 +1,411 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=1; # Default every 1 second my $opt_maxtime=0; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 0; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit; } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", - "<keys - " . length(keys %$hash) . ">", + "<unique keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", - "<keys - " . length(keys %$hash) . ">", + "<unique keys: " . keys(%$objects) . ">", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
834e55dcaef6ec2e06ac1c99d999eb51ff5d7c3d
Added number of keys to total
diff --git a/statpipe b/statpipe index ddf2afe..ce848ce 100755 --- a/statpipe +++ b/statpipe @@ -1,411 +1,411 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=1; # Default every 1 second my $opt_maxtime=0; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 0; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit; } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", - "<total>", + "<keys - " . length(keys %$hash) . ">", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", - "<total>", + "<keys - " . length(keys %$hash) . ">", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
18377d22a8b9785ba9afb40433548dd2fc8fb438
Change timings in logfaker
diff --git a/logfaker.pl b/logfaker.pl index 7f1c24a..e841ff1 100755 --- a/logfaker.pl +++ b/logfaker.pl @@ -1,30 +1,29 @@ #!/usr/bin/perl use strict; use Getopt::Long; use Time::HiRes qw( time usleep); my $opt_bulk=1; -my $opt_wait=1; +my $opt_wait=0.0006; my $opt_unbuffered=1; # Unbuffered output $| = 1; my $result = GetOptions( "b|buld=i" => \$opt_bulk, # how often do we update in time "s|sleep=f" => \$opt_wait, # how often do we update in lines "u|unbuffered=i" => \$opt_unbuffered); my $wait = $opt_wait * 1000000; -print "slowness is $wait"; open(my $fh, '<', $ARGV[0]) or die $!; my $linecounter = 0; my @lines; my $time = time(); while (my $line = <$fh>) { print $line; usleep($wait); }
auduny/statpipe
2637cd3afaea675d5335130a9deb70e4d592d931
Remove garbage title "fisk"
diff --git a/README.md b/README.md index b0ab748..f54f8f1 100644 --- a/README.md +++ b/README.md @@ -1,82 +1,79 @@ # Statpipe -#fisk - -<some nice video here> # NAME statpipe - swiss knife statistics # DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. # SYNOPSIS tail -f some.log | statpipe \[options\] \[regex\] ... \[regex\] Regex is a perl regex, if the regex has a group 'something\\.(.\*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.\*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version # EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 # BUGS Probably plenty. # TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? # COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/
auduny/statpipe
df67bbf0913a9a8211b70c0dd74a754a487507aa
Adding a hackis logfaker
diff --git a/logfaker.pl b/logfaker.pl new file mode 100755 index 0000000..7f1c24a --- /dev/null +++ b/logfaker.pl @@ -0,0 +1,30 @@ +#!/usr/bin/perl + +use strict; +use Getopt::Long; +use Time::HiRes qw( time usleep); + +my $opt_bulk=1; +my $opt_wait=1; +my $opt_unbuffered=1; +# Unbuffered output +$| = 1; + + +my $result = GetOptions( +"b|buld=i" => \$opt_bulk, # how often do we update in time +"s|sleep=f" => \$opt_wait, # how often do we update in lines +"u|unbuffered=i" => \$opt_unbuffered); + +my $wait = $opt_wait * 1000000; +print "slowness is $wait"; + +open(my $fh, '<', $ARGV[0]) or die $!; + +my $linecounter = 0; +my @lines; +my $time = time(); +while (my $line = <$fh>) { + print $line; + usleep($wait); +} diff --git a/statpipe b/statpipe index 75bf102..ddf2afe 100755 --- a/statpipe +++ b/statpipe @@ -1,410 +1,411 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=1; # Default every 1 second my $opt_maxtime=0; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 0; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { + close STDIN; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); - exit(0); + exit; } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut diff --git a/testfiles/words b/testfiles/words.txt similarity index 100% rename from testfiles/words rename to testfiles/words.txt
auduny/statpipe
c71288f148af22d426ac5e9d9d87e83782d74e29
More sane defaults
diff --git a/README.md b/README.md index 829adca..b0ab748 100644 --- a/README.md +++ b/README.md @@ -1,81 +1,82 @@ # Statpipe +#fisk <some nice video here> # NAME statpipe - swiss knife statistics # DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. # SYNOPSIS tail -f some.log | statpipe \[options\] \[regex\] ... \[regex\] Regex is a perl regex, if the regex has a group 'something\\.(.\*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.\*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version # EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 # BUGS Probably plenty. # TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? # COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ diff --git a/statpipe b/statpipe index 7b50792..75bf102 100755 --- a/statpipe +++ b/statpipe @@ -1,410 +1,410 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none -my $opt_timefreq=5; # Default every 5 second -my $opt_maxtime=60; # Default 60 seconds +my $opt_timefreq=1; # Default every 1 second +my $opt_maxtime=0; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; -my $opt_limit = 30; +my $opt_limit = 0; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) - --timefreq|-t Frequency of output in seconds (5) + --timefreq|-t Frequency of output in seconds (1 second) --linefreq Frequency of output in lines (none) - --maxtime Time before closing the pipe in seconds (60) + --maxtime Time before closing the pipe in seconds (unlimited) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) - --limit Limit output of keys (30) + --limit Limit output of keys (0) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? TODO: Rare, reverse list =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
d34a9531eacce44b9b3ba3b9fb6c169f7fb75ebd
Adding TODO: Reverse list
diff --git a/statpipe b/statpipe index b8443c1..7b50792 100755 --- a/statpipe +++ b/statpipe @@ -1,409 +1,410 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =head1 BUGS Probably plenty. =head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? +TODO: Rare, reverse list =head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
7ae7bb7bbab4126182170379962d20826b92c2a9
lowercase
diff --git a/README.md b/README.md index 761e638..829adca 100644 --- a/README.md +++ b/README.md @@ -1,75 +1,81 @@ # Statpipe <some nice video here> # NAME statpipe - swiss knife statistics # DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. # SYNOPSIS tail -f some.log | statpipe \[options\] \[regex\] ... \[regex\] Regex is a perl regex, if the regex has a group 'something\\.(.\*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.\*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version # EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 +# BUGS + Probably plenty. +# TODO + TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? +# COPYRIGHT + Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ diff --git a/statpipe b/statpipe index b4d37fd..b8443c1 100755 --- a/statpipe +++ b/statpipe @@ -1,409 +1,409 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 -=HEAD1 BUGS +=head1 BUGS Probably plenty. -=HEAD1 TODO +=head1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? -=HEAD1 COPYRIGHT +=head1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
eb49e001d43750f642b7817f77dce6be96d8e9e0
Fixed README again
diff --git a/README.md b/README.md index 4282e40..761e638 100644 --- a/README.md +++ b/README.md @@ -1,75 +1,75 @@ # Statpipe <some nice video here> # NAME statpipe - swiss knife statistics # DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. # SYNOPSIS tail -f some.log | statpipe \[options\] \[regex\] ... \[regex\] Regex is a perl regex, if the regex has a group 'something\\.(.\*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.\*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version # EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif - - #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 + + Probably plenty. TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ diff --git a/statpipe b/statpipe index db7b47a..b4d37fd 100755 --- a/statpipe +++ b/statpipe @@ -1,409 +1,409 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif - #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift #Count all words in a file $ cat file | statpipe --multi '(\w)' #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 + =HEAD1 BUGS Probably plenty. =HEAD1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? =HEAD1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
7cb80f04a8d32676c27a74cef09792c4ac13e9bb
Pod yeh
diff --git a/README.md b/README.md index 6f6f643..4282e40 100644 --- a/README.md +++ b/README.md @@ -1,73 +1,75 @@ # Statpipe <some nice video here> # NAME statpipe - swiss knife statistics # DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. # SYNOPSIS tail -f some.log | statpipe \[options\] \[regex\] ... \[regex\] Regex is a perl regex, if the regex has a group 'something\\.(.\*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.\*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version # EXAMPLES -Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) - $ tail -f /var/log/httpd/access.log | statpipe -f 7 + #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) + $ tail -f /var/log/httpd/access.log | statpipe -f 7 -Seperate fields by " and show field two - $ tail -f /var/log/httpd/access.log | statpipe -d \\" -f 2 + #Seperate fields by " and show field two + $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 -Group jpeg and jpg differently - $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif + #Group jpeg and jpg differently + $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif -Group jpeg and jpg into one key - $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift -Count all words in a file - $ cat file | statpipe --multi '(\\w)' -List top 20 articles the last 10 seconds - $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\\d+)' --maxtime=10 --limit 20 --time=0 + #Group jpeg and jpg into one key + $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift + + #Count all words in a file + $ cat file | statpipe --multi '(\w)' + + #List top 20 articles the last 10 seconds + $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 Probably plenty. TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ diff --git a/statpipe b/statpipe index 912ba97..db7b47a 100755 --- a/statpipe +++ b/statpipe @@ -1,408 +1,409 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES -Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) + #Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 -Seperate fields by " and show field two + #Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 -Group jpeg and jpg differently + #Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif -Group jpeg and jpg into one key + + #Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift -Count all words in a file + #Count all words in a file $ cat file | statpipe --multi '(\w)' -List top 20 articles the last 10 seconds + #List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =HEAD1 BUGS Probably plenty. =HEAD1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? =HEAD1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
502e00bc823f78b658f8a3b95bdcdabceb1781c6
Fix README
diff --git a/README.md b/README.md index beac902..6f6f643 100644 --- a/README.md +++ b/README.md @@ -1,78 +1,73 @@ -# Statpipe. The one and only cooltool - -I like my tool +# Statpipe +<some nice video here> # NAME statpipe - swiss knife statistics +# DESCRIPTION + +statpipe is a excellent little tool to analyse logfiles, or any file +for that matter, and produce percentage of hits, hits per second and +other cool stuff. +It's supposed to be a better way of doing something similar to +tail -f | awk | cut| sort | unique -c |sort -g | whatever. + # SYNOPSIS tail -f some.log | statpipe \[options\] \[regex\] ... \[regex\] +Regex is a perl regex, if the regex has a group 'something\\.(.\*)' the +match will be used as a key instead of the regexp itself. + +If no regex and no --field argument is given. It will be as '^(.\*)$' was given. +Meaning that it will count all unique lines in the file/pipe. + Options: + --field|f What field top use as key (default all fields) + --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) - --field|f What field top use as key - --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) + --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version -If the regex has a grouping, the match will be used instead of the regex as a -key - - -# DESCRIPTION - -statpipe is a excellent little tool to analyse logfiles, or any file -for that matter, and produce percentage of hits, hits per second and -other cool stuff. -It's supposed to be a better way of doing something similar to -tail -f | awk | cut| sort | unique -c |sort -g | whatever. - -# OPTIONS - - --timefreq|-t - This changes the updateinterval of the statistics. Default is 5 seconds. - Set it to 0 to turn it off. - - --linefreq|-t - Same as above, just measured in number of lines parsed. Default is 0 (off) - - - +# EXAMPLES +Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) + $ tail -f /var/log/httpd/access.log | statpipe -f 7 -# EXAMPLES +Seperate fields by " and show field two + $ tail -f /var/log/httpd/access.log | statpipe -d \\" -f 2 - Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) - $ tail -f /var/log/httpd/access.log | statpipe -f 7 +Group jpeg and jpg differently + $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif - Seperate fields by " and show field two - $ tail -f /var/log/httpd/access.log | statpipe -d \\" -f 2 +Group jpeg and jpg into one key + $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift - Group jpeg and jpg differently - $ tail -f /var/log/httpd/access.log | statpipe jpe?g png gif +Count all words in a file + $ cat file | statpipe --multi '(\\w)' - Group jpeg and jpg into one key - $ tail -f /var/log/httpd/access.log | statpipe (jpe?g) png gif --not gift +List top 20 articles the last 10 seconds + $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\\d+)' --maxtime=10 --limit 20 --time=0 - List top articles the last 10 seconds - $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\\d+)' --maxtime=10 --limit 20 +Probably plenty. TODO: Merge ($1) ($2) etc. -TODO: Switch to caculate percentage of hits instead of total TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe +TODO: Read defaultsfile from .statpipe? - +Audun Ytterdal <audun@ytterdal.net> +http://github.com/auduny/statpipe/ diff --git a/pre.md b/pre.md index 75221bd..45be3b6 100644 --- a/pre.md +++ b/pre.md @@ -1,5 +1,4 @@ -# Statpipe. The one and only cooltool - -I like my tool +# Statpipe +<some nice video here> diff --git a/statpipe b/statpipe index ba16e67..912ba97 100755 --- a/statpipe +++ b/statpipe @@ -1,408 +1,408 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Regex is a perl regex, if the regex has a group 'something\.(.*)' the match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift Count all words in a file $ cat file | statpipe --multi '(\w)' -List top articles the last 10 seconds +List top 20 articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 =HEAD1 BUGS Probably plenty. =HEAD1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe TODO: Read defaultsfile from .statpipe? =HEAD1 COPYRIGHT Audun Ytterdal <audun@ytterdal.net> http://github.com/auduny/statpipe/ =cut
auduny/statpipe
1485c3d4dc492b6ce1c2791ac3d59fdd870fadad
More documentation
diff --git a/statpipe b/statpipe index 885aede..ba16e67 100755 --- a/statpipe +++ b/statpipe @@ -1,403 +1,408 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] -Regex is a perl regex, if the regex has a group '(.*)' the match will be used -as a key instead of the regexp itself. +Regex is a perl regex, if the regex has a group 'something\.(.*)' the +match will be used as a key instead of the regexp itself. If no regex and no --field argument is given. It will be as '^(.*)$' was given. Meaning that it will count all unique lines in the file/pipe. Options: --field|f What field top use as key (default all fields) --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES -=over 4 - Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) -$ tail -f /var/log/httpd/access.log | statpipe -f 7 + $ tail -f /var/log/httpd/access.log | statpipe -f 7 Seperate fields by " and show field two -$ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 + $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 Group jpeg and jpg differently -$ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif + $ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif Group jpeg and jpg into one key -$ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift + $ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift Count all words in a file -$ cat file | statpipe --multi '(\w)' + $ cat file | statpipe --multi '(\w)' List top articles the last 10 seconds -$ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 ---limit 20 --time=0 + $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 --time=0 + +=HEAD1 BUGS -=back +Probably plenty. =HEAD1 TODO TODO: Merge ($1) ($2) etc. TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe +TODO: Read defaultsfile from .statpipe? + +=HEAD1 COPYRIGHT + +Audun Ytterdal <audun@ytterdal.net> +http://github.com/auduny/statpipe/ =cut
auduny/statpipe
73244b91f19454483e9555a081be13a656c96149
More documentation
diff --git a/README.md b/README.md index 9f251ce..beac902 100644 --- a/README.md +++ b/README.md @@ -1,74 +1,78 @@ # Statpipe. The one and only cooltool I like my tool # NAME statpipe - swiss knife statistics # SYNOPSIS tail -f some.log | statpipe \[options\] \[regex\] ... \[regex\] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) --(no)hits Show hits per second (yes) --help Show help --version Show version +If the regex has a grouping, the match will be used instead of the regex as a +key + + # DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doing something similar to tail -f | awk | cut| sort | unique -c |sort -g | whatever. # OPTIONS --timefreq|-t This changes the updateinterval of the statistics. Default is 5 seconds. Set it to 0 to turn it off. --linefreq|-t Same as above, just measured in number of lines parsed. Default is 0 (off) # EXAMPLES Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \\" -f 2 Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe jpe?g png gif Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe (jpe?g) png gif --not gift List top articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\\d+)' --maxtime=10 --limit 20 TODO: Merge ($1) ($2) etc. TODO: Switch to caculate percentage of hits instead of total TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe diff --git a/statpipe b/statpipe index ca54efa..885aede 100755 --- a/statpipe +++ b/statpipe @@ -1,406 +1,403 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics -=cut +=head1 DESCRIPTION + +statpipe is a excellent little tool to analyse logfiles, or any file +for that matter, and produce percentage of hits, hits per second and +other cool stuff. +It's supposed to be a better way of doing something similar to +tail -f | awk | cut| sort | unique -c |sort -g | whatever. +=cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] +Regex is a perl regex, if the regex has a group '(.*)' the match will be used +as a key instead of the regexp itself. + +If no regex and no --field argument is given. It will be as '^(.*)$' was given. +Meaning that it will count all unique lines in the file/pipe. + Options: + --field|f What field top use as key (default all fields) + --delimiter|d What delimiter to use for fields (spaces) --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --multi|m Match multiple times per line (no) - --field|f What field top use as key - --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --clear Clear screen between updates --relative|r Show relative percentages (no) + --keysize|k Length of keys (output) --(no)hits Show hits per second (yes) --help Show help --version Show version -=head1 DESCRIPTION - -statpipe is a excellent little tool to analyse logfiles, or any file -for that matter, and produce percentage of hits, hits per second and -other cool stuff. -It's supposed to be a better way of doing something similar to -tail -f | awk | cut| sort | unique -c |sort -g | whatever. - -=head1 OPTIONS - - --timefreq|-t - This changes the updateinterval of the statistics. Default is 5 seconds. - Set it to 0 to turn it off. - - --linefreq|-t - Same as above, just measured in number of lines parsed. Default is 0 (off) - - - =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $restcount = 0; my $hitflag=0; my $now = time(); while (<STDIN>) { $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } if (!$hitflag) { $restcount++; } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $restcount / $divider ) * 100, $restcount / $diff, $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES =over 4 Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 Group jpeg and jpg differently -$ tail -f /var/log/httpd/access.log | statpipe jpe?g png gif +$ tail -f /var/log/httpd/access.log | statpipe 'jpe?g' png gif Group jpeg and jpg into one key -$ tail -f /var/log/httpd/access.log | statpipe (jpe?g) png gif --not gift +$ tail -f /var/log/httpd/access.log | statpipe '(jpe?g)' png gif --not gift + +Count all words in a file +$ cat file | statpipe --multi '(\w)' List top articles the last 10 seconds -$ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 +$ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 +--limit 20 --time=0 =back =HEAD1 TODO TODO: Merge ($1) ($2) etc. -TODO: Switch to caculate percentage of hits instead of total TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe - =cut
auduny/statpipe
5b4c42c8fb9e43205391671e13723aed724bf4d5
Added a prefile
diff --git a/README.md b/README.md index 41075c6..9f251ce 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,74 @@ +# Statpipe. The one and only cooltool + +I like my tool + + # NAME statpipe - swiss knife statistics # SYNOPSIS tail -f some.log | statpipe \[options\] \[regex\] ... \[regex\] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) - --maxtime|-m Time before closing the pipe in seconds (60) + --maxtime Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) + --multi|m Match multiple times per line (no) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive - --relative|r Show relative percentages + --clear Clear screen between updates + --relative|r Show relative percentages (no) --(no)hits Show hits per second (yes) --help Show help --version Show version # DESCRIPTION -statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. -It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk +statpipe is a excellent little tool to analyse logfiles, or any file +for that matter, and produce percentage of hits, hits per second and +other cool stuff. +It's supposed to be a better way of doing something similar to +tail -f | awk | cut| sort | unique -c |sort -g | whatever. + +# OPTIONS + + --timefreq|-t + This changes the updateinterval of the statistics. Default is 5 seconds. + Set it to 0 to turn it off. + + --linefreq|-t + Same as above, just measured in number of lines parsed. Default is 0 (off) + + + + # EXAMPLES -```lang=console + Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \\" -f 2 Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe jpe?g png gif Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe (jpe?g) png gif --not gift List top articles the last 10 seconds - $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\\d+)' --maxtime=10 --limit 20 + $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\\d+)' --maxtime=10 --limit 20 TODO: Merge ($1) ($2) etc. TODO: Switch to caculate percentage of hits instead of total TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe -``` - - -```style=colorful -foo = fisk -bar -zoo -``` -Ninja diff --git a/pre.md b/pre.md new file mode 100644 index 0000000..75221bd --- /dev/null +++ b/pre.md @@ -0,0 +1,5 @@ +# Statpipe. The one and only cooltool + +I like my tool + +
auduny/statpipe
a5ba618457a97d2eb0c9166c4db38eda391e4ca6
Adding more docs + tidying up total and rest
diff --git a/statpipe b/statpipe index a81df15..ca54efa 100755 --- a/statpipe +++ b/statpipe @@ -1,379 +1,406 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =cut my $version="1.0"; - use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time -"m|maxtime=i" => \$opt_maxtime, # when to stop -"maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines -"l|limit=i" => \$opt_limit, # how many do we print +"maxtime=i" => \$opt_maxtime, # when to stop +"maxlines=i" => \$opt_maxlines, # when to stop "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) +"l|limit=i" => \$opt_limit, # how many do we print "n|not=s" => \$opt_not, # Not these "m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) - --maxtime|-m Time before closing the pipe in seconds (60) + --maxtime Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) + --multi|m Match multiple times per line (no) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive + --clear Clear screen between updates --relative|r Show relative percentages (no) --(no)hits Show hits per second (yes) --help Show help --version Show version =head1 DESCRIPTION -statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. -It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk +statpipe is a excellent little tool to analyse logfiles, or any file +for that matter, and produce percentage of hits, hits per second and +other cool stuff. +It's supposed to be a better way of doing something similar to +tail -f | awk | cut| sort | unique -c |sort -g | whatever. + +=head1 OPTIONS + + --timefreq|-t + This changes the updateinterval of the statistics. Default is 5 seconds. + Set it to 0 to turn it off. + + --linefreq|-t + Same as above, just measured in number of lines parsed. Default is 0 (off) + + =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; +my $restcount = 0; +my $hitflag=0; my $now = time(); while (<STDIN>) { + $hitflag=0; $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines # if field is specified, use that instead of complete line if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } # Delete trailing space chop($object); $line=$object; } # skip lines that the user does not want if ($opt_not) { if ($opt_case) { if ($line =~ m/$opt_not/) { + $restcount++; next; } } else { if ($line =~ m/$opt_not/i) { + $restcount++; next; } } } # Magic starts here for my $reg (@ARGV) { # for each regex if ($opt_multi) { # Using multi match? my @linehits; if ($opt_case) { if (@linehits = $line =~ m/$reg/g ) { + $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } else { # Caseinsensetiv is the default if ( @linehits = $line =~ m/$reg/ig ) { + $hitflag=1; foreach my $linehit (@linehits) { $hitcount++; if ($1) { $objects->{$linehit}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } } # Default is not using multi match } else { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; + $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; + $hitflag=1; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; + $hitflag=1; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } + if (!$hitflag) { + $restcount++; + } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } - my $rest = $lines - $hitcount; if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total>", - ($hitcount / $lines) * 100, + ($hitcount / $divider) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount, $lines ); } - if ($rest) { + if ($restcount) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", - ( $rest / $divider ) * 100, - $rest / $diff, - $rest, $lines + ( $restcount / $divider ) * 100, + $restcount / $diff, + $restcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES =over 4 Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe jpe?g png gif Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe (jpe?g) png gif --not gift List top articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 =back =HEAD1 TODO TODO: Merge ($1) ($2) etc. TODO: Switch to caculate percentage of hits instead of total TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe =cut
auduny/statpipe
c158dd93f52e9aad5eab4d986a219320a2c367f1
Added support for multiline matches
diff --git a/statpipe b/statpipe index 94846c4..a81df15 100755 --- a/statpipe +++ b/statpipe @@ -1,336 +1,379 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "m|maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines "l|limit=i" => \$opt_limit, # how many do we print "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "n|not=s" => \$opt_not, # Not these +"m|multi" => \$opt_multi, # Multimatch for each line "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --relative|r Show relative percentages (no) --(no)hits Show hits per second (yes) --help Show help --version Show version =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $now = time(); while (<STDIN>) { $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { - if ($lines >= $opt_maxlines) { + if ($lines > $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines - if ($opt_field) { # which field to use + + # if field is specified, use that instead of complete line + if ($opt_field) { my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } + # Delete trailing space chop($object); $line=$object; } + + # skip lines that the user does not want if ($opt_not) { - if ($line =~ m/$opt_not/) { - next; + if ($opt_case) { + if ($line =~ m/$opt_not/) { + next; + } + } else { + if ($line =~ m/$opt_not/i) { + next; + } } } - for my $reg (@ARGV) { - if ($opt_case) { - if ( $line =~ m/$reg/ ) { - $hitcount++; - if ($1) { - $objects->{$1}++; # add match as key - } else { - $objects->{$reg}++; # add regex as key + + # Magic starts here + for my $reg (@ARGV) { # for each regex + if ($opt_multi) { # Using multi match? + my @linehits; + if ($opt_case) { + if (@linehits = $line =~ m/$reg/g ) { + foreach my $linehit (@linehits) { + $hitcount++; + if ($1) { + $objects->{$linehit}++; # add match as key + } else { + $objects->{$reg}++; # add regex as key + } + } + } + } else { + # Caseinsensetiv is the default + if ( @linehits = $line =~ m/$reg/ig ) { + foreach my $linehit (@linehits) { + $hitcount++; + if ($1) { + $objects->{$linehit}++; # add match as key + } else { + $objects->{$reg}++; # add regex as key + } + } } } - } - else { - if ( $line =~ m/$reg/i ) { # caseinsensetive is default - $hitcount++; - if ($1) { - $objects->{$1}++; # add match as key - } else { - $objects->{$reg}++; # add regexp as key + # Default is not using multi match + } else { + if ($opt_case) { + if ( $line =~ m/$reg/ ) { + $hitcount++; + if ($1) { + $objects->{$1}++; # add match as key + } else { + $objects->{$reg}++; # add regex as key + } + } + } + else { + if ( $line =~ m/$reg/i ) { # caseinsensetive is default + $hitcount++; + if ($1) { + $objects->{$1}++; # add match as key + } else { + $objects->{$reg}++; # add regexp as key + } } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; $objects->{$line}++; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } my $rest = $lines - $hitcount; if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total>", ($hitcount / $lines) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($rest) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest / $diff, $rest, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES =over 4 Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe jpe?g png gif Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe (jpe?g) png gif --not gift List top articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 =back =HEAD1 TODO TODO: Merge ($1) ($2) etc. TODO: Switch to caculate percentage of hits instead of total TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe =cut diff --git a/testfile b/testfile index cc1ceeb..95c2001 100644 --- a/testfile +++ b/testfile @@ -1,8 +1,11 @@ foo foo foo -bar -bar +bar bar bar +bar bar zoo zoo zoo +ninja +pirate +nin
auduny/statpipe
505f2b1e0bdd2b49ba6d1b36f45abcea3e2f8ff0
Make -f field go first so we can use regexp based on that.
diff --git a/statpipe b/statpipe index 016b99c..94846c4 100755 --- a/statpipe +++ b/statpipe @@ -1,337 +1,336 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds -my $opt_maxlines=0; # Stop at five million lines +my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen -my $opt_relative=0; +my $opt_relative=0; my $result = GetOptions( -"t|timefreq=i" => \$opt_timefreq, # how often do we update in time + "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "m|maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines "l|limit=i" => \$opt_limit, # how many do we print "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "n|not=s" => \$opt_not, # Not these "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s -"h|help" => \$opt_help, # Print help +"h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version -); +); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --relative|r Show relative percentages (no) --(no)hits Show hits per second (yes) --help Show help --version Show version =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { - print "$version\n"; + print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $now = time(); while (<STDIN>) { $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines >= $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines + if ($opt_field) { # which field to use + my @fields = split(",",$opt_field); + my @fieldlist = split(/$opt_delimiter/,$line); + my $object; + for my $field (@fields) { + $object .= "$fieldlist[($field-1)] "; + } + chop($object); + $line=$object; + } + if ($opt_not) { if ($line =~ m/$opt_not/) { next; } } for my $reg (@ARGV) { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; - if ($opt_field) { # which field to use - my @fields = split(",",$opt_field); - my @fieldlist = split(/$opt_delimiter/,$line); - my $object; - for my $field (@fields) { - $object .= "$fieldlist[($field-1)] "; - } - chop($object); - $objects->{$object}++; - } - else { - $objects->{$line}++; - } + $objects->{$line}++; } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } my $rest = $lines - $hitcount; if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total>", ($hitcount / $lines) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", - "<total>", + "<total>", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($rest) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest / $diff, $rest, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { if (!$lines) { print "No lines parsed, did you feed me through a pipe?\n"; pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES =over 4 Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe jpe?g png gif Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe (jpe?g) png gif --not gift List top articles the last 10 seconds -$ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 +$ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 =back =HEAD1 TODO TODO: Merge ($1) ($2) etc. TODO: Switch to caculate percentage of hits instead of total TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe =cut
auduny/statpipe
d1cbaa418d205d335c807dc60e5a5ba0c4152d44
Fix division by zero
diff --git a/statpipe b/statpipe index 1f5569f..016b99c 100755 --- a/statpipe +++ b/statpipe @@ -1,332 +1,337 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "m|maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines "l|limit=i" => \$opt_limit, # how many do we print "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "n|not=s" => \$opt_not, # Not these "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --relative|r Show relative percentages (no) --(no)hits Show hits per second (yes) --help Show help --version Show version =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $now = time(); while (<STDIN>) { $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines >= $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines if ($opt_not) { if ($line =~ m/$opt_not/) { next; } } for my $reg (@ARGV) { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; if ($opt_field) { # which field to use my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } chop($object); $objects->{$object}++; } else { $objects->{$line}++; } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } my $rest = $lines - $hitcount; if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<total>", ($hitcount / $lines) * 100, $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total>", ($hitcount / $divider) * 100, $hitcount, $lines ); } if ($rest) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest / $diff, $rest, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } print "\n"; } sub end_pipe { + if (!$lines) { + print "No lines parsed, did you feed me through a pipe?\n"; + pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); + exit(0); + } print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES =over 4 Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe jpe?g png gif Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe (jpe?g) png gif --not gift List top articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 =back =HEAD1 TODO TODO: Merge ($1) ($2) etc. TODO: Switch to caculate percentage of hits instead of total TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe =cut
auduny/statpipe
27607113323613fed0685374d8c7b8ec8b10767e
More small fixes to logic
diff --git a/statpipe b/statpipe index e1c3e29..1f5569f 100755 --- a/statpipe +++ b/statpipe @@ -1,330 +1,332 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "m|maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines "l|limit=i" => \$opt_limit, # how many do we print "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "n|not=s" => \$opt_not, # Not these "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --relative|r Show relative percentages (no) --(no)hits Show hits per second (yes) --help Show help --version Show version =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $now = time(); while (<STDIN>) { $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines >= $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines if ($opt_not) { if ($line =~ m/$opt_not/) { next; } } for my $reg (@ARGV) { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; if ($opt_field) { # which field to use my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } chop($object); $objects->{$object}++; } else { $objects->{$line}++; } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( - "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d uniqe)/%d)\n", + "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( - "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d unique)/%d)\n", + "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } my $rest = $lines - $hitcount; + if ($opt_hits) { + printf( + "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", + "<total>", + ($hitcount / $lines) * 100, + $hitcount / $diff, + $hitcount, $lines + ); + } + else { + printf( + "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", + "<total>", + ($hitcount / $divider) * 100, + $hitcount, $lines + ); + } + if ($rest) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest / $diff, $rest, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } - if ($opt_hits) { - printf( - "%-".$opt_keysize."s: (100 %) (%.1f h/s) (%d/%d)\n", - "<total>", - $hitcount / $diff, - $hitcount, $lines - ); - } - else { - printf( - "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", - "<total>", ( $objects->{$reg} / $divider ) * 100, - $objects->{$reg}, $lines - ); - } - print "\n"; } sub end_pipe { print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES =over 4 Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe jpe?g png gif Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe (jpe?g) png gif --not gift List top articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 =back =HEAD1 TODO TODO: Merge ($1) ($2) etc. TODO: Switch to caculate percentage of hits instead of total TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe =cut
auduny/statpipe
95196d35acd5df9a9437708504c782c69ac90444
Change default keysize and fixed limited string
diff --git a/statpipe b/statpipe index 6ca07b2..e1c3e29 100755 --- a/statpipe +++ b/statpipe @@ -1,330 +1,330 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces -my $opt_keysize = 40; +my $opt_keysize = 30; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "m|maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines "l|limit=i" => \$opt_limit, # how many do we print "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "n|not=s" => \$opt_not, # Not these "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --relative|r Show relative percentages (no) --(no)hits Show hits per second (yes) --help Show help --version Show version =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $now = time(); while (<STDIN>) { $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines >= $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines if ($opt_not) { if ($line =~ m/$opt_not/) { next; } } for my $reg (@ARGV) { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; if ($opt_field) { # which field to use my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } chop($object); $objects->{$object}++; } else { $objects->{$line}++; } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( - "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d) hits(uniq) / %d)\n", + "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d uniqe)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( - "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d) hits(uniq) / %d)\n", + "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d unique)/%d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } my $rest = $lines - $hitcount; if ($rest) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest / $diff, $rest, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (100 %) (%.1f h/s) (%d/%d)\n", "<total>", $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total>", ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } print "\n"; } sub end_pipe { print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES =over 4 Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe jpe?g png gif Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe (jpe?g) png gif --not gift List top articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 =back =HEAD1 TODO TODO: Merge ($1) ($2) etc. TODO: Switch to caculate percentage of hits instead of total TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe =cut
auduny/statpipe
94c41882de53400eba3b87845c5fbd344912ee45
Default for relative
diff --git a/statpipe b/statpipe index 169b441..6ca07b2 100755 --- a/statpipe +++ b/statpipe @@ -1,330 +1,330 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_keysize = 40; my $opt_help = 0; my $opt_version = 0; my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "m|maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines "l|limit=i" => \$opt_limit, # how many do we print "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "n|not=s" => \$opt_not, # Not these "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "r|relative!" => \$opt_relative, # show relative percentages for hits "k|keysize=i" => \$opt_keysize, # What delimiter to use "hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive - --relative|r Show relative percentages + --relative|r Show relative percentages (no) --(no)hits Show hits per second (yes) --help Show help --version Show version =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $hitcount = 0; my $now = time(); while (<STDIN>) { $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines >= $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines if ($opt_not) { if ($line =~ m/$opt_not/) { next; } } for my $reg (@ARGV) { if ($opt_case) { if ( $line =~ m/$reg/ ) { $hitcount++; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default $hitcount++; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } if ( !@ARGV ) { # we didn't send regexp, count every line $hitcount++; if ($opt_field) { # which field to use my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } chop($object); $objects->{$object}++; } else { $objects->{$line}++; } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $limit = 0; my $hitlimit; my $limitedhits = 0; my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { if ($opt_relative) { $divider=$hitcount; } else { $divider=$lines; } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } my $rest = $lines - $hitcount; if ($rest) { if ($opt_hits) { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest / $diff, $rest, $lines ); } else { printf( "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } if ($opt_hits) { printf( "%-".$opt_keysize."s: (100 %) (%.1f h/s) (%d/%d)\n", "<total>", $hitcount / $diff, $hitcount, $lines ); } else { printf( "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", "<total>", ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } print "\n"; } sub end_pipe { print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES =over 4 Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe jpe?g png gif Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe (jpe?g) png gif --not gift List top articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 =back =HEAD1 TODO TODO: Merge ($1) ($2) etc. TODO: Switch to caculate percentage of hits instead of total TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe =cut
auduny/statpipe
81ea5b85340c242f59dc7865e1d9d1eba5785168
Added support for changing keysize and using relative percentages.
diff --git a/README.md b/README.md index 5684a46..a42eb3e 100644 --- a/README.md +++ b/README.md @@ -1,50 +1,51 @@ # NAME statpipe - swiss knife statistics # SYNOPSIS tail -f some.log | statpipe \[options\] \[regex\] ... \[regex\] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive - --hits Show hits per second (yes) + --relative|r Show relative percentages + --(no)hits Show hits per second (yes) --help Show help --version Show version # DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk # EXAMPLES Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \\" -f 2 Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe jpe?g png gif Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe (jpe?g) png gif --not gift List top articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\\d+)' --maxtime=10 --limit 20 TODO: Merge ($1) ($2) etc. TODO: Switch to caculate percentage of hits instead of total TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe diff --git a/statpipe b/statpipe index c797a72..169b441 100755 --- a/statpipe +++ b/statpipe @@ -1,319 +1,330 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces +my $opt_keysize = 40; my $opt_help = 0; my $opt_version = 0; +my $opt_hits=1; # Show hits per second my $opt_clear=0; #Don't clean screen -my $opt_hits=1; # show hits per second +my $opt_relative=0; my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "m|maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines "l|limit=i" => \$opt_limit, # how many do we print "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "n|not=s" => \$opt_not, # Not these "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use -"h|hits!" => \$opt_hits, # show hits/s +"r|relative!" => \$opt_relative, # show relative percentages for hits +"k|keysize=i" => \$opt_keysize, # What delimiter to use +"hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive - --hits Show hits per second (yes) + --relative|r Show relative percentages + --(no)hits Show hits per second (yes) --help Show help --version Show version =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; +my $hitcount = 0; my $now = time(); while (<STDIN>) { $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines >= $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines if ($opt_not) { if ($line =~ m/$opt_not/) { next; } } for my $reg (@ARGV) { if ($opt_case) { if ( $line =~ m/$reg/ ) { + $hitcount++; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default + $hitcount++; if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } if ( !@ARGV ) { # we didn't send regexp, count every line + $hitcount++; if ($opt_field) { # which field to use my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } chop($object); $objects->{$object}++; } else { $objects->{$line}++; } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; - my $hitsum = 0; my $limit = 0; my $hitlimit; my $limitedhits = 0; + my $divider=0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } - # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { - $hitsum += $objects->{$reg}; + if ($opt_relative) { + $divider=$hitcount; + } else { + $divider=$lines; + } if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( - "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", + "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", $reg, - ( $objects->{$reg} / $lines ) * 100, + ( $objects->{$reg} / $divider ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( - "%-25s : (%.1f%%) (%d hits / %d)\n", - $reg, ( $objects->{$reg} / $lines ) * 100, + "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", + $reg, ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( - "%-25s : (%.1f%%) (%.1f hits/s) (%d(%d) hits(uniq) / %d)\n", + "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d(%d) hits(uniq) / %d)\n", "<limited>", - ( $limitedhits / $lines ) * 100, + ( $limitedhits / $divider ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( - "%-25s : (%.1f%%) (%d(%d) hits(uniq) / %d)\n", - "<limited>", ( $limitedhits / $lines ) * 100, + "%-".$opt_keysize."s: (%-4.1f%%) (%d(%d) hits(uniq) / %d)\n", + "<limited>", ( $limitedhits / $divider ) * 100, $limitedhits, $hitlimit, $lines ); } } - my $rest = $lines - $hitsum; + my $rest = $lines - $hitcount; if ($rest) { if ($opt_hits) { printf( - "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", + "%-".$opt_keysize."s: (%-4.1f%%) (%.1f h/s) (%d/%d)\n", "<rest>", - ( $rest / $lines ) * 100, + ( $rest / $divider ) * 100, $rest / $diff, $rest, $lines ); } else { printf( - "%-25s : (%.1f%%) (%d hits / %d)\n", - "<rest>", ( $rest / $lines ) * 100, + "%-".$opt_keysize."s: (%-4.1f%%) (%d/%d)\n", + "<rest>", ( $rest / $divider ) * 100, $rest, $lines ); } } if ($opt_hits) { printf( - "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", + "%-".$opt_keysize."s: (100 %) (%.1f h/s) (%d/%d)\n", "<total>", - 100, - $hitsum / $diff, - $hitsum, $lines + $hitcount / $diff, + $hitcount, $lines ); } else { printf( - "%-25s : (%.1f%%) (%d hits / %d)\n", - $reg, ( $objects->{$reg} / $lines ) * 100, + "%-".$opt_keysize."s: (%.1f%%) (%d/%d)\n", + "<total>", ( $objects->{$reg} / $divider ) * 100, $objects->{$reg}, $lines ); } print "\n"; } sub end_pipe { print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES =over 4 Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe jpe?g png gif Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe (jpe?g) png gif --not gift List top articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 =back =HEAD1 TODO TODO: Merge ($1) ($2) etc. TODO: Switch to caculate percentage of hits instead of total TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe =cut
auduny/statpipe
9af1ad7b6c0be67e69d48dcb8e2a9e7ab87ba34b
Added # to shebang.
diff --git a/statpipe b/statpipe index 37f7141..c797a72 100755 --- a/statpipe +++ b/statpipe @@ -1,319 +1,319 @@ -!/usr/bin/perl +#!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME statpipe - swiss knife statistics =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_help = 0; my $opt_version = 0; my $opt_clear=0; #Don't clean screen my $opt_hits=1; # show hits per second my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "m|maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines "l|limit=i" => \$opt_limit, # how many do we print "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "n|not=s" => \$opt_not, # Not these "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "h|hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | statpipe [options] [regex] ... [regex] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --hits Show hits per second (yes) --help Show help --version Show version =head1 DESCRIPTION statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk =cut if ($opt_help) { pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $now = time(); while (<STDIN>) { $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines >= $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines if ($opt_not) { if ($line =~ m/$opt_not/) { next; } } for my $reg (@ARGV) { if ($opt_case) { if ( $line =~ m/$reg/ ) { if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } if ( !@ARGV ) { # we didn't send regexp, count every line if ($opt_field) { # which field to use my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } chop($object); $objects->{$object}++; } else { $objects->{$line}++; } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $hitsum = 0; my $limit = 0; my $hitlimit; my $limitedhits = 0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { $hitsum += $objects->{$reg}; if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-25s : (%.1f%%) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits, $hitlimit, $lines ); } } my $rest = $lines - $hitsum; if ($rest) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest / $diff, $rest, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest, $lines ); } } if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<total>", 100, $hitsum / $diff, $hitsum, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } print "\n"; } sub end_pipe { print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES =over 4 Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | statpipe -f 7 Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | statpipe jpe?g png gif Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | statpipe (jpe?g) png gif --not gift List top articles the last 10 seconds $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 =back =HEAD1 TODO TODO: Merge ($1) ($2) etc. TODO: Switch to caculate percentage of hits instead of total TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe =cut
auduny/statpipe
0457dad57d5f086dd6d2d6c4daf77ee29aa43c1d
Changing name to statpipe
diff --git a/README.md b/README.md index fb79533..5684a46 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,50 @@ # NAME -Pipestat - swiss knife statistics +statpipe - swiss knife statistics # SYNOPSIS -tail -f some.log | pipestat \[options\] \[regex\] ... \[regex\] +tail -f some.log | statpipe \[options\] \[regex\] ... \[regex\] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --hits Show hits per second (yes) --help Show help --version Show version # DESCRIPTION -Pipestat is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. +statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk # EXAMPLES -```console -Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) -$ tail -f /var/log/httpd/access.log | pipestat -f 7 -``` + + Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) + $ tail -f /var/log/httpd/access.log | statpipe -f 7 + Seperate fields by " and show field two - $ tail -f /var/log/httpd/access.log | pipestat -d \\" -f 2 + $ tail -f /var/log/httpd/access.log | statpipe -d \\" -f 2 Group jpeg and jpg differently - $ tail -f /var/log/httpd/access.log | pipestat jpe?g png gif + $ tail -f /var/log/httpd/access.log | statpipe jpe?g png gif Group jpeg and jpg into one key - $ tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif --not gift + $ tail -f /var/log/httpd/access.log | statpipe (jpe?g) png gif --not gift List top articles the last 10 seconds - $ tail -f /var/log/httpd/access.log | pipestat 'artid=(\\d+)' --maxtime=10 --limit 20 + $ tail -f /var/log/httpd/access.log | statpipe 'artid=(\\d+)' --maxtime=10 --limit 20 + +TODO: Merge ($1) ($2) etc. +TODO: Switch to caculate percentage of hits instead of total +TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe + + diff --git a/pipestat b/statpipe similarity index 93% rename from pipestat rename to statpipe index de0769b..37f7141 100755 --- a/pipestat +++ b/statpipe @@ -1,319 +1,319 @@ -#!/usr/bin/perl +!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. =head1 NAME -Pipestat - swiss knife statistics +statpipe - swiss knife statistics =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_help = 0; my $opt_version = 0; my $opt_clear=0; #Don't clean screen my $opt_hits=1; # show hits per second my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "m|maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines "l|limit=i" => \$opt_limit, # how many do we print "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "n|not=s" => \$opt_not, # Not these "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "h|hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS -tail -f some.log | pipestat [options] [regex] ... [regex] +tail -f some.log | statpipe [options] [regex] ... [regex] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --hits Show hits per second (yes) --help Show help --version Show version =head1 DESCRIPTION -Pipestat is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. +statpipe is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk =cut if ($opt_help) { - pod2usage("Pipestat $version by Audun Ytterdal <audun\@ytterdal.net>\n"); + pod2usage("statpipe $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $now = time(); while (<STDIN>) { $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines >= $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines if ($opt_not) { if ($line =~ m/$opt_not/) { next; } } for my $reg (@ARGV) { if ($opt_case) { if ( $line =~ m/$reg/ ) { if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } if ( !@ARGV ) { # we didn't send regexp, count every line if ($opt_field) { # which field to use my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } chop($object); $objects->{$object}++; } else { $objects->{$line}++; } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $hitsum = 0; my $limit = 0; my $hitlimit; my $limitedhits = 0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { $hitsum += $objects->{$reg}; if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-25s : (%.1f%%) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits, $hitlimit, $lines ); } } my $rest = $lines - $hitsum; if ($rest) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest / $diff, $rest, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest, $lines ); } } if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<total>", 100, $hitsum / $diff, $hitsum, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } print "\n"; } sub end_pipe { print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES =over 4 Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) -$ tail -f /var/log/httpd/access.log | pipestat -f 7 +$ tail -f /var/log/httpd/access.log | statpipe -f 7 Seperate fields by " and show field two -$ tail -f /var/log/httpd/access.log | pipestat -d \" -f 2 +$ tail -f /var/log/httpd/access.log | statpipe -d \" -f 2 Group jpeg and jpg differently -$ tail -f /var/log/httpd/access.log | pipestat jpe?g png gif +$ tail -f /var/log/httpd/access.log | statpipe jpe?g png gif Group jpeg and jpg into one key -$ tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif --not gift +$ tail -f /var/log/httpd/access.log | statpipe (jpe?g) png gif --not gift List top articles the last 10 seconds -$ tail -f /var/log/httpd/access.log | pipestat 'artid=(\d+)' --maxtime=10 --limit 20 +$ tail -f /var/log/httpd/access.log | statpipe 'artid=(\d+)' --maxtime=10 --limit 20 =back =HEAD1 TODO TODO: Merge ($1) ($2) etc. TODO: Switch to caculate percentage of hits instead of total -TODO: Name change: PMS? (Poor mans Splunk) +TODO: Name change: PMS? (Poor mans Splunk) (Pipe measure system), statpipe =cut
auduny/statpipe
35391f5cfb3b9d9e65d20b74f16d95806821cf43
More examples
diff --git a/README.md b/README.md index 5647c4c..44d023e 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,44 @@ # NAME Pipestat - swiss knife statistics # SYNOPSIS tail -f some.log | pipestat \[options\] \[regex\] ... \[regex\] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --hits Show hits per second (yes) --help Show help --version Show version # DESCRIPTION Pipestat is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk # EXAMPLES - Show field two + Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | pipestat -f 7 Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | pipestat -d \\" -f 2 Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | pipestat jpe?g png gif Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif --not gift List top articles the last 10 seconds $ tail -f /var/log/httpd/access.log | pipestat 'artid=(\\d+)' --maxtime=10 --limit 20 diff --git a/pipestat b/pipestat index d4bfada..9c0c202 100755 --- a/pipestat +++ b/pipestat @@ -1,314 +1,314 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. # TODO: Merge ($1) ($2) etc. # TODO: Switch to caculate percentage of hits instead of total =head1 NAME Pipestat - swiss knife statistics =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_help = 0; my $opt_version = 0; my $opt_clear=0; #Don't clean screen my $opt_hits=1; # show hits per second my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "m|maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines "l|limit=i" => \$opt_limit, # how many do we print "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "n|not=s" => \$opt_not, # Not these "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "h|hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | pipestat [options] [regex] ... [regex] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --hits Show hits per second (yes) --help Show help --version Show version =head1 DESCRIPTION Pipestat is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk =cut if ($opt_help) { pod2usage("Pipestat $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $now = time(); while (<STDIN>) { $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines >= $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines if ($opt_not) { if ($line =~ m/$opt_not/) { next; } } for my $reg (@ARGV) { if ($opt_case) { if ( $line =~ m/$reg/ ) { if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } if ( !@ARGV ) { # we didn't send regexp, count every line if ($opt_field) { # which field to use my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } chop($object); $objects->{$object}++; } else { $objects->{$line}++; } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $hitsum = 0; my $limit = 0; my $hitlimit; my $limitedhits = 0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { $hitsum += $objects->{$reg}; if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-25s : (%.1f%%) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits, $hitlimit, $lines ); } } my $rest = $lines - $hitsum; if ($rest) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest / $diff, $rest, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest, $lines ); } } if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<total>", 100, $hitsum / $diff, $hitsum, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } print "\n"; } sub end_pipe { print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES =over 4 -Show field two +Show top 30 visited urls. Update it every 5 seconds for 60 seconds (default) $ tail -f /var/log/httpd/access.log | pipestat -f 7 Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | pipestat -d \" -f 2 Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | pipestat jpe?g png gif Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif --not gift List top articles the last 10 seconds $ tail -f /var/log/httpd/access.log | pipestat 'artid=(\d+)' --maxtime=10 --limit 20 =back =cut
auduny/statpipe
a9e7bb8142f115ebcde57da70d13480feacefc05
I'm not really friends with markdown
diff --git a/README.md b/README.md index c325092..5647c4c 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,44 @@ # NAME Pipestat - swiss knife statistics # SYNOPSIS tail -f some.log | pipestat \[options\] \[regex\] ... \[regex\] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --hits Show hits per second (yes) --help Show help --version Show version # DESCRIPTION Pipestat is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk # EXAMPLES Show field two $ tail -f /var/log/httpd/access.log | pipestat -f 7 - \# Seperate fields by " and show field two + Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | pipestat -d \\" -f 2 - \# Group jpeg and jpg differently + Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | pipestat jpe?g png gif - \# Group jpeg and jpg into one key + Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif --not gift - \# List top articles the last 10 seconds + List top articles the last 10 seconds $ tail -f /var/log/httpd/access.log | pipestat 'artid=(\\d+)' --maxtime=10 --limit 20 diff --git a/pipestat b/pipestat index 7c6b82e..d4bfada 100755 --- a/pipestat +++ b/pipestat @@ -1,314 +1,314 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. # TODO: Merge ($1) ($2) etc. # TODO: Switch to caculate percentage of hits instead of total =head1 NAME Pipestat - swiss knife statistics =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_help = 0; my $opt_version = 0; my $opt_clear=0; #Don't clean screen my $opt_hits=1; # show hits per second my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "m|maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines "l|limit=i" => \$opt_limit, # how many do we print "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "n|not=s" => \$opt_not, # Not these "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "h|hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | pipestat [options] [regex] ... [regex] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --hits Show hits per second (yes) --help Show help --version Show version =head1 DESCRIPTION Pipestat is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk =cut if ($opt_help) { pod2usage("Pipestat $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $now = time(); while (<STDIN>) { $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines >= $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines if ($opt_not) { if ($line =~ m/$opt_not/) { next; } } for my $reg (@ARGV) { if ($opt_case) { if ( $line =~ m/$reg/ ) { if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } if ( !@ARGV ) { # we didn't send regexp, count every line if ($opt_field) { # which field to use my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } chop($object); $objects->{$object}++; } else { $objects->{$line}++; } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $hitsum = 0; my $limit = 0; my $hitlimit; my $limitedhits = 0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { $hitsum += $objects->{$reg}; if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-25s : (%.1f%%) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits, $hitlimit, $lines ); } } my $rest = $lines - $hitsum; if ($rest) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest / $diff, $rest, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest, $lines ); } } if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<total>", 100, $hitsum / $diff, $hitsum, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } print "\n"; } sub end_pipe { print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES =over 4 Show field two $ tail -f /var/log/httpd/access.log | pipestat -f 7 -# Seperate fields by " and show field two +Seperate fields by " and show field two $ tail -f /var/log/httpd/access.log | pipestat -d \" -f 2 -# Group jpeg and jpg differently +Group jpeg and jpg differently $ tail -f /var/log/httpd/access.log | pipestat jpe?g png gif -# Group jpeg and jpg into one key +Group jpeg and jpg into one key $ tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif --not gift -# List top articles the last 10 seconds +List top articles the last 10 seconds $ tail -f /var/log/httpd/access.log | pipestat 'artid=(\d+)' --maxtime=10 --limit 20 =back =cut
auduny/statpipe
bad2c6ae122c5fcc349e0d6138a471747d04398c
Documentation to markdown
diff --git a/README.md b/README.md index bf9ee6f..c325092 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,44 @@ # NAME Pipestat - swiss knife statistics # SYNOPSIS tail -f some.log | pipestat \[options\] \[regex\] ... \[regex\] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --hits Show hits per second (yes) --help Show help --version Show version # DESCRIPTION Pipestat is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk # EXAMPLES - tail -f /var/log/httpd/access.log | pipestat -f 7 + Show field two + $ tail -f /var/log/httpd/access.log | pipestat -f 7 - tail -f /var/log/httpd/access.log | pipestat -d \\" -f 2 + \# Seperate fields by " and show field two + $ tail -f /var/log/httpd/access.log | pipestat -d \\" -f 2 - tail -f /var/log/httpd/access.log | pipestat jpe?g png gif + \# Group jpeg and jpg differently + $ tail -f /var/log/httpd/access.log | pipestat jpe?g png gif - tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif + \# Group jpeg and jpg into one key + $ tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif --not gift - tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif - - tail -f /var/log/httpd/access.log | pipestat 'artid=(\\d+)' --maxtime=30 --limit 20 + \# List top articles the last 10 seconds + $ tail -f /var/log/httpd/access.log | pipestat 'artid=(\\d+)' --maxtime=10 --limit 20
auduny/statpipe
6d44003b45d48cd963b83496eac5b9f25530b270
More documentation
diff --git a/pipestat b/pipestat index b101fc6..7c6b82e 100755 --- a/pipestat +++ b/pipestat @@ -1,311 +1,314 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. # TODO: Merge ($1) ($2) etc. # TODO: Switch to caculate percentage of hits instead of total =head1 NAME Pipestat - swiss knife statistics =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_help = 0; my $opt_version = 0; my $opt_clear=0; #Don't clean screen my $opt_hits=1; # show hits per second my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "m|maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines "l|limit=i" => \$opt_limit, # how many do we print "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "n|not=s" => \$opt_not, # Not these "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "h|hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | pipestat [options] [regex] ... [regex] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --hits Show hits per second (yes) --help Show help --version Show version =head1 DESCRIPTION Pipestat is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk =cut if ($opt_help) { pod2usage("Pipestat $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $now = time(); while (<STDIN>) { $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines >= $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines if ($opt_not) { if ($line =~ m/$opt_not/) { next; } } for my $reg (@ARGV) { if ($opt_case) { if ( $line =~ m/$reg/ ) { if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } if ( !@ARGV ) { # we didn't send regexp, count every line if ($opt_field) { # which field to use my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } chop($object); $objects->{$object}++; } else { $objects->{$line}++; } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $hitsum = 0; my $limit = 0; my $hitlimit; my $limitedhits = 0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { $hitsum += $objects->{$reg}; if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-25s : (%.1f%%) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits, $hitlimit, $lines ); } } my $rest = $lines - $hitsum; if ($rest) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest / $diff, $rest, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest, $lines ); } } if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<total>", 100, $hitsum / $diff, $hitsum, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } print "\n"; } sub end_pipe { print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES =over 4 -tail -f /var/log/httpd/access.log | pipestat -f 7 +Show field two +$ tail -f /var/log/httpd/access.log | pipestat -f 7 -tail -f /var/log/httpd/access.log | pipestat -d \" -f 2 +# Seperate fields by " and show field two +$ tail -f /var/log/httpd/access.log | pipestat -d \" -f 2 -tail -f /var/log/httpd/access.log | pipestat jpe?g png gif +# Group jpeg and jpg differently +$ tail -f /var/log/httpd/access.log | pipestat jpe?g png gif -tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif +# Group jpeg and jpg into one key +$ tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif --not gift -tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif - -tail -f /var/log/httpd/access.log | pipestat 'artid=(\d+)' --maxtime=30 --limit 20 +# List top articles the last 10 seconds +$ tail -f /var/log/httpd/access.log | pipestat 'artid=(\d+)' --maxtime=10 --limit 20 =back =cut
auduny/statpipe
90a30ea1ffa6b41f350980c670ba3f7fad02167a
Fixed README
diff --git a/README.md b/README.md index 846c763..bf9ee6f 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,41 @@ # NAME Pipestat - swiss knife statistics # SYNOPSIS tail -f some.log | pipestat \[options\] \[regex\] ... \[regex\] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --hits Show hits per second (yes) --help Show help --version Show version # DESCRIPTION Pipestat is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk # EXAMPLES -- tail -f /var/log/httpd/access.log | pipestat -f 7 + tail -f /var/log/httpd/access.log | pipestat -f 7 - I love norwegian country + tail -f /var/log/httpd/access.log | pipestat -d \\" -f 2 -- tail -f /var/log/httpd/access.log | pipestat -d \\" -f 2 -- tail -f /var/log/httpd/access.log | pipestat jpe?g png gif -- tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif -- tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif -- tail -f /var/log/httpd/access.log | pipestat 'artid=(\\d+)' --maxtime=30 --limit 20 + tail -f /var/log/httpd/access.log | pipestat jpe?g png gif + + tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif + + tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif + + tail -f /var/log/httpd/access.log | pipestat 'artid=(\\d+)' --maxtime=30 --limit 20
auduny/statpipe
412a527705cd7683920beeeb878a55047da11263
CleanuCleanupp
diff --git a/pipestat b/pipestat index 311d66b..b101fc6 100755 --- a/pipestat +++ b/pipestat @@ -1,313 +1,311 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. # TODO: Merge ($1) ($2) etc. # TODO: Switch to caculate percentage of hits instead of total =head1 NAME Pipestat - swiss knife statistics =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_help = 0; my $opt_version = 0; my $opt_clear=0; #Don't clean screen my $opt_hits=1; # show hits per second my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "m|maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines "l|limit=i" => \$opt_limit, # how many do we print "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "n|not=s" => \$opt_not, # Not these "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "h|hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | pipestat [options] [regex] ... [regex] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --hits Show hits per second (yes) --help Show help --version Show version =head1 DESCRIPTION Pipestat is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk =cut if ($opt_help) { pod2usage("Pipestat $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $now = time(); while (<STDIN>) { $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines >= $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines if ($opt_not) { if ($line =~ m/$opt_not/) { next; } } for my $reg (@ARGV) { if ($opt_case) { if ( $line =~ m/$reg/ ) { if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } if ( !@ARGV ) { # we didn't send regexp, count every line if ($opt_field) { # which field to use my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } chop($object); $objects->{$object}++; } else { $objects->{$line}++; } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $hitsum = 0; my $limit = 0; my $hitlimit; my $limitedhits = 0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { $hitsum += $objects->{$reg}; if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-25s : (%.1f%%) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits, $hitlimit, $lines ); } } my $rest = $lines - $hitsum; if ($rest) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest / $diff, $rest, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest, $lines ); } } if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<total>", 100, $hitsum / $diff, $hitsum, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } print "\n"; } sub end_pipe { print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES =over 4 -=item tail -f /var/log/httpd/access.log | pipestat -f 7 +tail -f /var/log/httpd/access.log | pipestat -f 7 -I love norwegian country +tail -f /var/log/httpd/access.log | pipestat -d \" -f 2 -=item tail -f /var/log/httpd/access.log | pipestat -d \" -f 2 +tail -f /var/log/httpd/access.log | pipestat jpe?g png gif -=item tail -f /var/log/httpd/access.log | pipestat jpe?g png gif +tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif -=item tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif +tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif -=item tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif - -=item tail -f /var/log/httpd/access.log | pipestat 'artid=(\d+)' --maxtime=30 --limit 20 +tail -f /var/log/httpd/access.log | pipestat 'artid=(\d+)' --maxtime=30 --limit 20 =back =cut
auduny/statpipe
eac05d54a80f7dc08b7806aac9da2a2985a92f62
More markdown
diff --git a/pipestat b/pipestat index 99c1d1b..311d66b 100755 --- a/pipestat +++ b/pipestat @@ -1,313 +1,313 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. # TODO: Merge ($1) ($2) etc. # TODO: Switch to caculate percentage of hits instead of total =head1 NAME Pipestat - swiss knife statistics =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_help = 0; my $opt_version = 0; my $opt_clear=0; #Don't clean screen my $opt_hits=1; # show hits per second my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "m|maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines "l|limit=i" => \$opt_limit, # how many do we print "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "n|not=s" => \$opt_not, # Not these "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "h|hits!" => \$opt_hits, # show hits/s "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); =head1 SYNOPSIS tail -f some.log | pipestat [options] [regex] ... [regex] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --hits Show hits per second (yes) --help Show help --version Show version =head1 DESCRIPTION Pipestat is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk =cut if ($opt_help) { pod2usage("Pipestat $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $now = time(); while (<STDIN>) { $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines >= $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines if ($opt_not) { if ($line =~ m/$opt_not/) { next; } } for my $reg (@ARGV) { if ($opt_case) { if ( $line =~ m/$reg/ ) { if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } if ( !@ARGV ) { # we didn't send regexp, count every line if ($opt_field) { # which field to use my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } chop($object); $objects->{$object}++; } else { $objects->{$line}++; } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $hitsum = 0; my $limit = 0; my $hitlimit; my $limitedhits = 0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { $hitsum += $objects->{$reg}; if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-25s : (%.1f%%) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits, $hitlimit, $lines ); } } my $rest = $lines - $hitsum; if ($rest) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest / $diff, $rest, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest, $lines ); } } if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<total>", 100, $hitsum / $diff, $hitsum, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } print "\n"; } sub end_pipe { print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } =head1 EXAMPLES -=over 8 +=over 4 =item tail -f /var/log/httpd/access.log | pipestat -f 7 I love norwegian country =item tail -f /var/log/httpd/access.log | pipestat -d \" -f 2 =item tail -f /var/log/httpd/access.log | pipestat jpe?g png gif =item tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif =item tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif =item tail -f /var/log/httpd/access.log | pipestat 'artid=(\d+)' --maxtime=30 --limit 20 =back =cut
auduny/statpipe
dd66c0a264b0e64a0c27310566f846262f8cae0e
more markdown
diff --git a/README.md b/README.md index c2f9e47..846c763 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,39 @@ # NAME -Pipestat - swiss knife statistics, command line splunk alternative +Pipestat - swiss knife statistics # SYNOPSIS -<datastream> | pipestat \[options\] \[regex\] ... \[regex\] +tail -f some.log | pipestat \[options\] \[regex\] ... \[regex\] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) + --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --hits Show hits per second (yes) - --limit Limit output of keys (30) --help Show help --version Show version # DESCRIPTION Pipestat is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk -# Examples +# EXAMPLES + +- tail -f /var/log/httpd/access.log | pipestat -f 7 + + I love norwegian country -tail -f /var/log/httpd/access.log | pipestat -f +- tail -f /var/log/httpd/access.log | pipestat -d \\" -f 2 +- tail -f /var/log/httpd/access.log | pipestat jpe?g png gif +- tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif +- tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif +- tail -f /var/log/httpd/access.log | pipestat 'artid=(\\d+)' --maxtime=30 --limit 20 diff --git a/pipestat b/pipestat index 5711383..99c1d1b 100755 --- a/pipestat +++ b/pipestat @@ -1,295 +1,313 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. # TODO: Merge ($1) ($2) etc. # TODO: Switch to caculate percentage of hits instead of total =head1 NAME -Pipestat - swiss knife statistics, command line splunk alternative +Pipestat - swiss knife statistics =cut my $version="1.0"; use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); use Pod::Usage; # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=0; # Stop at five million lines my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_help = 0; my $opt_version = 0; my $opt_clear=0; #Don't clean screen my $opt_hits=1; # show hits per second my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "m|maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines +"l|limit=i" => \$opt_limit, # how many do we print "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "n|not=s" => \$opt_not, # Not these "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "h|hits!" => \$opt_hits, # show hits/s -"l|limit=i" => \$opt_limit, # how many do we print "h|help" => \$opt_help, # Print help "v|version" => \$opt_version # Print version ); + =head1 SYNOPSIS -<datastream> | pipestat [options] [regex] ... [regex] +tail -f some.log | pipestat [options] [regex] ... [regex] Options: --timefreq|-t Frequency of output in seconds (5) --linefreq Frequency of output in lines (none) --maxtime|-m Time before closing the pipe in seconds (60) --maxlines Maximum numbers of lines to parse (unlimited) --field|f What field top use as key --delimiter|d What delimiter to use for fields (spaces) + --limit Limit output of keys (30) --maxkeys Max number of unique keys (50000) --not|n Exclude lines with regex --case|s Be casesensetive --hits Show hits per second (yes) - --limit Limit output of keys (30) --help Show help --version Show version =head1 DESCRIPTION Pipestat is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk -=head1 Examples - -tail -f /var/log/httpd/access.log | pipestat -f - =cut if ($opt_help) { pod2usage("Pipestat $version by Audun Ytterdal <audun\@ytterdal.net>\n"); exit(0); } if ($opt_version) { print "$version\n"; exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $now = time(); while (<STDIN>) { $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines >= $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines if ($opt_not) { if ($line =~ m/$opt_not/) { next; } } for my $reg (@ARGV) { if ($opt_case) { if ( $line =~ m/$reg/ ) { if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } if ( !@ARGV ) { # we didn't send regexp, count every line if ($opt_field) { # which field to use my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } chop($object); $objects->{$object}++; } else { $objects->{$line}++; } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $hitsum = 0; my $limit = 0; my $hitlimit; my $limitedhits = 0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { $hitsum += $objects->{$reg}; if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-25s : (%.1f%%) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits, $hitlimit, $lines ); } } my $rest = $lines - $hitsum; if ($rest) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest / $diff, $rest, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest, $lines ); } } if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<total>", 100, $hitsum / $diff, $hitsum, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } print "\n"; } sub end_pipe { print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } +=head1 EXAMPLES + +=over 8 + +=item tail -f /var/log/httpd/access.log | pipestat -f 7 + +I love norwegian country + +=item tail -f /var/log/httpd/access.log | pipestat -d \" -f 2 + +=item tail -f /var/log/httpd/access.log | pipestat jpe?g png gif + +=item tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif + +=item tail -f /var/log/httpd/access.log | pipestat (jpe?g) png gif + +=item tail -f /var/log/httpd/access.log | pipestat 'artid=(\d+)' --maxtime=30 --limit 20 + +=back + +=cut
auduny/statpipe
13251170545715b5bc0978c397fc0983a514e769
Cleanup and add markdown
diff --git a/README b/README deleted file mode 100644 index 531a3e2..0000000 --- a/README +++ /dev/null @@ -1 +0,0 @@ -Tool to be do statistics on pipes from tails of logs and stuff diff --git a/README.md b/README.md new file mode 100644 index 0000000..c2f9e47 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# NAME + +Pipestat - swiss knife statistics, command line splunk alternative + +# SYNOPSIS + +<datastream> | pipestat \[options\] \[regex\] ... \[regex\] + + Options: + --timefreq|-t Frequency of output in seconds (5) + --linefreq Frequency of output in lines (none) + --maxtime|-m Time before closing the pipe in seconds (60) + --maxlines Maximum numbers of lines to parse (unlimited) + --field|f What field top use as key + --delimiter|d What delimiter to use for fields (spaces) + --maxkeys Max number of unique keys (50000) + --not|n Exclude lines with regex + --case|s Be casesensetive + --hits Show hits per second (yes) + --limit Limit output of keys (30) + --help Show help + --version Show version + +# DESCRIPTION + +Pipestat is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. +It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk + +# Examples + +tail -f /var/log/httpd/access.log | pipestat -f diff --git a/pipestat b/pipestat index 5b501ea..5711383 100755 --- a/pipestat +++ b/pipestat @@ -1,285 +1,295 @@ #!/usr/bin/perl # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. # TODO: Merge ($1) ($2) etc. # TODO: Switch to caculate percentage of hits instead of total =head1 NAME Pipestat - swiss knife statistics, command line splunk alternative -=head1 SYNOPSIS - -tail -f /var/log/httpd/access.log | pipestat '(jpe?g)' 'gif' 'png' -tail -f /var/log/httpd/access.log | pipestat -f 7 --maxtime=10 - -=head1 DESCRIPTION - =cut +my $version="1.0"; + use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); - +use Pod::Usage; # Unbuffered output $| = 1; - # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds -my $opt_maxlines=5000000; # Stop at five million lines -my $opt_maxkeys=500000; +my $opt_maxlines=0; # Stop at five million lines +my $opt_maxkeys=50000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_help = 0; +my $opt_version = 0; my $opt_clear=0; #Don't clean screen my $opt_hits=1; # show hits per second my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "m|maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "n|not=s" => \$opt_not, # Not these "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use -"h|hits" => \$opt_hits, # show hits/s +"h|hits!" => \$opt_hits, # show hits/s "l|limit=i" => \$opt_limit, # how many do we print -"h|help" => \$opt_help # Print help +"h|help" => \$opt_help, # Print help +"v|version" => \$opt_version # Print version ); +=head1 SYNOPSIS + +<datastream> | pipestat [options] [regex] ... [regex] + + Options: + --timefreq|-t Frequency of output in seconds (5) + --linefreq Frequency of output in lines (none) + --maxtime|-m Time before closing the pipe in seconds (60) + --maxlines Maximum numbers of lines to parse (unlimited) + --field|f What field top use as key + --delimiter|d What delimiter to use for fields (spaces) + --maxkeys Max number of unique keys (50000) + --not|n Exclude lines with regex + --case|s Be casesensetive + --hits Show hits per second (yes) + --limit Limit output of keys (30) + --help Show help + --version Show version + +=head1 DESCRIPTION + +Pipestat is a excellent little tool to analyse logfiles, or any file for that matter, and produce percentage of hits, hits per second and other cool stuff. +It's supposed to be a better way of doin tail -f | awk | cut| unique |sort |uniqeue | whaterver. Or as a poor mans splunk + +=head1 Examples + +tail -f /var/log/httpd/access.log | pipestat -f + +=cut + + if ($opt_help) { - &help; + pod2usage("Pipestat $version by Audun Ytterdal <audun\@ytterdal.net>\n"); + exit(0); +} + +if ($opt_version) { + print "$version\n"; + exit(0); } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $now = time(); + while (<STDIN>) { $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines >= $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines if ($opt_not) { if ($line =~ m/$opt_not/) { next; } } for my $reg (@ARGV) { if ($opt_case) { if ( $line =~ m/$reg/ ) { if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } if ( !@ARGV ) { # we didn't send regexp, count every line if ($opt_field) { # which field to use my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } chop($object); $objects->{$object}++; } else { $objects->{$line}++; } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $hitsum = 0; my $limit = 0; my $hitlimit; my $limitedhits = 0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { $hitsum += $objects->{$reg}; if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-25s : (%.1f%%) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits, $hitlimit, $lines ); } } my $rest = $lines - $hitsum; if ($rest) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest / $diff, $rest, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest, $lines ); } } if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<total>", 100, $hitsum / $diff, $hitsum, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } print "\n"; } sub end_pipe { print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } -sub help { - print "pipestat usage\n"; - print "someprogram | pipestat [options] [regexps]\n"; - print "options:\n"; - print " -t|--timefreq # How often do we update in time (default: 5 seconds)\n"; - print " -m|--maxtime # Stop after this number of seconds (default: 60 seconds)\n"; - print " --linefreq # How often do we update in lines (default: never\n"; - print " --maxlines # Max number of lines do we read (default 5 million)\n"; - print " -s|--case # Be case sensetive (default: caseinsensetive)\n"; - print " -c|--clear # Clear screen between updates (default: no)\n"; - print " -f|--field # what field to use?\n"; - print " -d|--delimiter # What regex delimiter to use (default: space)\n"; - print " -h|--hits # Show hits/s (default: on\n"; - print " -l|--limit # Limit how many to print (default: 30)\n"; - print " -n|--not # Exclude lines with this regexp\n"; - print " -h|--help # Show this help\n"; - print "\n"; - print "Examples\n"; - print "tail -f /var/log/httpd/access.log | pipestat 'gif' 'jpe?g'"; - print "tail -f /var/log/httpd/access.log | pipestat 'gif' '(jpe?g)'"; - print "tail -f /var/log/httpd/access.log | pipestat --field 6"; - print "tail -f /var/log/httpd/access.log | pipestat --field 1 --not '127\.0\.0\.1"; - exit; -}
auduny/statpipe
9de3a546f58cf7f1b02366aff0aea5c99ee0caac
POD Documentation
diff --git a/pipestat b/pipestat index 7fea39d..5b501ea 100755 --- a/pipestat +++ b/pipestat @@ -1,276 +1,285 @@ #!/usr/bin/perl -# Pipestat, A nice tool to get statistics from any text in a pipe # Copyright Audun Ytterdal <audun@ytterdal.net> # Licenced under GPL Version 2. - -# TODO: field 4-5 4,6 etc # TODO: Merge ($1) ($2) etc. -# TODO: Remove hits/s when cat'ing files -# TODO: Removing stuff like where field='S' etc +# TODO: Switch to caculate percentage of hits instead of total + +=head1 NAME + +Pipestat - swiss knife statistics, command line splunk alternative + +=head1 SYNOPSIS + +tail -f /var/log/httpd/access.log | pipestat '(jpe?g)' 'gif' 'png' +tail -f /var/log/httpd/access.log | pipestat -f 7 --maxtime=10 + +=head1 DESCRIPTION + +=cut use Getopt::Long; #use Data::Dumper; use Time::HiRes qw( time ); # Unbuffered output $| = 1; # Catch Ctrl-C and friends $SIG{INT} = \&end_pipe; my $opt_linefreq; # Default none my $opt_timefreq=5; # Default every 5 second my $opt_maxtime=60; # Default 60 seconds my $opt_maxlines=5000000; # Stop at five million lines my $opt_maxkeys=500000; my $opt_regex = 0; my $opt_case = 0; my $opt_limit = 30; my $opt_field; my $opt_delimiter = '\s+'; #Default delimiter is one or more spaces my $opt_help = 0; my $opt_clear=0; #Don't clean screen my $opt_hits=1; # show hits per second my $result = GetOptions( "t|timefreq=i" => \$opt_timefreq, # how often do we update in time "m|maxtime=i" => \$opt_maxtime, # when to stop "maxlines=i" => \$opt_maxlines, # when to stop "linefreq=i" => \$opt_linefreq, # how often do we update in lines "maxkeys=i" => \$opt_maxkeys, # maxkeys (default 5000) "n|not=s" => \$opt_not, # Not these "s|case" => \$opt_case, # key sensetive? "c|clear" => \$opt_clear, # clear and updatescreen? "f|field=s" => \$opt_field, # what field to use? "d|delimiter=s" => \$opt_delimiter, # What delimiter to use "h|hits" => \$opt_hits, # show hits/s "l|limit=i" => \$opt_limit, # how many do we print "h|help" => \$opt_help # Print help ); if ($opt_help) { &help; } # The hash where we store objects my $objects; # counters my $freqcount = 0; my $starttime = time(); my $freqtime = $starttime; my $lines = 0; my $keys = 0; my $now = time(); while (<STDIN>) { $now = time(); $lines++; if ($opt_maxkeys) { $keys = keys %$objects; if ($keys > $opt_maxkeys) { print "Maxkeys ($opt_maxkeys) reached\n"; &end_pipe; } } if ($opt_maxtime) { if ($now - $starttime >= $opt_maxtime) { print "Maxtime of $opt_maxtime seconds reached.\n"; &end_pipe; } } if ($opt_maxlines) { if ($lines >= $opt_maxlines) { print "Maxlines of $opt_maxlines reached.\n\n"; &end_pipe; } } my $line = $_; chomp $line; # remove trailing newlines if ($opt_not) { if ($line =~ m/$opt_not/) { next; } } for my $reg (@ARGV) { if ($opt_case) { if ( $line =~ m/$reg/ ) { if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regex as key } } } else { if ( $line =~ m/$reg/i ) { # caseinsensetive is default if ($1) { $objects->{$1}++; # add match as key } else { $objects->{$reg}++; # add regexp as key } } } } if ( !@ARGV ) { # we didn't send regexp, count every line if ($opt_field) { # which field to use my @fields = split(",",$opt_field); my @fieldlist = split(/$opt_delimiter/,$line); my $object; for my $field (@fields) { $object .= "$fieldlist[($field-1)] "; } chop($object); $objects->{$object}++; } else { $objects->{$line}++; } } $freqcount++; if ($opt_linefreq) { # print out every <n> lines printout( $objects, $lines, $starttime ) if ( $freqcount >= $opt_linefreq ); $freqcount = 0; } if ($opt_timefreq) { # print out every <n> seconds if ( time() - $freqtime >= $opt_timefreq ) { printout( $objects, $lines, $starttime ); $freqtime = time(); } } } &end_pipe; # we only get here if the pipe is closed. sub printout { my ( $objects, $lines, $starttime ) = @_; my $diff = time() - $starttime; my $hitsum = 0; my $limit = 0; my $hitlimit; my $limitedhits = 0; if ($opt_clear) { # if set, clear screen between prints my $clear = `tput clear`; print $clear; } # sort the hash values and print descending for my $reg ( sort { $objects->{$b} <=> $objects->{$a} } keys %$objects ) { $hitsum += $objects->{$reg}; if ( !$hitlimit ) { # only print untill we hit the limit if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg} / $diff, $objects->{$reg}, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } } else { $limitedhits += $objects->{$reg}; } $limit++; if ( $opt_limit && $limit >= $opt_limit ) { $hitlimit++; } } if ($hitlimit) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits / $diff, $limitedhits, $hitlimit, $lines ); } else { printf( "%-25s : (%.1f%%) (%d(%d) hits(uniq) / %d)\n", "<limited>", ( $limitedhits / $lines ) * 100, $limitedhits, $hitlimit, $lines ); } } my $rest = $lines - $hitsum; if ($rest) { if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest / $diff, $rest, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", "<rest>", ( $rest / $lines ) * 100, $rest, $lines ); } } if ($opt_hits) { printf( "%-25s : (%.1f%%) (%.1f hits/s) (%d hits / %d)\n", "<total>", 100, $hitsum / $diff, $hitsum, $lines ); } else { printf( "%-25s : (%.1f%%) (%d hits / %d)\n", $reg, ( $objects->{$reg} / $lines ) * 100, $objects->{$reg}, $lines ); } print "\n"; } sub end_pipe { print "\n"; printout( $objects, $lines, $starttime ); my $diff = time() - $starttime; printf( "Parsed %d lines in %.2f secs (%.1f lines/s)\n", $lines, $diff, $lines / $diff ); exit; } sub help { print "pipestat usage\n"; print "someprogram | pipestat [options] [regexps]\n"; print "options:\n"; print " -t|--timefreq # How often do we update in time (default: 5 seconds)\n"; print " -m|--maxtime # Stop after this number of seconds (default: 60 seconds)\n"; print " --linefreq # How often do we update in lines (default: never\n"; print " --maxlines # Max number of lines do we read (default 5 million)\n"; print " -s|--case # Be case sensetive (default: caseinsensetive)\n"; print " -c|--clear # Clear screen between updates (default: no)\n"; print " -f|--field # what field to use?\n"; print " -d|--delimiter # What regex delimiter to use (default: space)\n"; print " -h|--hits # Show hits/s (default: on\n"; print " -l|--limit # Limit how many to print (default: 30)\n"; print " -n|--not # Exclude lines with this regexp\n"; print " -h|--help # Show this help\n"; print "\n"; print "Examples\n"; print "tail -f /var/log/httpd/access.log | pipestat 'gif' 'jpe?g'"; print "tail -f /var/log/httpd/access.log | pipestat 'gif' '(jpe?g)'"; print "tail -f /var/log/httpd/access.log | pipestat --field 6"; print "tail -f /var/log/httpd/access.log | pipestat --field 1 --not '127\.0\.0\.1"; exit; }