Permalink
Browse files

More style changes. jQuery niceness. Support for creating/cleaning logs.

  • Loading branch information...
1 parent 6fe57bc commit 5efe7563b94e1ffe7f57d1a8a87bce71fbcc2bbe @watsonian committed Feb 9, 2010
Showing with 407 additions and 6,155 deletions.
  1. +104 −28 memwatcher.rb
  2. +70 −9 public/css/main.css
  3. +0 −6,078 public/js/jquery-1.4.1.js
  4. +152 −0 public/js/jquery-1.4.1.min.js
  5. +33 −2 public/js/main.js
  6. +30 −7 views/index.erb
  7. +18 −0 views/memcheck.erb
  8. +0 −31 views/processes.erb
View
@@ -1,48 +1,124 @@
require 'rubygems'
+require 'yaml'
require 'vendor/sinatra/lib/sinatra'
require 'vendor/mem_info/lib/mem_info'
require 'erb'
-get '/hi' do
- @mem_used = MemInfo.new.memused
- erb :index
-end
+@@memory_threshold = 50000
+@@max_memused = @@memory_threshold
+@@num_checks = 0
+@@max_checks = 6
+@@logs_to_keep = 25
+
+
+#####
+# Actions
-get '/processes' do
- @file_list = Dir.glob("log/procs/*.snapshot.out").sort.reverse
+get '/' do
+ @memory_threshold = @@memory_threshold
+ @file_list = get_log_list
@files = []
@file_list.each do |file|
@files << hash_from_filename(file)
end
- erb :processes
+ erb :index
end
-def megabytes(kilobytes)
- (kilobytes.to_f / 1024.0).floor
+get '/memcheck' do
+ @meminfo = MemInfo.new
+ @max_memused = @@max_memused
+ if mem_increased?(@meminfo)
+ save_process_list!(@meminfo)
+ @max_memused = update_max_memused!(@meminfo)
+ end
+
+ check_cleanup!
+ cleanup_logs!
+
+ erb :memcheck
end
-def readable_date(date, format="%Y/%h/%d %I:%M:%S %p")
- date = DateTime.parse(date)
- date.strftime(format)
+put '/max_memused' do
+ begin
+ @@memory_threshold = params[:memory_threshold].to_i
+ status 200
+ "Update Succeeded"
+ rescue
+ status 500
+ "Update Failed"
+ end
end
-def date_from_filename(filename)
- File.basename(filename).split("-").first
-end
-def oldmem_from_filename(filename)
- File.basename(filename).split("-")[1]
-end
+#####
+# Helpers
-def newmem_from_filename(filename)
- File.basename(filename).split("-")[2].split(".").first
-end
+helpers do
+ def mem_increased?(cur_meminfo)
+ cur_meminfo.memused > @@max_memused
+ end
+
+ def update_max_memused!(cur_meminfo)
+ @@max_memused = cur_meminfo.memused
+ end
+
+ def save_process_list!(cur_meminfo)
+ system("ps auxr > log/procs/`date \"+%Y%m%d_%H%M%S-#{@@max_memused}-#{cur_meminfo.memused}\"`.snapshot.out")
+ end
+
+ def check_cleanup!
+ @@num_checks += 1
+ if @@num_checks > @@max_checks
+ @@num_checks = 1
+ @@max_memused = @@memory_threshold
+ end
+ end
+
+ def get_log_list
+ Dir.glob("log/procs/*.snapshot.out").sort.reverse
+ end
+
+ def cleanup_logs!
+ logs = get_log_list
+ FileUtils::rm_f(logs[@@logs_to_keep..-1]) unless @@logs_to_keep > logs.size
+ end
+
+ def readable_date(date, format="%Y/%h/%d %I:%M:%S %p")
+ date = DateTime.parse(date)
+ date.strftime(format)
+ end
+
+ def date_from_filename(filename)
+ File.basename(filename).split("-").first
+ end
+
+ def oldmem_from_filename(filename)
+ File.basename(filename).split("-")[1]
+ end
+
+ def newmem_from_filename(filename)
+ File.basename(filename).split("-")[2].split(".").first
+ end
+
+ def hash_from_filename(filename)
+ {
+ :name => date_from_filename(filename),
+ :oldmem => oldmem_from_filename(filename),
+ :newmem => newmem_from_filename(filename),
+ :data => File.open(filename) { |f| f.read }
+ }
+ end
+
+ def megabytes(kilobytes)
+ (kilobytes.to_f / 1024.0).floor
+ end
+
+ def cycle
+ %w{even odd}[@_cycle = ((@_cycle || -1) + 1) % 2]
+ end
-def hash_from_filename(filename)
- {
- :name => date_from_filename(filename),
- :oldmem => oldmem_from_filename(filename),
- :newmem => newmem_from_filename(filename),
- :data => File.open(filename) { |f| f.read }
- }
+ CYCLE = %w{even odd}
+ def cycle_fully_sick
+ CYCLE[@_cycle = ((@_cycle || -1) + 1) % 2]
+ end
end
View
@@ -1,50 +1,111 @@
body {
margin: 0px;
- font-family: "Lucida Grande";
+ font-family: "Helvetica";
}
h1 {
margin-left: 15px;
font-size: 2em;
}
-ul {
+div.form {
+ position: absolute;
+ top: 15px;
+ left: 300px;
+}
+
+div.form label {
+ font-size: .9em;
+ font-weight: bold;
+ padding-right: 5px;
+}
+
+div.form input {
+ width: 55px;
+}
+
+div.form li {
+ padding-left: 5px;
+}
+
+div.form ul {
+ list-style: none;
+}
+
+div.form #memory_threshold_result {
+ font-size: .9em;
+ font-weight: bold;
+ padding: 3px;
+}
+
+div.form #memory_threshold_result.success {
+ color: green;
+}
+
+div.form #memory_threshold_result.failed {
+ color: red;
+}
+
+div.processes ul {
border-top: 1px solid black;
list-style: none;
-/* float: left;*/
margin-top: 0px;
margin-bottom: 0px;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 15px;
padding-right: 15px;
- background-color: #efefef;
+ background-color: #e1e8f4;
+}
+
+div.processes ul:hover {
+ background-color: #f6f8d5;
+}
+
+div.processes .even {
+ background-color: #e1e8f4;
+}
+
+div.processes .odd {
+ background-color: #fff;
}
.clear {
clear: both;
}
-li {
+.hidden {
+ display: none;
+}
+
+ul.form {
+ float: left;
+}
+
+.form li {
+ float: left;
+}
+
+div.processes li {
font-size: .8em;
}
-li.timestamp {
+div.processes li.timestamp {
float: left;
font-weight: bold;
}
-li.memchange {
+div.processes li.memchange {
float: left;
padding-left: 10px;
}
-li.procs {
+div.processes li.procs {
display: none;
float: left;
}
-pre.procs {
+div.processes pre.procs {
border: 1px solid #666;
overflow: scroll;
background-color: #000;
Oops, something went wrong.

0 comments on commit 5efe756

Please sign in to comment.