all_seeing_eye 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'redis'
4
+ gem 'chronic'
5
+ gem 'active_support'
6
+ gem 'rbtree'
7
+ gem 'i18n'
8
+
9
+ group :development do
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "rcov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ active_support (3.0.0)
5
+ activesupport (= 3.0.0)
6
+ activesupport (3.0.0)
7
+ chronic (0.6.2)
8
+ git (1.2.5)
9
+ i18n (0.5.0)
10
+ jeweler (1.6.4)
11
+ bundler (~> 1.0)
12
+ git (>= 1.2.5)
13
+ rake
14
+ rake (0.9.2)
15
+ rbtree (0.3.0)
16
+ rcov (0.9.10)
17
+ redis (2.2.2)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ active_support
24
+ bundler (~> 1.0.0)
25
+ chronic
26
+ i18n
27
+ jeweler (~> 1.6.4)
28
+ rbtree
29
+ rcov
30
+ redis
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Josh Symonds
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = all_seeing_eye
2
+
3
+ A highly configurable Gem that lets you view requests as they occur, backed by Redis.
4
+
5
+ == Contributing to all_seeing_eye
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Josh Symonds. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ gem.name = "all_seeing_eye"
17
+ gem.homepage = "http://github.com/Veraticus/all_seeing_eye"
18
+ gem.license = "MIT"
19
+ gem.summary = 'Log requests to Redis, then view them with pretty graphs'
20
+ gem.description = %Q{AllSeeingEye observes all requests, with parameters that you specify, to Redis. Then it composes them into graphs for you to see.}
21
+ gem.email = "veraticus@gmail.com"
22
+ gem.authors = ["Josh Symonds"]
23
+ end
24
+ Jeweler::RubygemsDotOrgTasks.new
25
+
26
+ require 'rake/testtask'
27
+ Rake::TestTask.new(:test) do |test|
28
+ test.libs << 'lib' << 'test'
29
+ test.pattern = 'test/**/*_test.rb'
30
+ test.verbose = true
31
+ end
32
+
33
+ require 'rcov/rcovtask'
34
+ Rcov::RcovTask.new do |test|
35
+ test.libs << 'test'
36
+ test.pattern = 'test/**/test_*.rb'
37
+ test.verbose = true
38
+ test.rcov_opts << '--exclude "gems/*"'
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "all_seeing_eye #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,93 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{all_seeing_eye}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Josh Symonds"]
12
+ s.date = %q{2011-08-10}
13
+ s.default_executable = %q{all-seeing-eye}
14
+ s.description = %q{AllSeeingEye observes all requests, with parameters that you specify, to Redis. Then it composes them into graphs for you to see.}
15
+ s.email = %q{veraticus@gmail.com}
16
+ s.executables = ["all-seeing-eye"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "all_seeing_eye.gemspec",
29
+ "bin/all-seeing-eye",
30
+ "init.rb",
31
+ "lib/all_seeing_eye.rb",
32
+ "lib/all_seeing_eye/integrations/rails2.rb",
33
+ "lib/all_seeing_eye/model.rb",
34
+ "lib/all_seeing_eye/models/request.rb",
35
+ "lib/all_seeing_eye/server.rb",
36
+ "lib/all_seeing_eye/server/public/application.js",
37
+ "lib/all_seeing_eye/server/public/eye.png",
38
+ "lib/all_seeing_eye/server/public/jquery-1.6.2.min.js",
39
+ "lib/all_seeing_eye/server/public/jquery.equal_heights.js",
40
+ "lib/all_seeing_eye/server/public/jquery.flot.js",
41
+ "lib/all_seeing_eye/server/public/reset.css",
42
+ "lib/all_seeing_eye/server/public/style.css",
43
+ "lib/all_seeing_eye/server/views/field.erb",
44
+ "lib/all_seeing_eye/server/views/layout.erb",
45
+ "lib/all_seeing_eye/server/views/left.erb",
46
+ "lib/all_seeing_eye/server/views/total.erb",
47
+ "lib/all_seeing_eye/server/views/view.erb",
48
+ "test/base_test.rb",
49
+ "test/fixtures/all_seeing_eye.yml",
50
+ "test/fixtures/redis-test.conf",
51
+ "test/model_test.rb",
52
+ "test/test_helper.rb"
53
+ ]
54
+ s.homepage = %q{http://github.com/Veraticus/all_seeing_eye}
55
+ s.licenses = ["MIT"]
56
+ s.require_paths = ["lib"]
57
+ s.rubygems_version = %q{1.6.2}
58
+ s.summary = %q{Log requests to Redis, then view them with pretty graphs}
59
+
60
+ if s.respond_to? :specification_version then
61
+ s.specification_version = 3
62
+
63
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
64
+ s.add_runtime_dependency(%q<redis>, [">= 0"])
65
+ s.add_runtime_dependency(%q<chronic>, [">= 0"])
66
+ s.add_runtime_dependency(%q<active_support>, [">= 0"])
67
+ s.add_runtime_dependency(%q<rbtree>, [">= 0"])
68
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
69
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
70
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
71
+ s.add_development_dependency(%q<rcov>, [">= 0"])
72
+ else
73
+ s.add_dependency(%q<redis>, [">= 0"])
74
+ s.add_dependency(%q<chronic>, [">= 0"])
75
+ s.add_dependency(%q<active_support>, [">= 0"])
76
+ s.add_dependency(%q<rbtree>, [">= 0"])
77
+ s.add_dependency(%q<i18n>, [">= 0"])
78
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
79
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
80
+ s.add_dependency(%q<rcov>, [">= 0"])
81
+ end
82
+ else
83
+ s.add_dependency(%q<redis>, [">= 0"])
84
+ s.add_dependency(%q<chronic>, [">= 0"])
85
+ s.add_dependency(%q<active_support>, [">= 0"])
86
+ s.add_dependency(%q<rbtree>, [">= 0"])
87
+ s.add_dependency(%q<i18n>, [">= 0"])
88
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
89
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
90
+ s.add_dependency(%q<rcov>, [">= 0"])
91
+ end
92
+ end
93
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ begin
5
+ require 'vegas'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'vegas'
9
+ end
10
+ require 'all_seeing_eye'
11
+ require 'all_seeing_eye/server'
12
+
13
+
14
+ Vegas::Runner.new(AllSeeingEye::Server, 'all-seeing-eye')
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'all_seeing_eye'
@@ -0,0 +1,30 @@
1
+ class AllSeeingEye
2
+ module Integrations
3
+ module Rails2
4
+ def log_request
5
+ _start_time = DateTime.now
6
+ yield
7
+ _end_time = DateTime.now
8
+ hash = {}
9
+ begin
10
+ Timeout::timeout(AllSeeingEye.configuration['timeout']) {
11
+ AllSeeingEye::Request.fields.each do |field, options|
12
+ object = options['object'] == 'controller' ? 'self' : options['object']
13
+ val = eval("#{object}#{options['method']}")
14
+ hash[field] = val
15
+ end
16
+ hash['created_at'] = _end_time
17
+ hash['time_spent'] = (_end_time - _start_time).to_f * 1000
18
+ AllSeeingEye::Request.create(hash)
19
+ Rails.logger.info('+++ Request watched by AllSeeingEye')
20
+ }
21
+ rescue Timeout::Error
22
+ Rails.logger.info('+++ Request not watched by AllSeeingEye; it took too long to complete')
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ ActionController::Base.send(:include, AllSeeingEye::Integrations::Rails2)
30
+ ActionController::Base.send(:around_filter, :log_request)
@@ -0,0 +1,163 @@
1
+ class AllSeeingEye::Model
2
+ attr_accessor :id, :score
3
+
4
+ def self.model_name
5
+ self.to_s.split('::').last.downcase
6
+ end
7
+
8
+ def self.next_id
9
+ AllSeeingEye.redis.incr("allseeingeye:#{self.model_name}:id")
10
+ end
11
+
12
+ def self.fields
13
+ AllSeeingEye.configuration[self.model_name]
14
+ end
15
+
16
+ def self.field_keys
17
+ self.fields.keys + ['time_spent']
18
+ end
19
+
20
+ def self.field_names
21
+ (self.field_keys + ['created_at', 'time_spent']).flatten
22
+ end
23
+
24
+ def self.new(fields = {})
25
+ object = super()
26
+ fields.each {|key, value| object.send("#{key}=".to_sym, value)}
27
+ object
28
+ end
29
+
30
+ def self.create(fields)
31
+ self.new(fields).save
32
+ end
33
+
34
+ def self.load(object)
35
+ object = Marshal.load(object)
36
+ object.send(:initialize)
37
+ end
38
+
39
+ def self.find(id)
40
+ self.load(AllSeeingEye.redis["allseeingeye:#{self.model_name}:#{id}"])
41
+ end
42
+
43
+ def self.all(options = {})
44
+ all = AllSeeingEye.redis.sort("allseeingeye:#{self.model_name}:all", :by => 'nosort', :get => "allseeingeye:#{self.model_name}:*").collect{|o| self.load(o)}
45
+ all = all.find_all{|o| o.created_at > options[:start]} if options[:start]
46
+ all = all.find_all{|o| o.created_at < options[:stop]} if options[:stop]
47
+ all
48
+ end
49
+
50
+ def self.count(options = {})
51
+ options[:start] = options[:start].to_i if options[:start] && (options[:start].is_a?(Time) || options[:start].is_a?(DateTime) || options[:start].is_a?(Date))
52
+ options[:stop] = options[:stop].to_i if options[:stop] && (options[:stop].is_a?(Time) || options[:stop].is_a?(DateTime) || options[:stop].is_a?(Date))
53
+ options = {:start => '-inf', :stop => '+inf'}.merge(options)
54
+
55
+ AllSeeingEye.redis.zrangebyscore("allseeingeye:#{self.model_name}:fields:created_at", options[:start], options[:stop], :with_scores => false).collect{|id| self.find(id)}.size
56
+ end
57
+
58
+ def self.find_by_field(field, options = {})
59
+ if options[:value]
60
+ all = AllSeeingEye.redis.sort("allseeingeye:#{self.model_name}:fields:#{field}:#{options[:value]}", :by => 'nosort', :get => "allseeingeye:#{self.model_name}:*").collect{|o| self.load(o)}
61
+ all = all.find_all{|o| o.created_at > options[:start]} if options[:start]
62
+ all = all.find_all{|o| o.created_at < options[:stop]} if options[:stop]
63
+ all
64
+ else
65
+ options[:start] = options[:start].to_i
66
+ options[:stop] = options[:stop].to_i
67
+ options = {:start => '-inf', :stop => '+inf'}.merge(options)
68
+
69
+ AllSeeingEye.redis.zrangebyscore("allseeingeye:#{self.model_name}:fields:#{field}", options[:start], options[:stop], :with_scores => false).collect{|id| self.find(id)}
70
+ end
71
+ end
72
+
73
+ def self.count_by_field(field, options = {})
74
+ options = {:start => '-inf', :stop => '+inf'}.merge(options)
75
+
76
+ raw_list = AllSeeingEye.redis.zrangebyscore("allseeingeye:#{self.model_name}:fields:#{field}", options[:start], options[:stop], :with_scores => true)
77
+ list = []
78
+ raw_list.each_with_index do |value, index|
79
+ if index % 2 == 0
80
+ list << [value]
81
+ else
82
+ list.last[1] = value.to_i
83
+ end
84
+ end
85
+ list.reverse
86
+ end
87
+
88
+ def self.first
89
+ self.find(AllSeeingEye.redis.zrange("allseeingeye:#{self.model_name}:fields:created_at", 0, 0))
90
+ end
91
+
92
+ def self.last
93
+ self.find(AllSeeingEye.redis.zrange("allseeingeye:#{self.model_name}:fields:created_at", -1, -1))
94
+ end
95
+
96
+ def self.search(query)
97
+ if query =~ /^[\sa-zA-Z0-9,-]*? to [\sa-zA-Z0-9,-]*?$/
98
+ start = Chronic.parse(query.split(' to ').first, :context => :past)
99
+ stop = Chronic.parse(query.split(' to ').last, :context => :past)
100
+ AllSeeingEye.redis.zrangebyscore("allseeingeye:#{self.model_name}:fields:created_at", start.to_i, stop.to_i, :with_scores => false).collect{|id| self.find(id)}
101
+ elsif query =~ /^(#{self.field_names.join('|')}):(.*)$/
102
+ self.find_by_field($1, :value => $2)
103
+ else
104
+ results = []
105
+ self.field_names.each {|f| results << self.find_by_field(f, :value => query)}
106
+ results.flatten.uniq
107
+ end
108
+ end
109
+
110
+ def self.conglomerate(array, options = {})
111
+ return [] if array.empty?
112
+
113
+ options = {:granularity => 500}.merge(options)
114
+ if !array.first.score.nil?
115
+ array = array.sort{|a, b| a.score <=> b.score}
116
+ else
117
+ array = array.sort{|a, b| a.created_at <=> b.created_at}
118
+ end
119
+ start = array.first.created_at.utc.to_i
120
+ stop = array.last.created_at.utc.to_i
121
+ interval = (stop - start) / options[:granularity]
122
+ interval = 1 if interval == 0
123
+
124
+ tree = RBTree.new
125
+ options[:granularity].times {|n| tree[start + (interval * n)] = 0}
126
+
127
+ array.each do |o|
128
+ val = o.created_at.utc.to_i
129
+ bound = tree.lower_bound(val)
130
+ bound = tree.upper_bound(val) if bound.nil?
131
+ tree[bound.first] += 1
132
+ end
133
+ tree.to_a
134
+ end
135
+
136
+ def initialize
137
+ self.class.field_names.each do |key|
138
+ self.class.send(:attr_accessor, key.to_sym)
139
+ end
140
+ self
141
+ end
142
+
143
+ def id
144
+ @id ||= self.class.next_id
145
+ end
146
+
147
+ def save
148
+ AllSeeingEye.redis["allseeingeye:#{self.class.model_name}:#{id}"] = Marshal.dump(self)
149
+ AllSeeingEye.redis.sadd("allseeingeye:#{self.class.model_name}:all", id)
150
+ self.class.field_names.each do |field|
151
+ value = self.send(field.to_sym)
152
+ next if value.nil? || (value.respond_to?(:empty?) && value.empty?)
153
+ if value.is_a?(Time) || value.is_a?(DateTime) || value.is_a?(Date)
154
+ AllSeeingEye.redis.zadd("allseeingeye:#{self.class.model_name}:fields:#{field}", value.to_i, id)
155
+ else
156
+ AllSeeingEye.redis.lpush("allseeingeye:#{self.class.model_name}:fields:#{field}:#{value}", id)
157
+ AllSeeingEye.redis.zincrby("allseeingeye:#{self.class.model_name}:fields:#{field}", 1, value)
158
+ end
159
+ end
160
+ self
161
+ end
162
+
163
+ end
@@ -0,0 +1,3 @@
1
+ class AllSeeingEye::Request < AllSeeingEye::Model
2
+
3
+ end
@@ -0,0 +1,16 @@
1
+ function showTooltip(x, y, contents) {
2
+ $('<div id="tooltip">' + contents + '</div>').css( {
3
+ position: 'absolute',
4
+ display: 'none',
5
+ top: y + 5,
6
+ left: x + 5,
7
+ border: '1px solid #5395bc',
8
+ padding: '5px',
9
+ 'background-color': '#eaf0f3',
10
+ opacity: 0.80
11
+ }).appendTo("body").fadeIn(200);
12
+ }
13
+
14
+ $(document).ready($(function() {
15
+ $('#page').equalHeights();
16
+ }));