Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

migrated external plugins in scout's repo

  • Loading branch information...
commit f82db011881972e5e92d8f12d7ecdcc5596547a0 1 parent a910378
Andre Lewis authored
View
33 check_timestamp/check_timestamp.rb
@@ -0,0 +1,33 @@
+# Ensures that the timestamp of a file is within a given threshold
+class CheckTimestamp < Scout::Plugin
+
+ OPTIONS=<<-EOS
+ path:
+ name: path
+ notes: path to the file which will have its timestamp checked
+ default: /fully/qualified/path/to/your/file
+ threshold:
+ name: threshold
+ notes: threshold in minutes for the timestamp. If the timestamp of the file is older than this threshold, an error will be returned.
+ default: 360
+ EOS
+
+ def build_report
+ begin
+ threshold = option(:threshold).to_f
+ path = option(:path)
+ timestamp = File.new(path).mtime
+ current_time = Time.now
+ difference = ((current_time - timestamp) / 60).round.to_f
+ output = "Path: #{path}, Threshold: #{threshold} minutes, Path Timestamp: #{timestamp}, Current Time: #{current_time}, Difference: #{difference}"
+ report(:difference => difference, :threshold => threshold)
+ if difference > threshold
+ alert(:subject => "File #{path} was #{difference} minutes old, which is over the threshold of #{threshold} minutes", :body => output)
+ end
+ return difference
+ rescue Exception => e
+ error(:subject => 'Error running Check Timestamp plugin', :body => e)
+ return -1
+ end
+ end
+end
View
54 starling_monitor/starling_monitor.rb
@@ -0,0 +1,54 @@
+class StarlingMonitor < Scout::Plugin
+
+ OPTIONS=<<-EOS
+ host:
+ name: Host
+ notes: The host to monitor
+ default: 127.0.0.1
+ port:
+ name: Port
+ notes: The port starling is running on
+ default: 61613
+ queue_re:
+ name: Name Reqular Expresssion
+ notes: Pattern to test against queue names to select queues to monitor
+ default:
+ max_depth:
+ name: Maximum Items
+ notes: Alert if the queue contains more items than this
+ default: 4000
+ EOS
+
+ attr_accessor :connection
+
+ needs 'starling'
+
+ def build_report
+ self.connection=Starling.new("#{option(:host)}:#{option(:port)}")
+ @report = {}
+
+ begin
+ connection.sizeof(:all).each do |queue_name,item_count|
+ check_queue(queue_name,item_count) if should_check_queue?(queue_name)
+ end
+ report(@report)
+ rescue Exception=>e
+ error("Got unexpected error: #{e} #{e.class}")
+ end
+ end
+
+ def should_check_queue?(name)
+ option(:queue_re).nil? or /#{option(:queue_re)}/ =~ name
+ end
+
+ def check_queue(name,depth)
+ q_depth = (depth||0).to_i
+ @report ||= {}
+ @report[name] = q_depth
+ if q_depth > option(:max_depth).to_i
+ alert("Max Queue Depth for #{name} exceeded","#{q_depth} items is more than the max allowed #{option(:max_depth)}")
+ end
+ end
+
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.